I have create functionality on event "sales_order_place_after". I have to Send "COUPON CODE" for an order placed with this event "sales_order_place_after". If someone does fail credit card transaction then also this "COUPON CODE" was sent. This is wrong.

And also order created with "Canceled" on


. Can you suggest me any event for success order only?


There are two way to send your coupon after cc payment is success

1st (Recommended) :

you can create a custom event after cc transaction is completed Ex :

Place this code on transaction complete file (You need to find this file)

Mage::dispatchEvent('my_custom_event', $order);

Place following code into any module config.xml file


Create Observer file into your model directory and put following code

class Namespace_Modulename_Model_Observer
  public function my_custom_method($observer) {
    //get order and check payment method and check transaction is success or not

2nd :

  1. Create new table with order id, coupon code, issendcopon.
  2. Create sales_order_place_after event and insert data into new table.
  3. Set cron after 10 mins and check which have 0 value issendcopon and send coupon which order is success.
|improve this answer|||||

you can change your event to checkout_onepage_controller_success_action

|improve this answer|||||
  • Whenever CC transaction is made through any portal or gateway or via APIs, the transaction responses are always returned to merchant website.
  • e.g. if a user performs transaction from your website, you must capture the transaction response/status before sending the Coupon Code
  • Fist apply check to validate if the transaction is successful, only then you should send the Coupon Code
  • Because sales_order_place_after is triggered whenever any order is successfully placed, it has nothing to do with the order payment process
  • So in short, there can be a successful order but can be with failed payment transaction
  • Apply Coupon Code sending function only at order success event (success page or success controller action) instead of sales_order_place_after
  • Because sales_order_place_after is triggered as soon as you submit order from checkout, you must wait to check on success page if the order is successful or not.

Hope this helps.

|improve this answer|||||
  • Things are ok. But How we can validate this "if the order is successful or not." – Pratik Kamani Jul 13 '17 at 12:00
  • I just send a coupon code for next order benefit on "sales_order_place_after ".When I place an order and with credit card payment fail, I got this coupon code via mail. This is wrong. – Pratik Kamani Jul 13 '17 at 12:01
  • You have to use either APIs or something that must be provided by the payment gateway. e.g. If you are using any third party payment gateway then you must get responses against each transaction on your response back URL. If you are using APIs, then you must be getting transaction status on your API response. What CC payment gateway are you using ? – Ahsan Horani Jul 14 '17 at 12:09
  • 1
    Use checkout_onepage_controller_success_action event to validate your transactions – Ahsan Horani Jul 14 '17 at 12:09

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.