webgriffe/lib-monetaweb2 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

webgriffe/lib-monetaweb2

Composer 安装命令:

composer require webgriffe/lib-monetaweb2

包简介

Webgriffe Setefi MonetaWeb 2.0 PHP library

README 文档

README

Run Status

This library provides a complete integration for the XML Hosted 3DSecure protocol of Setefi MonetaWeb 2.0 payment gateway. It was developed following the technical documentation provided by Setefi released in July 2017.

Installation

In order to use this library, first of all import it using composer:

composer require webgriffe/lib-monetaweb2

Usage

Payment initialization

You can generate a payment initialization URL using the GatewayClient class:

$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'
);

The getPaymentPageInfo method returns a GatewayPageInfo value object that encapsulates 3 values:

  • Payment ID, unique ID of the payment session
  • Security Token, an hash that should be compared to the one returned in the response of the notify request (server-to-server notification, of which we talk below)
  • Hosted Page URL, the URL to which the user must be redirected in order to perform the payment

Server to server notification

Once that you redirected the user to the Hosted Page URL a server-to-server notification will be perfomed by MonetaWebDue to one of the 2 urls that you specified when you called getPaymentPageInfo. In the example of the payment initialization the user will be redirected to http://www.merchant.it/notify/ in case of successful operation and to http://www.merchant.it/error/ otherwise.

You can handle this request by using the handleNotify method of the GatewayClient class:

$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);

The result of the handleNotify method could be a PaymentResultInfo object or a PaymentResultErrorInfo:

  • The former object is returned when the notify request comunicates that the payment was handled successfully (this does not means that the payment was successful!). The properties of this object are mapped 1to1 with the successful notify response parameters, so refer to the payment gateway's integration documentation for more details about them.
  • Instead, the latter object is returned when the notify request comunicates an error. This means that something went unexpectedly wrong during the payment. This has nothing to do with, for example, a "canceled" order: cases like this are not unexpected and so they generates a PaymentResultInfo object (as explained above). Even the properties of this object are mapped 1to1 with the parameters of the "faulty notify response", so refer to the payment gateway's integration documentation for more details about them.

The Security Token is a value that is comunicated by Setefi both in the payment initialization response and the server to server notification. You should compare them to be ensure the integrity of the payment. In order to do this, the GatewayClient class has a method called verifySecurityToken that accepts the initialization's security token and the payment result info (returned by the handle notify) as parameters and returns a boolean:

$gatewayClient = new Webgriffe\LibMonetaWebDue\Api\GatewayClient();
...
$match = $gatewayClient->verifySecurityToken($storedSecurityToken, $paymentResult);

So an example of a real implementation for the server to server notification could be this:

$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
            ..
        }
    }
    ..
}

Contributing

Fork this repository, make your changes and submit a pull request. Please run the tests and the coding standards checks before submitting a pull request. You can do it with:

vendor/bin/phpspec run
vendor/bin/phpcs --standard=PSR2 src/

License

This library is under the MIT license. See the complete license in the LICENSE file.

Credits

Developed by Webgriffe®.

webgriffe/lib-monetaweb2 适用场景与选型建议

webgriffe/lib-monetaweb2 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19.28k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2017 年 09 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 webgriffe/lib-monetaweb2 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 webgriffe/lib-monetaweb2 我们能提供哪些服务?
定制开发 / 二次开发

基于 webgriffe/lib-monetaweb2 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 19.28k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 16
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-09-29