rohit / line-pay
Laravel 的 Line 支付包
Requires
- php: >=7
- guzzlehttp/guzzle: ^6.1
Requires (Dev)
- mockery/mockery: dev-master
- orchestra/testbench: ~3.3
- phpunit/phpunit: ^6.3@dev
This package is not auto-updated.
Last update: 2024-09-15 02:22:09 UTC
README
非常简单轻量级的 Line 支付包。
安装
Composer
将 Line Pay 添加到您的 composer.json 文件
"rohit/line-pay": "^3.0"
运行 composer install
以获取包的最新版本
或者您可以直接运行 composer require
命令
composer require rohit/line-pay
配置
完成包安装后,您需要配置 config/app.php
并添加 Providers
和 Aliases
'providers` => [ ....... ....... Rohit\LinePay\LinePayServiceProvider::class ]
'aliases' => [ ...... ...... 'LinePay' => Rohit\LinePay\Facades\LinePay::class ]
供应商发布
在上述步骤完成后,您需要发布供应商为此包。它将在 config
文件夹下创建 line-pay.php
文件。此文件夹包含您区域设置的配置。
php artisan vendor:publish --provider="Rohit\LinePay\LinePayServiceProvider"
line-pay.php
文件将包含以下结构
return [ 'channel-id' => 'Line Pay Channel Id', 'channel-secret' => 'Line Pay Channel Secret', 'reservation-url' => 'https://sandbox-api-pay.line.me/v1/payments/request', 'detail-url' => 'https://sandbox-api-pay.line.me/v1/payments', ];
函数
-
处理支付
您可以使用 process Payment 函数处理您的支付,该函数接受数组作为参数,如下所示
LinePay::processPayment($params);
processPayment 的数组参数描述如下
处理支付响应如下
[ 'status' => 'success' or 'failed', 'data' => [ 'request' => 'Params you send while calling the function (You may need to save it to log for future)', 'response' => 'Array response (You may need to save it to log for future)', ], ] The response will be empty [] or as follows: [ 'returnCode' => '0000' (if success) or other code, 'returnMessage' -> 'OK', 'info' => [ 'transactionId' => 'Transaction Id eg: 12345678', 'paymentUrl' => [ 'web' => 'Payment url for web.' (Need to redirect to this for payment), 'app' => 'Payment url for app', ], 'paymentAccessToken' => 'Access Token for Payment' ], ]
-
验证支付
从 line 成功支付后,它将重定向到
confirmUrl
。现在我们需要在更新我们的订单之前验证 line 的支付。这是一个用于安全的 3 方握手。此函数接受两个参数:事务 ID 和参数数组。LinePay::verifyPayment($transactionId, $params);
verifyPayment 的数组参数描述如下
验证支付响应如下
[ 'status' => 'success' or 'failed', 'data' => [ 'request' => 'Params you send while calling the function (You may need to save it to log for future)', 'response' => 'Array response (You may need to save it to log for future)', ], ]
响应将是一个空数组 [] 或者如下所示
If payment Type is NORMAL the response will be as follow: [ 'returnCode' => '0000' (if success) or other code, 'returnMessage' -> 'OK', 'info' => [ 'orderId' => 'OrderID of the payment', 'transactionId' => 'Transaction Id', 'payInfo' => [ [ 'method' => 'BALANCE', 'amount' => '10', ], [ 'method' => 'DISCOUNT', 'amount' => '10', ], ], ], ]
If payment Type is PREAPPROVED the response will be as follow: [ 'returnCode' => '0000' (if success) or other code, 'returnMessage' -> 'OK', 'info' => [ 'orderId' => 'OrderID of the payment', 'transactionId' => 'Transaction Id', 'payInfo' => [ [ 'method' => 'CREDIT_CARD', 'amount' => '10', 'creditCardNickName' => 'test', 'creditCardBrand' => 'VISA', ], 'regKey' => 'Random reg Key', ], ], ]
-
捕获支付
如果在处理支付时,通过 processPayment 函数的
capture
参数为 false,那么只有在调用 Catpute API 之后,支付才完成。此函数完成由 processPayment 只授权的支付。此函数接受两个参数:事务 ID 和参数数组。LinePay::verifyPayment($transactionId, $params);
verifyPayment 的数组参数描述如下
验证支付响应如下
[ 'status' => 'success' or 'failed', 'data' => [ 'request' => 'Params you send while calling the function (You may need to save it to log for future)', 'response' => 'Array response (You may need to save it to log for future)', ], ] The response will be empty [] or as follows: [ 'returnCode' => '0000' (if success) or other code, 'returnMessage' -> 'OK', 'info' => [ 'orderId' => 'The order id', 'transactionId' => 'Transaction Id eg: 12345678', 'info' => [ [ 'method' => 'BALANCE', 'amount' => 10, ], [ 'method' => 'DISCOUNT', 'amount' => 10, ], ], ], ]
-
取消支付
取消之前授权的支付。此 API 可以通过此 API 退款已经捕获的支付。
LinePay::voidPayment($transactionId);
取消支付的响应如下
[ 'status' => 'success' or 'failed', 'data' => [ 'request' => [], 'response' => 'Array response (You may need to save it to log for future)', ], ] The response will be empty [] or as follows: [ 'statusCode' => '0000' (if success) or other code, 'returnMessage' => 'OK', ]