rez0sk/laravel-zarinpal

This package is abandoned and no longer maintained. No replacement package was suggested.

Laravel package for Zarinpal payment gateway.

dev-master 2019-04-12 20:29 UTC

This package is auto-updated.

Last update: 2022-07-13 03:59:27 UTC


README

Build Status codecov StyleCI

Laravel package for Zarinpal payment gateway.

This package provides an interface (a laravel facade) that you can easily use and mock!

Features

  • Mockability
  • Dynamic MerchantID
  • Supporting zarinpal's sandbox

Installation

composer require rez0sk/laravel-zarinpal

Configuration

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.

Sandbox mode (Optional)

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();
    }
}

Usage

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'
]);

Dynamic MerchantID

You can dynamically set MerchantID before each payment:

Zarinpal::setMerchantID('xxxxx-xxxx-xxx');
Zarinpal::pay(...)

Payment Verification

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.
}

TODO

  • CI setup.
  • Adding examples.
  • Improve tests.
  • Support wages.