mothership-ec / cog-mothership-ecommerce

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

Mothership中的E-Commerce处理Cog模块

3.8.0 2016-03-23 17:32 UTC

README

配置

分发

  • 打印机名称: ...

支付

  • gateway:要使用的网关名称。注意该网关必须对系统可用。
  • use-test-payments:使用外部支付网关的测试环境。
  • salt:在支付过程中对数据进行散列时使用。

网关

支付网关允许您通过外部服务处理支付。

在Mothership中,网关有两个组件;一个是实现Gateway\GatewayInterface的实现,用于与外部服务通信,另一个是处理购买和退款请求的控制器。

默认网关

ZeroPayment

零支付网关是最基本的实现,它仅完成订单并直接重定向到成功URL。

LocalPayment

本地支付网关是零支付的扩展。

使用新的网关提供商扩展

要添加新的网关提供商,您需要创建一个新的适配器,该适配器实现Gateway\GatewayInterface并将其附加到gateway.collection服务。

其次,您需要实现Controllers\Gateway\PurchaseControllerInterfaceControllers\Gateway\RefundControllerInterface。如果您的网关不支持退款,则应将refund()方法返回$this->createNotFoundException()

当然,您的网关和控制器可以使用额外的处理新提供商特定功能和流程的方法,例如外部服务的回调。

购买

购买过程是一个系统,它向网关发送支付请求,并在成功响应中创建/修改对象,并对已取消和失败的购买做出相应反应。例如,标准结账流程在成功时将订单保存到数据库并记录其付款。

当编写新的购买过程时,'继续支付'操作应使用$this->get('gateway')->getPurchaseControllerReference()将请求转发到当前网关的购买控制器引用。

此转发请求应传递正在购买的PayableInterface实例和阶段配置。

$controller = 'Message:Mothership:Foo::Controller:Bar';
return $this->forward($this->get('gateway')->getPurchaseControllerReference(), [
    'payable' => $instanceOfPayableInterface,
    'stages'  => [
        'cancel'  => $controller . '#cancel',  // Method for reacting to cancelled purchases
        'failure' => $controller . '#failure', // Method for reacting to failed purchases
        'success' => $controller . '#success', // Method for reacting to successful purchases
    ]
]);

购买过程需要一个实现Controllers\Gateway\CompleteControllerInterface的控制器。这应该实现successcancelfailure方法。

success() 方法应将可支付对象转换为它所表示的对象的已保存实例,例如订单,根据需要存储任何付款,并返回一个 JsonResponse 中的成功 URL。此完成过程应在通过外部提供商确认购买时由网关购买控制器调用。

退款

退款过程与购买过程相同,除了您需要将请求转发到 $this->get('gateway')->getRefundControllerReference() 并传递一个额外的 reference 参数。退款不需要 cancel 阶段。

$controller = 'Message:Mothership:Foo::Controller:Bar';
return $this->forward($this->get('gateway')->getRefundControllerReference(), [
    'payable'   => $instanceOfPayableInterface,
    'reference' => 'reference for the payment made previously being refunded',
    'stages'    => [
        'failure' => $controller . '#failure', // Method for reacting to failed refunds
        'success' => $controller . '#success', // Method for reacting to successful refunds
    ]
]);