hochstrasserio / wirecard-bundle
集成了hochstrasser/wirecard库的Bundle
v1.1.0
2017-08-10 15:49 UTC
Requires
- php: >=5.5.0
- hochstrasserio/wirecard: ^0.2.0 || ^1.0.0
- symfony/symfony: ^2.7.0 || ^3.0.0
Requires (Dev)
- phpunit/phpunit: ^4.0.0
This package is not auto-updated.
Last update: 2024-09-14 18:26:04 UTC
README
安装
使用Composer安装包
composer require 'hochstrasserio/wirecard-bundle:dev-master'
将Bundle添加到您的AppKernel
// AppKernel.php $bundles = [ … new Hochstrasser\WirecardBundle\HochstrasserWirecardBundle(), … ];
使用方法
Bundle引用配置
hochstrasser_wirecard: # Checkout language, required language: ~ # Customer ID, required customer_id: ~ # Secret, required secret: ~ # Shop ID, optional shop_id: ~ # Password for backend requests, optional backend_password: ~ # User agent used for requests, change this to your app name user_agent: "Hochstrasser/Wirecard" # Version of DataStorage JS, possible values are null and "pci3" javascript_script_version: ~
获取Wirecard上下文
<?php $context = $this->get('hochstrasser_wirecard.context');
使用WirecardController处理确认请求
此Bundle包含了一个控制器实现,用于处理发送到支付请求中提供的confirmUrl
参数的请求。
confirmUrl
参数设置了一个URL,该URL会通过Wirecard请求支付信息和状态进行更新。
在路由配置中注册控制器以启用此功能
wirecard_confirm: path: /wirecard/confirm defaults: _controller: hochstrasser_wirecard.wirecard_controller:confirmAction
然后将URL传递给InitPaymentRequest
<?php $request->setConfirmUrl($this->generateUrl('wirecard_confirm'), [], UrlGeneratorInterface::ABSOLUTE_URL);
控制器随后检查responseFingerprint。当指纹有效时,它将在应用的事件分发器中触发Hochstrasser\WirecardBundle\Event\ConfirmPaymentEvent
。
处理此事件以实现您的业务逻辑,例如排队发送订单确认邮件。
例如
<?php use Hochstrasser\WirecardBundle\Event\ConfirmPaymentEvent; $listener = function (ConfirmPaymentEvent $event) { // Response parameters // See: https://guides.wirecard.at/response_parameters $data = $event->getData(); if ($event->isPaymentState(ConfirmPaymentEvent::SUCCESS)) { // We got the payment, queue order confirmation email } else if ($event->isPaymentState(ConfirmPaymentEvent::FAILURE)) { // Notify the user that something went wrong with the payment, and order // is on hold } };
ConfirmPaymentEvent
还包含Wirecard支付响应状态的常量
SUCCESS
:支付成功,例如发送订单确认PENDING
:支付仍在处理中CANCEL
:支付被客户取消FAILURE
:支付失败,即通知用户订单无法处理