1

I have a Magento site where we currently do an auth and capture at time of order. We want to be able to offer back orders but to do that we want/need to make the payment method do an auth only and then capture at time of shipment.

We used Authorize.net and was thinking that I could replicate the existing Authorize.net payment gateway code and make all the neccessary code changes so that it showed up as a new payment method, something like Authorize.net (Back Orders).

When there is no back order product in the cart the Authorize.net (Back Orders) option would not be avaialbel but if there is any back order item in the cart then the Authorize.net (Back Orders) would be the only option available.

So I was just wondering if this makes sense or if there is an easier way of doing this?

2

It may be possible to temporarily alter the system configuration, but the trick is to do it before the payment info is processed. The function that processes whether it is AUTH or CAPTURE is Mage_Sales_Model_Order_Payment::place(), but a better hook is to use the "sales_order_place_before" event:

/**
 * Changes the Authorize.NET payment action (AUTH or CAPTURE)
 * depending on whether the order has backorder items.
 *
 * Event(s): sales_order_place_before
 *
 * @param  Varien_Event_Observer $observer
 */
public function backorderItemsPaymentAction(Varien_Event_Observer $observer)
{
    /* @var $order Mage_Sales_Model_Order */
    $order = $observer->getEvent()->getOrder();
    $store = $order->getStore();

    if (EVALUATE_ORDER_HERE_FOR_BACKORDER_ITEMS) {
        $store->setConfig(
            'payment/authorizenet/payment_action', 
            Mage_Paygate_Model_Authorizenet::ACTION_AUTHORIZE
        );
    }
}

This changes the IN-MEMORY setting of the system config until the end of the request execution and will not be saved. Also, this solution wouldn't adversely affect anything if a different payment is selected. You will of course need to test this to make sure it is working as expected.

Let me know if you need more help.

EDIT:

Actually it would be considered bad practice to change the system config in this manner, which is CONTRARY to what the system config in the admin is set to. To make this proper, add another system configuration field (payment/authorizenet/payment_action_backorder) under authorizenet just for the backorder items, so that you can have two distinct actions and its clear in the Magento Admin what is going on. Then copy the setting value from payment_action_backorder to payment_action like the observer is doing in the code above.

  • That sounds like that should work great and I guess if the check if a back order items is not in the cart them it should probably be st back to AUTH and CAPTURE since the user could exit out of the check out process, remove the back order item(s) and go back into the check out process? – Trevor Orr Nov 9 '16 at 21:33
  • Only change the payment action if the order (and its no longer the cart here, but an order) has backorder items, and leave the default behavior for Auth and Capture the way that it is on the website now. – Phil M Nov 9 '16 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.