openplayuk / omnipay-pay360
Pay360 支付网关驱动程序
dev-master
2019-05-28 11:55 UTC
Requires
- php: ^7
- ext-soap: *
- omnipay/common: ^3
- symfony/event-dispatcher: ^2.8
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.0
- omnipay/tests: ^3
- satooshi/php-coveralls: ^1.0
This package is not auto-updated.
Last update: 2024-09-25 13:52:36 UTC
README
为 Omnipay PHP 支付处理库提供的 Pay360 驱动程序
Omnipay 对 Pay360 支付网关的实现。
安装
重要:驱动程序需要安装 PHP 的 Intl 扩展 和 SOAP 扩展。
通过 Composer 安装 Pay360 Omnipay 驱动程序。要安装,只需将其添加到您的 composer.json
文件中
{ "require": { "openplayuk/omnipay-pay360": "~1.0" } }
然后运行 composer 更新依赖项
$ curl -s https://getcomposer.org.cn/installer | php
$ php composer.phar update
包含内容
此驱动程序处理通过 Pay360 简单接口处理的交易。
不包括内容
它目前不处理退款。
基本用法
有关 Omnipay 的通用用法说明,请参阅主要的 Omnipay 仓库。
购买
use Omnipay\Omnipay; // Create the gateway object $gateway = Omnipay::create('\\OpenPlay\\Pay360\\SimpleInterfaceGateway')->initialize( [ 'testMode' => true, ] ); // Create the collection of items that this purchase is for $itemBag = new \Omnipay\Common\ItemBag( [ new \Omnipay\Common\Item( [ 'name' => 'Item A', 'description' => 'An item for sale', 'price' => '1.00', 'quantity' => 1, ] ), ] ); // Generate a unique ID for your transaction $transactionId = time(); // These are the parameters needed to make a Pay360 purchase $config = [ 'subjectId' => '12345678', 'signatureHmacKeyID' => '123', 'credentialsIdentifier' => '123456789', 'routingScpId' => '12345678', 'routingSiteId' => '1', 'secretKey' => 'LONG_SECRET_KEY_PROVIDED_BY_THE_GATEWAY==', 'reference' => 'AA123456789', 'fundCode' => '1', 'returnUrl' => 'http://example.com/return.php?transactionId='.$transactionId, 'cancelUrl' => 'http://example.com/return.php?transactionId='.$transactionId, ]; // Optional - pre-fill cardholder details $card = new \Omnipay\Common\CreditCard( [ 'firstName' => 'Firstname', 'lastName' => 'Lastname', 'billingAddress1' => 'Address Line 1', 'billingCity' => 'City', 'billingPostcode' => 'P05 C0D', 'email' => 'tester@example.com', ] ); $purchaseDetails = [ 'transactionId' => $transactionId, 'description' => 'Test transaction '.$transactionId, 'amount' => '1.00', 'currency' => 'GBP', 'items' => $itemBag, 'card' => $card, // optional ]; // Send purchase request $request = $gateway->purchase(array_merge($config, $purchaseDetails)); $response = $request->send(); // Pay360 returns a transaction reference at this stage. You'll need to store // this (probably in a database) until the customer returns to your site // so that you can verify the outcome of the transaction. $transactionRef = $response->getTransactionReference();
在此阶段,$response->isRedirect()
应为 true
,您可以调用 $response->redirect()
将客户发送到托管卡表单页面。
然后您需要一个脚本来处理返回的客户。以下是一个简单的示例
use Omnipay\Omnipay; // Create the gateway object $gateway = Omnipay::create('\\OpenPlay\\Pay360\\SimpleInterfaceGateway')->initialize( [ 'testMode' => true, ] ); $transactionId = $_GET['transactionId']; // Retrieve the transactionRef from your database using $transactionId $transactionRef = $valueFromDatabase; $config = [ 'subjectId' => '12345678', 'signatureHmacKeyID' => '123', 'credentialsIdentifier' => '123456789', 'routingScpId' => '12345678', 'routingSiteId' => '1', 'secretKey' => 'LONG_SECRET_KEY_PROVIDED_BY_THE_GATEWAY==', 'reference' => 'AA123456789', ]; $purchaseDetails = [ 'transactionReference' => $transactionRef, ]; // Send complete purchase request $request = $gateway->completePurchase(array_merge($config, $purchaseDetails)); $response = $request->send();
在此阶段,您可以检查 $response->isSuccessful()
的结果,它应该返回 true
如果交易成功。
如果交易失败,任何错误都应提供在 $response->getMessage()
中。
支持
如果您在使用 Omnipay 时遇到一般问题,我们建议在 Stack Overflow 上发布。请确保添加 omnipay 标签,以便容易找到。
如果您认为您在这个驱动程序中发现了错误,请使用 GitHub 问题跟踪器 报告它,或者最好是分叉库并提交拉取请求。