使用Magento中的Authorize.Net以编程方式授权然后捕获

时间:2010-07-21 05:01:30

标签: magento authorize.net

任何人都可以帮助我使用Authorize.Net获取授权和捕获步骤(代码)吗?似乎每个人都知道如何同时使用两者,但是,没有任何解释,我们如何能够将其转化为特殊步骤,首先是授权,之后是捕获(使用trasactionID)。

2 个答案:

答案 0 :(得分:5)

按照以下步骤在授权后自动捕获您的订单:

  1. 将付款方式配置为授权(非直接销售)

  2. 使用名为sales_order_payment_place_end

  3. 的方法创建一个处理名为automaticalyCaptureOrder的事件的观察者
  4. 使用以下观察者方法代码:

     public function automaticalyCaptureOrder(Varien_Event_Observer $observer)
     {
         $payment = $observer->getEvent()->getPayment();
         // Add additional check for payment method instance, 
         // We need to be sure that only Authorize.Net payment will be captured
         if ($payment->getMethodInstance() instanceof Mage_Paygate_Model_Authorizenet) {
             $payment->capture(null); // null value tells Magento to create
                                      // an invoice automatically
         }
     }
    
  5. 坐下来放松一下:)

  6. 如果您对此解决方案有任何困难,请告诉我,我会尽快回复您。

    <强>更新

    要在一段时间后捕获订单付款,您应该按其唯一ID加载订单对象,并执行与以前类似的操作,但您还需要在调用捕获方法后保存订单对象:

    $order->load($orderId); // Or $order->loadByIncrementId($incrementId);
    $order->getPayment()->capture(null); // Capturing the payment
    $order->save(); // Save updated information (transaction ids, order status)
    

答案 1 :(得分:0)

CAPTURE事务需要从AUTH事务返回的授权代码。需要将x_auth_code密钥设置为AUTH请求中的授权代码的值。在AUTH事务的分隔响应中,它是#5字段。

请参阅AIM指南的第13页。另请参阅附录B中的第58页,了解每种交易类型的最低必填字段。

祝你好运。