开发者

Authorize and then Capture programmatically using Authorize.Net in Magento

Can anyone help me in getting the Authorization and the Capture steps (code) usin开发者_运维知识库g Authorize.Net? It seems that everyone knows how to use both at the same time, however, there is no explanation as how we can do that into spearate steps, the Authorize first and the Capture after that (using a trasactionID).


Follow these steps to automatically capture your orders after the authorization:

  1. Configure the payment method to Authorize (not Direct Sale)

  2. Create an observer that will handle event called sales_order_payment_place_end with method called automaticalyCaptureOrder

  3. Use the following observer method code:

     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
         }
     }
    
  4. Sit back and relax :)

Please let me know if you have any difficulties with this solution and I'll get back to you.

UPDATE:

To capture order payment after some period of time you should load order object by its unique id, and perform similar actions as before, but also you need to save order object after calling the capture method:

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


CAPTURE transactions require the Authorization code that's returned from your AUTH transaction. The x_auth_code key needs to be set to the value of the Authorization Code from the AUTH request. In the delimited response of the AUTH transaction, it's field #5.

Refer to page 13 of the AIM guide. Also look at page 58 in Appendix B for the minimum required fields for each transaction type.

Good luck.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜