shahrooz7216 / laravel-multi-payment
基于驱动程序的laravel在线支付包,支持多种网关
Requires
- php: ^7.4|^8.0
- ext-json: *
- guzzlehttp/guzzle: ^6.5.5|^7.0.1
- illuminate/contracts: ^7.0|^8.0|^9.0
- illuminate/http: ^7.0|^8.0|^9.0
- illuminate/support: ^7.0|^8.0|^9.0
- ramsey/uuid: ^4.0
Requires (Dev)
- orchestra/testbench: ^6.24|^7.0
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 v7.0+ 和需要php v7.4+
支持的网关
- Mellat Bank (Behpardakht)
- Saman Bank (Sep)
- Parsian Bank (Top)
- Pasargad Bank (Pep)
- Eghtesad Novin Bank (Pardakht Novin)
- Zarinpal
- IDPay
- Pay.ir
- Zibal
安装与配置
使用composer安装
composer require shahrooz7216/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
你还需要在config目录的app.php文件中的providers数组中添加Service provider
'providers' => [
shahrooz7216\MultiPayment\Providers\MultiPaymentServiceProvider::class,
],
你应该将配置环境变量添加到你的.env文件中
EGHTESAD_NOVIN_TERMINAL_ID="..."
EGHTESAD_NOVIN_MERCHANT_ID="..."
EGHTESAD_NOVIN_MID="..."
EGHTESAD_NOVIN_USER_ID="..."
EGHTESAD_NOVIN_PASSWORD="..."
EGHTESAD_NOVIN_TOKEN=""
EGHTESAD_NOVIN_CALLBACK_URL="https://something.com/novin.php"
EGHTESAD_NOVIN_API_ENDPOINT="https://pna.shaparak.ir"
EGHTESAD_NOVIN_CERT_PATH="..."
EGHTESAD_NOVIN_CERT_USERNAME="..."
EGHTESAD_NOVIN_CERT_PASSWORD="..."
EGHTESAD_NOVIN_MODE="NoSign"
你也可以发布网关重定向的视图文件并对其进行自定义
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开始交易_id/令牌的支付过程并打开带有接收数据的网关支付网页)。第二是验证(检查支付是否成功)。
购买
Inovice
对象包含支付数据。首先创建一个发票,设置金额和其他信息,然后将发票传递给 PaymentGateway
Facade 以开始支付过程。您可以在Facade上使用 setProvider
方法在支付前更改网关。
// On top... use shahrooz7216\MultiPayment\Facades\PaymentGateway; //// $invoice = new Invoice(10000); $invoice->setPhoneNumber("989123456789"); return PaymentGateway::purchase($invoice, function (string $transactionId) { // Save transaction_id and do stuff... })->view();
验证
在网关将您的应用程序重定向到您的应用程序后,您必须创建一个发票并设置其交易_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
Facade 中的 unverifiedPayments
方法来使用此功能。
退款
使用 refund
方法,您可以退款给客户。