soliantconsulting/soliant-payment

2.0.0 2016-11-26 17:29 UTC

This package is auto-updated.

Last update: 2024-09-16 06:30:57 UTC


README

Build Status Coverage Status Latest Stable Version Latest Unstable Version Total Downloads License

快速入门

安装

通过 composer

{
    "require": {
        "soliantconsulting/soliant-payment": "^2.0.0" // ZF2 v1.0.1
    },
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/goetas/serializer.git"
        }
    ],
    "minimum-stability": "dev",
    "prefer-stable": true
}

使用

ZF3 v2.0.0

将模块添加到 modules.config.php

return [
    'Zend\Filter',
    'Zend\Hydrator',
    'Zend\Router',
    'Zend\Validator',
    'Soliant\Payment\Base',
    'Soliant\Payment\Authnet',
    'Soliant\Payment\Demo', // (Optional) Access demo via /soliant-payment route
];

ZF2 v1.0.1

将模块添加到项目配置 application.config.php。

'modules' => [
    'Soliant\Payment\Base', // Required for all payment modules
    'Soliant\Payment\[Payment Module]', // Where "Payment Module" is one of the following ("Authnet")
    'Soliant\Payment\Demo', // Access demo via /soliant-payment route
 ],

将支付模块配置目录中的 local.php.dist 文件复制到项目自动加载目录。

$ cp vendor/soliantconsulting/soliant-payment/module/[Payment Module]/[Payment Module].payment.local.php.dist 
config/autoload/[Payment Module].payment.local.php

使用以下之一的有效别名通过工厂注入所需的支付服务。

"authorizeAndCapture" // 授权并捕获信用卡或电子支票

ZF3 v2.0.0

public function __invoke(ContainerInterface $sm)
{
    return new MyService($sm->get("[Service Alias]"));
}

ZF2 v1.0.1

public function createService(ServiceLocatorInterface $serviceLocator)
{
    return new MyService($serviceLocator->get("[Service Alias]"));
}

每个支付服务应实现以下请求结构。请求数据通过数组传递到 "sendRequest" 方法,该方法返回一个响应对象。(有关数据数组结构和重写数据字段名称的信息,请参阅已实现的支付模块 payment.local.php.dist 文件。例如,链接)。可以使用 "isSuccess" 方法测试响应对象的成功,该方法返回布尔响应。

如果请求成功,应通过 "getData" 方法访问请求服务返回的任何数据。
如果请求失败,"getMessages" 方法将被填充。

$response = $this->[Service Alias]->sendRequest([
    'paymentType' => 'creditCard',
    'amount' => '5.00',
    'expirationDate' => '2017-01',
    'cardNumber' => '4111111111111111'
]);

if ($response->isSuccess()) {
    // get the response data
    $data = $response->getData();
} else {
    // get the errors
    $errors = $response->getMessages();
}