krzysiekpiasecki / dotphpay
Dotpay 是专为波兰电商提供的最全面的在线全球支付解决方案。该仓库包含支付实现和验证层的中间件。
Requires
- doctrine/annotations: ^1.5.1
- doctrine/cache: ^1.7
- psr/http-server-middleware: 1.0.0
- symfony/form: ^4.0
- symfony/http-foundation: ^4.0
- symfony/psr-http-message-bridge: ^1.0
- symfony/security-csrf: ^4.0
- symfony/validator: ^3.4
- zendframework/zend-diactoros: ^1.7
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.10
- phpdocumentor/reflection-docblock: ~2.0
- phpunit/phpunit: ^5.0
- sami/sami: 4.0.14
- symfony/config: ^4.0
- symfony/translation: ^4.0
- symfony/twig-bridge: ^4.0
- zendframework/zend-diactoros: ^1.7
README
Dotpay 是专为波兰电商提供的最全面的在线全球支付解决方案。该仓库包含支付实现和验证层的中间件。
文档
需要更多详细信息吗?这里是API的完整文档。
使用此库
安装
源代码通过 Composer 和 Packagist 分发。
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 } }