omalizadeh / laravel-multi-payment
基于驱动程序的laravel支付包,支持通过多个网关进行在线支付
Requires
- php: ^8.1
- ext-json: *
- guzzlehttp/guzzle: ^7.5
- illuminate/contracts: ^8.0 || ^9.0 || ^10.0
- illuminate/http: ^8.0 || ^9.0 || ^10.0
- illuminate/support: ^8.0 || ^9.0 || ^10.0
- ramsey/uuid: ^4.7
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.16
- orchestra/testbench: ^8.5
Suggests
- ext-bcmath: Needed to use pasargad gateway
- ext-openssl: Needed to use eghtesad novin gateway
- ext-simplexml: Needed to use pasargad gateway
- ext-soap: Needed to use SOAP drivers: mellat, saman
README
Laravel在线支付网关包
这是一个支持多驱动程序的laravel网关支付包。每个驱动程序都可以有多个配置。支持laravel v8.0+,需要php v8.1+
喜欢这个包,请给它加星标!
支持的网关
- Mellat Bank (Behpardakht)
- Saman Bank (Sep)
- Parsian Bank (Top)
- Pasargad Bank (Pep)
- Eghtesad Novin Bank (Pardakht Novin)
- Zarinpal
- IDPay
- Pay.ir
- Zibal
- PayStar
安装与配置
使用composer安装
composer require omalizadeh/laravel-multi-payment
发布主配置文件
php artisan vendor:publish --tag=multipayment-config
基于标签发布网关配置文件,例如
- zarinpal-config
- mellat-config
- saman-config
- pasargad-config
- novin-config
例如
php artisan vendor:publish --tag=zarinpal-config
您还可以发布网关重定向的视图文件并进行自定义
php artisan vendor:publish --tag=multipayment-view
在主配置文件multipayment.php
中,您可以指定默认驱动程序。例如,zarinpal.second
的值表示将使用配置在zarinpal配置文件中second
键部分的zarinpal
网关。还有一个选项,可以从伊朗托曼货币(IRR)自动转换到伊朗里亚尔(IRR)以及反向转换。
/** * set default gateway * * valid pattern --> GATEWAY_NAME.GATEWAY_CONFIG_KEY */ 'default_gateway' => env('DEFAULT_PAYMENT_GATEWAY', 'zarinpal.second'), /** * set to false if your in-app currency is IRR */ 'convert_to_rials' => true
在每个网关配置文件中,您可以指定多个凭据,因此您可以为您的应用程序从同一提供者拥有多个网关。
/** * gateway configurations */ 'first' => [ 'merchant_id' => '', 'callback_url' => 'https://yoursite.com/path/to', 'mode' => 'normal', // Supported values: normal, sandbox, zaringate 'description' => 'payment using zarinpal', ], 'second' => [ 'merchant_id' => '', 'callback_url' => 'https://yoursite.com/path/to', 'mode' => 'sandbox', 'description' => 'payment using zarinpal', ]
用法
网关支付有两个主要阶段。第一个是购买(通过调用网关API的transaction_id/token开始处理)和打开带有接收数据的网关支付网页。第二个是验证(检查支付是否成功)。
购买
Inovice
对象包含支付数据。首先,您创建一个发票,设置金额和其他信息,然后通过将发票传递给PaymentGateway
外观启动支付流程。您可以使用外观上的setProvider
方法在支付前更改网关。
// On top... use Omalizadeh\MultiPayment\Facades\PaymentGateway; //// $invoice = new Invoice(10000); $invoice->setPhoneNumber("989123456789"); return PaymentGateway::purchase($invoice, function (string $transactionId) { // Save transaction_id and do stuff... })->view();
验证
在支付网关将您的应用程序重定向后,您必须创建一个发票并设置其transaction_id和金额。然后使用PaymentGateway
验证发票的支付是否成功。
try { // Get amount & transaction_id from database or gateway request $invoice = new Invoice($amount, $transactionId); $receipt = PaymentGateway::verify($invoice); // Save receipt data and return response // } catch (PaymentAlreadyVerifiedException $exception) { // Optional: Handle repeated verification request } catch (PaymentFailedException $exception) { // Handle exception for failed payments return $exception->getMessage(); }
其他功能
未经验证的支付
还有一个方法(目前仅由zarinpal支持)可以获取成功的未经验证支付列表。使用PaymentGateway
外观上的unverifiedPayments
方法来使用此功能。
退款
使用refund
方法,您可以退款成功的支付给客户。