alighasemzadeh / gateway
This package is abandoned and no longer maintained.
No replacement package was suggested.
A Laravel package for connecting to all Iraninan payment gateways
dev-master
2021-04-20 03:08 UTC
Requires
- php: >=5.6.4
- illuminate/contracts: ~5.4|^6.0|^7.0|^8.0
- illuminate/database: ~5.4|^6.0|^7.0|^8.0
- illuminate/http: ~5.4|^6.0|^7.0|^8.0
- illuminate/support: ~5.4|^6.0|^7.0|^8.0
- illuminate/view: ~5.4|^6.0|^7.0|^8.0
- nesbot/carbon: >=1.20
Requires (Dev)
- mockery/mockery: ^1.0
- phpunit/phpunit: ^7.0|^8.0
This package is auto-updated.
Last update: 2021-06-20 03:34:34 UTC
README
Iranian Payment Gateways
This library is inspired by laravel Socialite and PoolPort and larabook/gateway and ShirazSoft/Gateway
Available PSPs (Bank):
- Beh Pardakht (MELLAT)
- SADAD (MELLI)
- SEP (SAMAN)
- PEC (PARSIAN)
- Mabna V1
old method
- Mabna V2
new method
- Asan Pardakht
- IranKish
Available 3rd-parties:
- Pay.ir
- ZarinPal
- JibIt
- PayPing
- NextPay
- SizPay
- SabaPay (Saba Novin)
- Pardano
Install
Step 1:
composer require parsisolution/gateway
Step 2:
php artisan vendor:publish --provider="Alighasemzadeh\Gateway\GatewayServiceProvider"
Step 3:
php artisan migrate
Step 4:
Change config/gateways.php
fields to your specifications.
Usage
Step 1:
Get instance of Gateway from Gateway Facade Gateway::of('mellat')
Or create one yourself: new Mellat(app(), config('gateways.mellat'));
Or
new Mellat(app(), [ 'username' => '', 'password' => '', 'terminalId' => 0000000, 'callback-url' => '/' ]);
Step2:
Then to create new payment transaction you can do like this:
try { $gateway = Gateway::of('zarinpal'); // $gateway = new Zarinpal(app(), config('gateways.zarinpal')); $gateway->callbackUrl(route('callback')); // You can change the callback // You can make it stateless. // in default mode it uses session to store and retrieve transaction id // (and other gateway specific or user provided (using $gateway->with) required parameters) // but in stateless mode it get transaction id and other required parameters from callback url // Caution: you should use same stateless value in callback too $gateway->stateless(); // Then you should create a transaction to be processed by the gateway // Amount is in `Toman` by default but you can set the currency in second argument as well. IRR (for `Riyal`) $transaction = new RequestTransaction(new Amount(12000)); // 12000 Toman $transaction->setExtra([ 'mobile' => '9122628796', // mobile of payer (for zarinpal) 'email' => 'ali@gmail.com', // email of payer (for zarinpal) ]); $transaction->setExtraField('description', 'توضیحات من'); $authorizedTransaction = $gateway->authorize($transaction); $refId = $authorizedTransaction->getReferenceId(); // شماره ارجاع بانک $transID = $authorizedTransaction->getId(); // شماره تراکنش // در اینجا // شماره تراکنش بانک را با توجه به نوع ساختار دیتابیس تان // در جداول مورد نیاز و بسته به نیاز سیستم تان // ذخیره کنید . return $gateway->redirect($authorizedTransaction); } catch (\Exception $e) { echo $e->getMessage(); }
Step3:
And in callback
try { $settledTransaction = Gateway::settle(true); // true argument for stateless $trackingCode = $settledTransaction->getTrackingCode(); $refId = $settledTransaction->getReferenceId(); $cardNumber = $settledTransaction->getCardNumber(); // تراکنش با موفقیت سمت بانک تایید گردید // در این مرحله عملیات خرید کاربر را تکمیل میکنیم } catch (\Alighasemzadeh\Gateway\Exceptions\RetryException $e) { // تراکنش قبلا سمت بانک تاییده شده است و // کاربر احتمالا صفحه را مجددا رفرش کرده است // لذا تنها فاکتور خرید قبل را مجدد به کاربر نمایش میدهیم echo $e->getMessage() . "<br>"; } catch (\Exception $e) { // نمایش خطای بانک echo $e->getMessage(); }