📐Use
you can start using your wallet very easily by checking these docs.
Start using Payments
you can create your own custom drivers if it does not exist in the list, read the
Create custom driverssection.
In the config file, you can set the default driver to use for all your payments. But you can also change the driver at runtime.
Choose what gateway you would like to use in your application. Then make that as the default driver so that you don't have to specify that everywhere. But, you can also use multiple gateways in a project.
// Eg. if you want to use zarinpal.
'default' => 'zarinpal',Then fill the credentials for that gateway in the drivers array.
'drivers' => [
'zarinpal' => [
// Fill in the credentials here.
'apiPurchaseUrl' => 'https://www.zarinpal.com/pg/rest/WebGate/PaymentRequest.json',
'apiPaymentUrl' => 'https://www.zarinpal.com/pg/StartPay/',
'apiVerificationUrl' => 'https://www.zarinpal.com/pg/rest/WebGate/PaymentVerification.json',
'merchantId' => '',
'callbackUrl' => 'http://yoursite.com/path/to',
'description' => 'payment in '.config('app.name'),
],
...
]your Invoice holds your payment details, so initially we'll talk about Invoice class.
Working with invoices
before doing any thing you need to use Invoice class to create an invoice.
In your code, use it like the below:
available methods:
uuid: set the invoice's unique IDgetUuid: retrieve the invoice's current unique IDdetail: attach some custom details to the invoicegetDetails: retrieve all custom detailsamount: set the invoice amountgetAmount: retrieve invoice amounttransactionId: set invoice payment transaction IDgetTransactionId: retrieve payment transaction idvia: set up a driver we use to pay the invoicegetDriver: retrieve the driver
Purchase invoice
In order to pay the invoice, we need the payment transaction. We purchased the invoice to retrieve the transaction id:
Pay Invoice
After purchasing the invoice, we can redirect the user to the bank payment page:
Verify payment
When the user has completed the payment, the bank redirects them to your website, then you need to verify your payment in order to ensure the invoice has been paid.
Useful methods
callbackUrl: can be used to change callbackUrl on the runtime.amount: you can set the invoice amount directlyvia: change driver on the flyconfig: set driver configs on the fly
Create custom drivers:
First you have to add the name of your driver, in the drivers array and also you can specify any config parameters you want.
Now you have to create a Driver Map Class that will be used to pay invoices. In your driver, You just have to extend TomatoPHP\TomatoWallet\Abstracts\Driver.
Eg. You created a class: App\Packages\PaymentDriver\MyDriver.
Once you create that class you have to specify it in the payment.php config file map section.
Note:- You have to make sure that the key of the map array is identical to the key of the drivers array.
Events
You can listen for 2 events
InvoicePurchasedEvent: Occurs when an invoice is purchased (after purchasing invoice is done successfully).
InvoiceVerifiedEvent: This occurs when an invoice is verified successfully.
Last updated
Was this helpful?