tsaiyihua / laravel-linepay
laravel的linepay库
2.5
2024-03-15 02:52 UTC
Requires
- guzzlehttp/guzzle: ^6.5.5|^7.0.1
- laravel/framework: ^6.20.1|^7.30.1|^8.75.0|^9.0|^10.0|^11.0
README
Laravel LinePay 是用于连接Line Pay的非官方套件
前言
目前只能执行一般付款后自动请款的动作,建议只在手机环境下出现 LinePay 的付款方式。
系统需求
-
v2.x
- PHP >= 7.2
- Laravel >= 6.0
-
v1.x
- PHP >= 7
- Laravel >= 5.7 < 6.0
安装
composer require tsaiyihua/laravel-linepay
环境设置
php artisan vendor:publish --tag=linepay
.env 文件中添加
LINE_PAY_CHANNEL_ID=
LINE_PAY_CHANNEL_SECRET=
申请及测试流程说明网址
https://pay.line.me/tw/developers/techsupport/sandbox/testflow?locale=zh_TW
用法
Line Pay 的付款流程必须先进行(reserve),然后确认付款后(confirm)才能完成整个付款。
Reserve
<?php namespace App\Http\Controllers; use TsaiYiHua\LinePay\Constants\ConfirmUrlType; use TsaiYiHua\LinePay\Reserve; use TsaiYiHua\LinePay\Services\StringService; class LinePayController extends Controller { protected $linePayReserve; public function __construct(Reserve $linePayReserve) { $this->linePayReserve = $linePayReserve; } public function pay() { $orderId = StringService::identifyNumberGenerator('O'); $postData = [ 'orderId' => $orderId, 'productName' => 'Item Name', 'productImageUrl' => 'https://tyh.idv.tw/images/tyhlogo.jpg', 'amount' => 50, 'confirmUrlType' => ConfirmUrlType::WEB ]; return $this->linePayReserve->setPostData($postData)->chat()->reserve(); } }
Confirm
Confirm 时会返回 transactionId 以及 orderId
$transId = $request->get('transactionId'); $orderId = $request->get('orderId'); $sendData = [ 'transactionId' => $transId, 'orderId' => $orderId ]; return $this->linePayConfirm->setPostData($sendData)->chat()->confirm(function($response){ if (!empty($response)) { // 處理完成付款後的動作 ... } });
已知问题
- 当使用网页登录或扫码付款时,页面会跳回 confirmUrl 页,但 Server-to-Server 也进行了一次通信,因此会有两次 Confirm Request。第二次的 Confirm Request 就会出现 1198 的处理中的错误,而前端网页有可能会先完成,有时会慢于 Server-to-Server,因此有时成功有时失败。
- 测试时不能发送 capture 为 false 时的状态,会报
LinePayException (2103) Parameter is not allowed. [capture:`false`]
。