jagdish-j-p / fpx-payment
FPX支付服务的Laravel实现
Requires
- php: ^7.4|^8.0
- eastwest/json: ^3.0
- laravelcollective/html: ^6.2
- monarobase/country-list: ^3.2
- nesbot/carbon: ^2.48.0
Requires (Dev)
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.3.3
This package is auto-updated.
Last update: 2024-09-04 08:45:18 UTC
README
此包提供了Paynet FPX服务的Laravel实现。
成为赞助商
您的支持使我能够保持此包免费、更新和可维护。或者,您可以通过以下链接传播信息!
安装
您可以通过composer安装此包
composer require jagdish-j-p/fpx-payment
然后运行发布命令以发布配置文件和支持控制器
php artisan fpx:publish
这将生成以下文件
- 默认设置的可覆盖的配置文件
fpx.php - 将接收支付响应和任何主机到主机事件的控制器
Http/Controllers/FPX/Controller.php - 公共目录中的资源。
- 默认HTML的可覆盖视图文件
payment.blade.php。注意不要更改表单操作URLfpx.payment.auth.request。
设置
- 将您的重定向URL和您的卖家和交换ID添加到
.env文件中。
FPX_INDIRECT_PATH=payments/fpx/callback FPX_DIRECT_PATH=payments/fpx/webhook FPX_INDIRECT_URL="${APP_URL}/${FPX_INDIRECT_PATH}" FPX_DIRECT_URL="${APP_URL}/${FPX_DIRECT_PATH}" FPX_EXCHANGE_ID= FPX_SELLER_ID=
-
如果您已经生成了CSR,可以跳过此步骤。在浏览器中访问
fpx/csr/request路径以生成CSR。http://app.test/fpx/csr/request填写表单并点击
GENERATE。在右侧的textarea中将生成openSSL代码。如果您尚未安装,请从https://www.openssl.org/下载openSSL。运行openssl代码以生成CSR。将此CSR提交给FPX服务提供商以获取交换证书。 -
在生成您的证书后,将它们添加到您的应用中。默认情况下,我们寻找以下指令内的证书。在
storage/app目录中创建fpx/uat和fpx/prod目录,并将您的证书粘贴到那里。您可以在fpx certificates/uat/fpxuat_current.cer中找到UAT证书,将其重命名为您的交换ID,并将其放置在提到的UAT目录中。
'certificates' => [ 'uat' => [ 'disk' => 'local', // S3 or Local. Don't put your certificate in public disk 'dir' => '/fpx/uat', ], 'production' => [ 'disk' => 'local', // S3 or Local. Don't put your certificate in public disk 'dir' => '/fpx/prod', ] ],
您可以通过更新配置文件来覆盖默认设置。
- 运行迁移以添加银行和fpx_transactions表
php artisan migrate
- (可选) 如果您在初始设置中遇到问题,请运行此命令
php artisan optimize
使用方法
- 首先运行以下命令以播种银行列表。
php artisan fpx:banks
您应该安排fpx:banks Artisan命令每天运行
$schedule->command('fpx:banks')->daily();
- 添加以下属性的
x-fpx-payment组件
<x-fpx-payment :reference-id="$invoice->id" :datetime="$invoice->created_at->format('Ymdhms')" :amount="$invoice->total" :customer-name="$company->name" :customer-email="$company->owner->email" :product-description="Salary Invoice" :class="css class name for styling button">
在测试期间,您可以使用test-mode属性来覆盖提供的金额为'MYR 1.00'
<x-fpx-payment :reference-id="$invoice->id" :datetime="$invoice->created_at->format('Ymdhms')" :amount="$invoice->total" :customer-name="$company->name" :customer-email="$company->owner->email" :product-description="Salary Invoice" :class="css class name for styling button" test-mode>
- 在
Http/Controllers/FPX/Controller.php中处理支付响应
/** * This will be called after the user approve the payment * on the bank side * * @param Request $request * @return Response */ public function callback(Request $request) { $response = $request->handle(); // Update your order status } /** * This will handle any direct call from FPX * * @param Request $request * @return string */ public function webhook(Request $request) { $response = $request->handle(); // Update your order status return 'OK'; }
- 使用命令检查所有挂起交易的状态
php artisan fpx:payment-status
- 使用命令检查特定交易的状态,通过逗号分隔的顺序参考ID传递。
php artisan fpx:payment-status reference_id1,reference_id2,reference_id3
- 从控制器检查交易状态和银行列表
use JagdishJP/FpxPayment/Fpx; /** * Returns status of transaction * * @param string $reference_id reference order id * @return array */ $status = Fpx::getTransactionStatus($reference_id); /** * returns collection of bank_id and name * * @param bool $getLatest (optional) pass true to get latest banks * @return \Illuminate\Support\Collection */ $banks = Fpx::getBankList(true);
- 交易状态API
http://app.test/api/fpx/transaction/status/$reference_id
网页集成
您可以访问http://app.test/fpx/initiate/payment以查看网页集成支付的流程演示。
移动应用集成
- 在URL中附加
app参数以检查演示。 http://app.test/fpx/initiate/payment/app - 这将在交易完成后打印JSON响应,以集成到移动应用中。
按以下步骤将集成到移动应用程序中。
请求详情
在网页视图中以POST方法打开http://app.test/fpx/initiate/payment/app,并提交以下参数。
response_format = "JSON"
reference_id = unique order reference id
customer_name = name of the buyer/customer
amount = amount to be charged
customer_email = email id of customer
remark = remarks for the transaction
additional_params = any additional parameters you want to pass
响应
您必须使用response字段来显示收据。如果需要额外的详细信息,将添加fpx_response。
response.status将显示为成功、失败或挂起。
{
"response": {
"status": "succeeded/failed/pending",
"message": "Payment is successfull",
"transaction_id": "",
"reference_id": "",
"amount": "",
"transaction_timestamp": "",
"buyer_bank_name": "",
"response_format": "JSON",
"additional_params": "type=123"
},
"fpx_response": {
"fpx_debitAuthCode": "",
"fpx_debitAuthNo": "",
"fpx_sellerExId": "",
"fpx_creditAuthNo": "",
"fpx_buyerName": "",
"fpx_buyerId": null,
"fpx_sellerTxnTime": "",
"fpx_sellerExOrderNo": "",
"fpx_makerName": "",
"fpx_buyerBankBranch": "",
"fpx_buyerBankId": "",
"fpx_msgToken": "",
"fpx_creditAuthCode": "",
"fpx_sellerId": "",
"fpx_fpxTxnTime": "",
"fpx_buyerIban": null,
"fpx_sellerOrderNo": "",
"fpx_txnAmount": "",
"fpx_fpxTxnId": "",
"fpx_checkSum": "",
"fpx_msgType": "",
"fpx_txnCurrency": "",
}
}
您也可以用您自定义的设计覆盖payment.blade.php以与您的布局集成。但不要更改HTML控件的name属性和表单的action URL。
变更日志
有关最近更改的更多信息,请参阅变更日志。
贡献
有关详细信息,请参阅贡献指南。
安全性
如果您发现任何与安全相关的问题,请通过电子邮件jagdish.j.ptl@gmail.com而不是使用问题跟踪器。
致谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。
Laravel包模板
本包使用Laravel包模板生成。
