1

I'm building a module that integrates 3rd party gift cards. I'm using an observer before the order is placed to charge the card.

public function beforeOrderPlace($observer)
{
    $order = $observer->getOrder();
    $this->chargeGiftcard($order->getGiftcardNumber(), $order->getGiftcardAmount());
}

However, in the event the order can't be created (i.e. the remaining balance charged to a credit card failed) I need to "uncharge" the giftcard from the 3rd party, with something like

public function rollback($observer)
{
    $order = $observer->getOrder();
    $this->addBalanceToGiftcard($order->getGiftcardNumber(), $order->getGiftcardAmount());
}

How can I hook into the transaction used during order creation to add my rollback?

1
  • Would there be any events dispatch on your payment module upon failed payment? I'm having a hard time to find events dispatched by Magento for failed payment. Apr 28, 2015 at 23:08

1 Answer 1

1

I would hook the observer to the invoice create event so you're sure everything went well. When a CC payment is cleared it will create an invoice in Magento.

Next to that you'll need to do a giftcard refund when a creditmemo is created. As with any Payment method there are a dozen more checks I can think of you might want to do to prevent overcharging or fraud. Did you take a look at any of the existing giftcard modules out there to see how they approached the issue?

Check out this list of events to find a good one to hook https://www.nicksays.co.uk/magento-events-cheat-sheet-1-7/

1
  • I have a requirement to charge the card after order place, not invoice. And yes, I'm emulating Enterprise Giftcards. Apr 29, 2015 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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