mjedari / mellat-pay
伊朗梅拉特银行网关包
dev-master
2022-02-21 09:49 UTC
Requires
- php: ^7.4|^8.0
Requires (Dev)
- orchestra/testbench: ^6.22
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-09-21 15:23:30 UTC
README
伊朗梅拉特银行全在线支付服务
为Behpadakht梅拉特银行支付服务定制的Laravel包。
特性
- 事件调用
- 日志通道
- 内置速率限制器
安装
您可以通过composer安装此包
composer require mjedari/mellat-pay
您可以使用以下命令发布和运行迁移以及所有资产
php artisan vendor:publish --tag="mellat-pay"
php artisan migrate
您可以单独发布资产
php artisan vendor:publish --tag="mellat-pay-config" php artisan vendor:publish --tag="mellat-pay-views" php artisan vendor:publish --tag="mellat-pay-lang"
这是您应该自定义的发布配置文件的内容。在测试之前设置credentials
非常重要。callback
是您的默认回调。您可以通过修改table
来更改包表名。所有异常和消息都将位于您的包local
语言下。
return [ /* * Language for errors and messages: * */ 'local' => 'fa', //en /* * Description of credentials: * */ 'credentials' => [ 'username' => '', 'password' => '', 'terminalId' => 0000000, ], /* * Gateway's default callback: * */ 'callback' => '/callback', /* * Description of table name: * */ 'table' => 'mellat_transactions', ];
有一个视图文件是银行重定向器。可选地,您可以使用以下方法发布并修改任何自定义使用
php artisan vendor:publish --tag="mellat-pay"
简单用法
有主要三个步骤。首先,您应该以这种方式初始化网关
// initiate transaction and redirect to bank $gateway = MellatPay::price(10000) ->callback('/payment/callback') ->ready(); return $gateway->redirect();
如果一切正常,它将重定向到银行支付页面。然后,您应该定义一个回调路由并等待银行回调请求
// payment callback route $gateway = MellatPay::confirm() ->then(function ($response) { // transaction succeeded and response is transaction full info: return $response; })->catch(function ($e) { // you can get error occurred in transaction verify process: return $e->getMessage(); });
高级用法
交易可支付关系
您可以通过在MellatPay
外观上使用payable
方法将交易指定给其他模型。但在那之前,请确保您已将payable
特质添加到相关模型中
// in your related modal namespace App\Models; use Mjedari\MellatPay\Traits\Payable; class Product extends Model { use payable; // <--- add this trait ... ... ... }
在您的支付控制器中
// initiate route $product = Product::find(1); $gateway = MellatPay::payable($product)->price(10000)->ready();
设置可选值
支付请求中有一些选项。您可以针对每个交易设置description
、callback
、payer
、mobile
和payable
。
重要
- 如果您未指定
callback
URL,将使用默认的URL。 mobile
对向银行发送有用,它将被用于根据用户的先前支付卡信息自动完成网关输入。
// initiate route full example $product = Product::find(245); $gateway = MellatPay::payable($product) ->price(10000) // <--- price in IRR ->description("This is a description") // <--- send to bank and store ->callback("https://example.dev/callback/product/245") // <--- callback to etch request ->payer(1) // <--- used as user id ->mobile("989102128582") // <--- used for gateway page autocomplete ->ready(); return $gateway->redirect();
将自定义变量传递到重定向页面
如果您想修改重定向文件,在发布视图文件后,您可以在重定向时通过调用此方法将任何变量传递到该文件。
// initiate and redirect route $wallet = Wallet::find(1); $product = Product::find(1); $gateway->with($product, $wallet)->redirect(); // or $gateway->with(['product' => $product, 'wallet' => $wallet]) ... //or $gateway->with($product) ...
*请注意,交易信息已通过$transaction
可用。
测试
composer test
变更日志
有关最近更改的更多信息,请参阅变更日志。
贡献
有关详细信息,请参阅贡献指南。
安全漏洞
请参阅我们的安全策略了解如何报告安全漏洞。
鸣谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。