ramin-roozdar / gateway
一个用于连接所有伊朗支付网关的 Laravel 包
2.1
2018-11-29 08:49 UTC
Requires
- php: >=5.6.4
- illuminate/contracts: ~5.4
- illuminate/database: ~5.4
- illuminate/http: ~5.4
- illuminate/support: ~5.4
- illuminate/view: ~5.4
- nesbot/carbon: ~1.20
Requires (Dev)
- mockery/mockery: ~0.9
- phpunit/phpunit: ~4.0|~5.0
README
伊朗支付网关
此库受 laravel Socialite、PoolPort、larabook/gateway 和 ShirazSoft/Gateway 启发
可用的 PSP(银行)
- Beh Pardakht (MELLAT)
- SADAD (MELLI)
- SEP (SAMAN)
- PEC (PARSIAN)
- Mabna (SADERAT)
- Asan Pardakht
- IranKish
可用的第三方
- Pay.ir
- JibIt
- Pardano
- ZarinPal
- NextPay
安装
步骤 1
composer require parsisolution/gateway
步骤 2
php artisan vendor:publish --provider="Parsisolution\Gateway\GatewayServiceProvider"
步骤 3
将 config/gateways.php
字段更改为您的规格。
用法
步骤 1
从 Gateway Facade 获取 Gateway 实例 Gateway::of('mellat')
或者自己创建一个: new Mellat(app(), config('gateways.mellat'));
或者
new Mellat(app(), [ 'username' => '', 'password' => '', 'terminalId' => 0000000, 'callback-url' => '/' ]);
步骤2
然后创建新的支付事务,可以这样做
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(); }
步骤3
并在回调中
try { $settledTransaction = Gateway::settle(true); // true argument for stateless $trackingCode = $settledTransaction->getTrackingCode(); $refId = $settledTransaction->getReferenceId(); $cardNumber = $settledTransaction->getCardNumber(); // تراکنش با موفقیت سمت بانک تایید گردید // در این مرحله عملیات خرید کاربر را تکمیل میکنیم } catch (\Parsisolution\Gateway\Exceptions\RetryException $e) { // تراکنش قبلا سمت بانک تاییده شده است و // کاربر احتمالا صفحه را مجددا رفرش کرده است // لذا تنها فاکتور خرید قبل را مجدد به کاربر نمایش میدهیم echo $e->getMessage() . "<br>"; } catch (\Exception $e) { // نمایش خطای بانک echo $e->getMessage(); }