webgriffe / lib-monetaweb2
Webgriffe Setefi MonetaWeb 2.0 PHP 库
Requires
- guzzlehttp/guzzle: ^6.3
- respect/validation: ^1.1
Requires (Dev)
- phpspec/phpspec: ^2.5.8
- squizlabs/php_codesniffer: ^3.0
This package is auto-updated.
Last update: 2024-09-17 10:32:47 UTC
README
此库为 Setefi MonetaWeb 2.0 支付网关的 XML 托管 3DSecure 协议提供了完整的集成。它是根据 Setefi 在 2017 年 7 月发布的技术文档开发的。
安装
要使用此库,首先需要使用 composer 导入它
composer require webgriffe/lib-monetaweb2
用法
支付初始化
您可以使用 GatewayClient
类生成支付初始化 URL
$gatewayClient = new Webgriffe\LibMonetaWebDue\Api\GatewayClient();
$getPaymentPageInfo = $gatewayClient->getPaymentPageInfo(
'https://ecommerce.keyclient.it/ecomm/ecomm/DispatcherServlet',
'99999999',
'99999999',
1428.7,
'EUR',
'ITA',
'http://www.merchant.it/notify/',
'http://www.merchant.it/error/',
'TRCK0001',
'Descrizione',
'Nome Cognome',
'nome@dominio.com',
'Campo Personalizzabile'
);
getPaymentPageInfo
方法返回一个封装了 3 个值的 GatewayPageInfo
值对象
- 支付 ID,支付会话的唯一 ID
- 安全令牌,一个哈希值,应与通知请求响应(我们下面会提到的服务器到服务器通知)中返回的值进行比较
- 托管页面 URL,用户必须重定向到该 URL 以执行支付
服务器到服务器通知
当您将用户重定向到 托管页面 URL
后,MonetaWeb 将通过您在调用 getPaymentPageInfo
时指定的 2 个 URL 之一执行服务器到服务器通知。在支付初始化的示例中,如果操作成功,用户将被重定向到 http://www.merchant.it/notify/
,否则重定向到 http://www.merchant.it/error/
。
您可以使用 GatewayClient
类的 handleNotify
方法处理此请求
$gatewayClient = new Webgriffe\LibMonetaWebDue\Api\GatewayClient();
...
// $psrRequest must be an instance of an object that implements the \Psr\Http\Message\RequestInterface
$paymentResult = $gatewayClient->handleNotify($psrRequest);
handleNotify
方法的返回结果可以是 PaymentResultInfo
对象或 PaymentResultErrorInfo
- 当通知请求表示支付已成功处理时(这并不意味着支付已成功!)返回前者对象。此对象的可选属性与成功通知响应参数一一对应,因此请参阅支付网关的集成文档以获取更多详细信息。
- 相反,当通知请求表示出现错误时,返回后者对象。这意味着支付过程中出现了意外错误。这与“已取消”订单等情况无关:这些情况是意料之中的,因此会生成一个 PaymentResultInfo 对象(如上所述)。即使此对象的可选属性也与“错误的”通知响应参数一一对应,因此请参阅支付网关的集成文档以获取更多详细信息。
安全令牌是一个在支付初始化响应和服务器到服务器通知中由 Setefi 通信的值。您应该比较它们以确保支付的安全。为此,GatewayClient
类有一个名为 verifySecurityToken
的方法,该方法接受初始化的安全令牌和支付结果信息(由 handle notify 返回)作为参数,并返回一个布尔值
$gatewayClient = new Webgriffe\LibMonetaWebDue\Api\GatewayClient();
...
$match = $gatewayClient->verifySecurityToken($storedSecurityToken, $paymentResult);
因此,服务器到服务器通知的真实实现示例可以是以下内容
$gatewayClient = new Webgriffe\LibMonetaWebDue\Api\GatewayClient();
...
$paymentResult = $gatewayClient->handleNotify($psrRequest);
if ($paymentResult instanceof PaymentResultErrorInfo) {
..
} else {
/** @var PaymentResultInfo $paymentResult */
if (!$paymentResult->isCanceled()) { // the security token is not returned if the payment was canceled
if (!$gatewayClient->verifySecurityToken($storedSecurityToken, $paymentResult)) {
// error
..
}
}
..
}
贡献
分叉此存储库,进行您的更改并提交一个 pull 请求。请在提交 pull 请求之前运行测试和编码标准检查。您可以使用以下方法完成此操作
vendor/bin/phpspec run
vendor/bin/phpcs --standard=PSR2 src/
许可证
此库受 MIT 许可证的保护。请参阅 LICENSE 文件中的完整许可证。
致谢
由 Webgriffe® 开发。