adnane-ka / omnipay-sepay
为 Omnipay 支付处理库提供的 Sepay 网关
1.3
2024-09-06 11:42 UTC
Requires
- guzzlehttp/psr7: ^2.4
- nyholm/psr7: ^1.8
- omnipay/common: ^3.3
- php-http/curl-client: ^2.1
- php-http/httplug: ^2.3
- php-http/message: ^1.0
- symfony/http-client: ^6.2
README
为 Omnipay 支付处理库提供的 Sepay 支付网关
Omnipay 是一个与框架无关、多网关的 PHP 5.3+ 支付处理库。本包实现了 Omnipay 的 Tap 支持。
安装
composer require adnane-ka/omnipay-sepay
基本用法
此包提供了以下网关
- Sepay
此包与 Sepay 的 API 交互。
有关一般使用说明,请参阅主要的 Omnipay 存储库。
流程
- 配置网关。
- 为操作创建 QR 图像。
- 在站内结账页面上显示 QR 图像供最终用户操作。
- 一旦操作完成,应触发 webhook。
- 接收 webhook 中的数据。
- 通过比较/处理接收到的数据来完成购买。
示例用法
配置
use Omnipay\Omnipay; $gateway = Omnipay::create('Sepay'); $gateway->setApiKey('YOUR_API_KEY'); $gateway->setBankAccountNumber('YOUR_BANK_ACCOUNT_NUMBER'); $gateway->setBankName('YOUR_BANK_NAME');
创建购买
$response = $gateway->purchase([ 'amount' => 100000, // the amount in VND 'checkoutUrl' => 'https://:8000/checkout.php', // the page where the QR image is displayed 'returnUrl' => 'https://:8000/complete.php', // the URL to return to after the operation is fully proccessed 'transactionId' => uniqid() // A unique identifier for the operation ])->send(); if ($response->isRedirect()) { // The QR code is generated successfully and you're ready to be redirected to checkout $response->redirect(); } else { // An error occured echo $response->getMessage(); }
结账
<!-- The return URL is going be injected as encoded URL `completeUrl` --> <form action="<?php echo urldecode($_GET['completeUrl']); ?>" method="post" style="display: flex; flex-direction: column; width:30%;"> <!-- Display the QR image for the end-user --> <img src='<?php echo urldecode($_GET['qrSrc']); ?>'> <!-- The transaction ID is received as a query param --> <input type="hidden" name="transactionId" value="<?php echo $_GET['transactionId']; ?>"> <button type="submit">I've Paid, Complete My Order.</button> </form>
完成购买
当用户使用显示的 QR 图像付款并提交结账表单后,他们将被重定向到 returnUrl
,您将在该地址处理付款
$response = $gateway->completePurchase([ 'transactionId' => 'FGJAKANMCHK', // This should be retrieved from request redirect 'amount' => 100000, // Locate this from your system 'webhookResponse' => /*This should be located from the webhook*/ json_decode('{ "id": 92704, "gateway":"Vietcombank", "transactionDate":"2024-07-25 14:02:37", "accountNumber":"0010000000355", "code":null, "content":"chuyen tien mua iphone", "transferType":"in", "transferAmount":100000, "accumulated":19077000, "subAccount":null, "referenceCode":"MBVCB.3278907687", "description":"FGJAKANMCHK" }', true) ])->send(); if($response->isSuccessful()){ // Payment was successful and charge was captured // $response->getData() // $response->getTransactionReference() // payment reference }else{ // Charge was not captured and payment failed // $response->getData() }
支持
如果您对 Omnipay 有任何一般性问题,我们建议您在 Stack Overflow 上发布。请确保添加 omnipay 标签,以便易于查找。
如果您想了解发布公告,讨论项目想法或提出更详细的问题,还有一个您可以订阅的 邮件列表。
如果您认为您发现了一个错误,请使用 GitHub 问题跟踪器 报告它,或者更好的是,分支库并提交一个 pull request。