Isy
Isy

Reputation: 21

Authorize and then Capture programmatically using Authorize.Net in Magento

Can anyone help me in getting the Authorization and the Capture steps (code) using 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).

Upvotes: 2

Views: 6331

Answers (2)

Ivan Chepurnyi
Ivan Chepurnyi

Reputation: 9223

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)

Upvotes: 5

Shiun
Shiun

Reputation: 2677

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.

Upvotes: 0

Related Questions