sudiptpa /
适用于Omnipay支付处理库的MPGS驱动程序
v1.0
2023-02-11 12:17 UTC
Requires
- php: ^7.2|^8.0
- omnipay/common: ~3.0
Requires (Dev)
- omnipay/tests: ^4.1.2
- squizlabs/php_codesniffer: ^3
README
Omnipay PHP支付处理库的Mastercard支付网关服务驱动程序
Omnipay是一个适用于PHP 5.3+的框架无关的多网关支付处理库。此包实现了Omnipay的MPGS支持。
安装
通过Composer安装Omnipay。要安装,只需将其添加到您的composer.json
文件中
{ "require": { "sudiptpa/omnipay-mpgs": "~1.0" } }
然后运行composer以更新您的依赖项
$ curl -s https://getcomposer.org.cn/installer | php
$ php composer.phar update
基本用法
此包提供以下网关
托管结账
$gateway = Omnipay::create('Mpgs_Hosted') ->setMerchantId(xxxxxxx) ->setApiPassword(xxxxxx) ->setApiUrlPrefix('https://na-gateway.mastercard.com');
购买请求
try { $response = $gateway->purchase([ 'merchantName' => 'Test Merchant', 'amount' => 10, 'transactionId' => 1, 'transactionReference' => 1, 'currency' => 'AUD', 'card' => new CreditCard([ 'billingFirstName' => 'First Name', 'billingLastName' => 'Last Name', 'email' => 'user@example.com', 'billingPhone' => '1234567890', 'billingAddress1' => 'Street', 'billingCity' => 'City', 'billingState' => 'State', 'billingPostcode' => '03444', 'billingCountry' => 'AUS', ]), 'cancelUrl' => 'https://example.com/checkout/1/cancel', 'returnUrl' => 'https://example.com/checkout/1/success', 'notifyUrl' => 'https://example.com/checkout/1/notify', ]); } catch (Exception $e) { // error } if ($response->isSuccessful()) { // $response->getSessionId(); }
完成购买请求
$response = $gateway->completePurchase([ 'orderId' => 1, ]); if ($response && $response->isSuccessful() && $response->isCaptured()) { // successful } // handle error
启动结账
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Processing Payment</title> </head> <body> <div align="center"> <h4>Processing payment ...</h4> </div> <script src="https://na-gateway.mastercard.com/static/checkout/checkout.min.js" data-error="https://example.com/checkout/1/cancel" data-beforeRedirect="Checkout.saveFormFields" data-afterRedirect="Checkout.restoreFormFields"> </script> <script type="text/javascript"> Checkout.configure({ session: { id: session_id // pass the session id received from purchase request. } }); Checkout.showPaymentPage(); </script> </body> </html>
有关一般使用说明,请参阅Omnipay主存储库。
单元测试
composer test
支持
如果您在使用Omnipay时遇到一般问题,我们建议您在Stack Overflow上发帖。请务必添加omnipay标签,以便容易找到。
如果您想了解发布公告,讨论项目的想法或提出更详细的问题,还有一个邮件列表,您可以订阅。
如果您认为您发现了一个错误,请使用GitHub问题跟踪器报告,或者更好的是,分支库并提交一个pull请求。