Jump to content

Execute code after payment received


Recommended Posts

Hi,

I need to execute a php code once the payment has been received, until now I had only 1 payment method so I wrote in on the confirmation hook of that payment method, but now I'll add more payment methods...so I'll like to know if there is a common place to put that code, instead of each payment confirmation for each different method. So I have to write it once!

Thanks

Share this post


Link to post
Share on other sites
22 hours ago, Maria Gonzalez said:

For all payment methods I have enabled? So..there is no single point?

Not all payments are received when the order is created.  So again I ask, is it upon order creation, or is it upon payment received (those could be different things depending on the type of payment and payment module used)

If you accept orders using COD, check or bankwire, the payment is NOT received when an order is created.

If you use a module that accepts credit cards, then is payment received when the order is created?  Or is payment received when the payment provider settles the transaction at night and the money moves into your account the following day.

You need to start thinking about this before asking your questions.

Share this post


Link to post
Share on other sites

orderconfirmation hook is used to display information to the customer on the front end order confirmation page.  Since you said you need to execute PHP code, then I assume this is the wrong hook to use

First you would create your own module that registers one of the following hooks.

You can use actionValidateOrder hook, which is called anytime a new order is created.  Then you can check the order status to confirm the payment status, and then execute your code

Or you can use the actionPaymentConfirmation hook, which would be called anytime an orders order status changes to 'payment accepted'.  This is probably the most appropriate hook to use, but it assumes the payment modules you use to accept payments treat this order status properly

 

Share this post


Link to post
Share on other sites
On 17/11/2017 at 1:52 PM, bellini13 said:

Or you can use the actionPaymentConfirmation hook, which would be called anytime an orders order status changes to 'payment accepted'.  This is probably the most appropriate hook to use, but it assumes the payment modules you use to accept payments treat this order status properly

 

 

That is what I need! 

Another question, sometimes my code will "fail" (i.e. if not enough stock). Is anyway to automatically relauch that script (that own module, so recheck if enough stock and continue without failing), for example every 10 minutes.....

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More