Laravel package for Zarinpal payment gateway.
This package provides an interface (a laravel facade) that you can easily use and mock!
- Mockability
- Dynamic MerchantID
- Supporting zarinpal's sandbox
composer require rez0sk/laravel-zarinpal
In your config/services.php
file add this config:
'zarinpal' => [
'merchant_id' => env('ZARINPAL_MERCHANT_ID'),
'description' => 'Default description' // optional
]
then add ZARINPAL_MERCHANT_ID
to your .env
file.
It's recomanded to enable sandbox mode in local
environment.
If you wan't to do so, add these lines to your AppServiceProvider
class's boot
function.
public function boot()
{
if ($this->app->isLocal()) {
Zarinpal::enableSandbox();
}
}
Simply issue a payment-request and redirect user to Zarinpal with one shot!
use Zarinpal\Facades\Zarinpal;
...
public function someControllerFunction ()
{
return Zarinpal::pay(2000, route('paymnet.verify', $order->id))->redirect();
}
Or retrieve Authority code and redirect manually:
Zarinpal::pay(2000, 'http://callback.url/id')->payment->authority
There are some additional information you can provide for payment:
Zarinpal::pay(2000, 'http://callback.url/id', [
'description' => 'This is such a dummy order!',
'email' => 'User's email address',
'phone' => 'User's phone number'
]);
You can dynamically set MerchantID before each payment:
Zarinpal::setMerchantID('xxxxx-xxxx-xxx');
Zarinpal::pay(...)
public function verifyOrderPayment (Order $order, Request $request)
{
$result = Zarinpal::verify($request, $order->TotalPrice);
$result->status //Status code. 100 means success :)
$result->RefID //Payment's unique ReferenceID
$result->amount // Payment's amount in Tuman. (Always use Toman with Zarinpal)
$result->description //Payment's description.
}
- CI setup.
- Adding examples.
- Improve tests.
- Support wages.