该包已被废弃,不再维护。未建议替代包。

Dotpay 是专为波兰电商提供的最全面的在线全球支付解决方案。该仓库包含支付实现和验证层的中间件。

v0.19 2018-04-13 05:31 UTC

This package is not auto-updated.

Last update: 2020-08-22 07:24:45 UTC


README

Dotpay 是专为波兰电商提供的最全面的在线全球支付解决方案。该仓库包含支付实现和验证层的中间件。

Dotpay

文档

需要更多详细信息吗?这里是API的完整文档

使用此库

安装

源代码通过 ComposerPackagist 分发。

composer require krzysiekpiasecki/dotphpay

支付中间件

自定义域支付处理器必须只实现 \Dotpay\Server\Handler\PaymentHandlerInterface 接口。您必须在将客户端重定向到支付网关之前,至少使用它来持久化客户端支付。

class BusinessPaymentHandler implements \Dotpay\Server\Handler\PaymentHandlerInterface
{
    public function handle(Payment $payment)
    {
        // TODO: Implement handle() method.
    }
}

实现处理器后,创建 PSR-15 兼容的请求对象,例如使用 Zend Diactoros 组件。

$psrRequest = Zend\Diactoros\ServerRequestFactory::fromGlobals(
    $_GET,
    $_POST
);

最后,调用支付中间件来执行您自己的支付处理器,然后使用例如 Zend Diactoros 组件发送重定向响应到客户端。

$paymentMiddleware = new \Dotpay\Server\Payment();

$httpResponse = $paymentMiddleware->process(
    $psrRequest,
    new \Dotpay\Server\Handler\PaymentHandler(
        '747789',
        'Np3n4QmXxp6MOTrLCVs905fdrGf3QIGm',
        new BusinessPaymentHandler()
    )
);

$emitter = new \Zend\Diactoros\Response\SapiEmitter();
$emitter->emit($httpResponse);

URLC 中间件

自定义域 URLC 处理器必须只实现 \Dotpay\Server\Handler\URLCHandlerInterface 接口。您必须使用它来确认交易完成或处理状态变化。

class BusinessURLCHandler implements \Dotpay\Server\Handler\URLCHandlerInterface
{
    public function handle(\Dotpay\Response\URLC $URLC)
    {
        // TODO: Implement handle() method.
    }
}

实现处理器后,创建 PSR-15 兼容的请求对象,例如使用 Zend Diactoros 组件。

$psrRequest = \Zend\Diactoros\ServerRequestFactory::fromGlobals(
    $_POST
);

最后,调用 URLC 中间件来执行您自己的 URLC 处理器,并在交易正确处理时,使用例如 Zend Diactoros 组件发送响应 "OK" 到 Dotpay。

$urlcMiddleware = new \Dotpay\Server\Payment();

$httpResponse = $urlcMiddleware->process(
    $psrRequest, 
    new \Dotpay\Server\Handler\URLCHandler(
        'Np3n4QmXxp6MOTrLCVs905fdrGf3QIGm',
        new BusinessURLCHandler()
    )
);

$emitter = new \Zend\Diactoros\Response\SapiEmitter();
$emitter->emit($httpResponse);

错误代码中间件

自定义域处理器用于从 Dotpay 服务器获取错误代码必须只实现 \Dotpay\Server\Handler\ErrorCodeHandlerInterface 接口。

class BusinessErrorCodeHandler implements \Dotpay\Server\Handler\ErrorCodeHandlerInterface  {
    public function handle(string $errorCode)
    {
        // TODO: Implement handle() method with custom logic
    }
}

实现处理器后,创建 PSR-15 兼容的请求对象,例如使用 Zend Diactoros 组件。

$psrRequest = Zend\Diactoros\ServerRequestFactory::fromGlobals(
    $_GET
);

最后,调用错误代码中间件来执行您自己的错误代码处理器。

$errorCodeMiddleware = new \Dotpay\Server\ErrorCode();

$httpResponse = $errorCodeMiddleware->process(
     $psrRequest,
     new \Dotpay\Server\Handler\ErrorCodeHandler(
         new BusinessErrorCodeHandler()
     )
);

验证层

该库使用 Symfony Validator 组件来验证请求。如果您愿意,可以使用该库提供的验证层独立使用。验证示例在此

use Symfony\Component\Validator\Validation;

$validator = Validation::createValidator();
$violations = $validator->validate('-1',
    new \Dotpay\Request\Validator\Constraint\IdConstraint()
);

if (0 !== count($violations)) {
    // there are errors, now you can show them
    foreach ($violations as $violation) {
        echo $violation->getMessage().'<br>';
        // Output: The value "-1" is not a valid 'id' parameter
    }
}

其他资源

Dotpay 技术手册:支付实现
使用 Symfony 验证组件