I am building an application that will need to create some database records in an external database when an order is purchased/completed.

So when the customer makes the purchase from our One Page Checkout cart page, I am hoping to use an Event Observer on
checkout_type_onepage_save_order_after and then connect to my external database and make an order database entry as well as a separate entry for each order item in my other database.

So my question is, how can I test my observer that should be triggered or caught when the order process is completed without you know, using my own credit card!?

Is there some sort of way to trigger or tesdt my code with PHP in a test file? Or some other way to make a test purchase on the live site?

1 Answer 1


What you're looking for is to test order placement!

Unit tests

There are a bunch of ways to do this, but what you probably need / want is to create unit tests. The two most prevalent at this time are:

Fortunately for you there's a new site for screencasts that just popped up and it goes through unit testing in general, and specifically for Magento:



Now, to answer your question. You shouldn't have to use your real credit card for development/testing if you're using a gateway with a test mode or a sandbox. Make sure your payment gateway provides this - change the API credentials to this sandbox environment and use test credit card data (see: http://www.getcreditcardnumbers.com/). All of the major providers offer this service.

Next - HOW do you test this? The old-fashioned way to do this is just bite the bullet and manually enter the order. (See: https://magento.stackexchange.com/a/836/336) This will allow you to enter the order over and over to test and debug.

  • Thanks Phil, good to see you're still active here! After posting this I came across a solution which involves enabling the Credit card (saved) payment option in Magento Admin panel and then you can run a test card using the CC number 4111111111111111 with any name and a future exp date. I really like your answer for being able to refresh the page and have the order re-submit, that will help a lot in my case as it already appears my Event Observer code is not working! The site is using One Page Checkout so I am trying to hook into the Event: checkout_type_onepage_save_order_after
    – JasonDavis
    May 25, 2015 at 0:51
  • Have you tried sales_order_place_after
    – philwinkle
    May 25, 2015 at 0:52
  • Would you happen to know from experience if there is an alternative Event that will fire on order purchase regardless of order type. I take it from the name of checkout_type_onepage_save_order_after that it is only fired when One Page Checkout is used. My boss does use one page checkout but I am not 100% sure if it is a different one or the same one. I did look at the Magento source code where there checkout_type_onepage_save_order_after event is fired and see that it is in the core Magento code though. I have more testing to do though just in case it is an error on my end.....
    – JasonDavis
    May 25, 2015 at 0:54
  • ...continued....Right now for testing I am trying to have my event observer send an email and also log to a log file and both are not working! Also I see you posted a response already! pretty much answer my question, thanks! getcreditcardnumbers.com this is a great find, thanks for sharing ill pass it on as well!
    – JasonDavis
    May 25, 2015 at 1:06
  • Also, your event sales_order_place_after does the trick, thanks again
    – JasonDavis
    May 25, 2015 at 1:32

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.