letuananh1873/fpx-payment

FPX支付服务的一个Laravel实现

1.0.1 2022-04-21 07:26 UTC

This package is auto-updated.

Last update: 2024-09-21 12:37:16 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。注意不要更改表单操作URL fpx.payment.auth.request

设置

  1. 将您的重定向URL和您的卖家和交换ID添加到 .env 文件中。
FPX_INDIRECT_URL=https://app.test/payments/fpx/callback
FPX_INDIRECT_PATH=payments/fpx/callback
FPX_DIRECT_URL=https://app.test/payments/fpx/direct-callback
FPX_DIRECT_PATH=payments/fpx/direct-callback

FPX_EXCHANGE_ID=
FPX_SELLER_ID=
  1. 如果您已生成CSR,可以跳过此步骤。在浏览器中访问 fpx/csr/request 路径以生成CSR。

    http://app.test/fpx/csr/request

    填写表单并点击 GENERATE。在右侧的textarea中将生成带有openSSL代码。如果您还没有安装,请从 https://www.openssl.org/ 下载openSSL。运行openssl代码以生成CSR。将此CSR提交给FPX服务提供商以获取交换证书。

  2. 在生成您的证书后,将它们添加到您的应用程序中。默认情况下,我们会在以下指令中查找证书。在 storage/app/public 目录中创建 fpx/uatfpx/prod 目录,并将您的证书粘贴到那里。您可以在 uat certificate/fpxuat_current.cur 中找到UAT证书,将其重命名为您的交换ID,并将其放置在指定的UAT目录中。

'certificates' => [
	'uat' => [
		'disk' => 'local', // S3 or Local. Don't put your certificate in public disk
		'dir' => '/public/fpx/uat',
	],
	'production' => [
		'disk' => 'local', // S3 or Local. Don't put your certificate in public disk
		'dir' => '/public/fpx/prod',
	]
],

您可以通过更新配置文件来覆盖默认值。

  1. 运行迁移以添加银行和fpx_transactions表
php artisan migrate

用法

  1. 首先运行以下命令以初始化银行列表。
php artisan fpx:banks

您应该安排fpx:banks Artisan命令每天运行

$schedule->command('fpx:banks')->daily();
  1. 添加具有以下属性的 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>
  1. 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';
	}
  1. 使用命令检查所有挂起交易的状态
php artisan fpx:payment-status
  1. 使用命令通过逗号分隔的订单参考ID检查特定交易的状态
php artisan fpx:payment-status reference_id1,reference_id2,reference_id3
  1. 从控制器检查交易状态和银行列表
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);
  1. 交易状态API
http://app.test/api/fpx/transaction/status/$reference_id

Web集成

您可以访问 http://app.test/fpx/initiate/payment 以查看Web集成支付流程的演示。

移动应用集成

按照以下步骤集成到移动应用程序中。

请求详情

使用POST方法在web视图中打开 http://app.test/fpx/initiate/payment/app 并POST以下参数。

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。

变更日志

请参阅CHANGELOG获取更多关于最近变更的信息。

贡献

请参阅CONTRIBUTING以获取详细信息。

安全

如果您发现任何与安全相关的问题,请通过jagdish.j.ptl@gmail.com邮箱报告,而不是使用问题跟踪器。

致谢

许可

MIT 许可证 (MIT)。请参阅许可文件获取更多信息。

Laravel 包模板

此包是使用Laravel 包模板生成的。