Quick onAfterOrderConfirm question

  • Posts: 10
  • Thank you received: 0
6 months 1 week ago #319606

I want to run code that after order confirm sends SMS, I can directly use this trigger without caring what payment gateway it is correct?

function onAfterOrderConfirm(&$order){
//Run my SMS code here
}

Thanks so much

Please Log in or Create an account to join the conversation.

  • Posts: 71219
  • Thank you received: 10726
  • MODERATOR
6 months 1 week ago #319608

Hi,

No that trigger is called after the checkout for the payment method selected so that it can redirect to the payment gateway.
What you want to do is to implement instead the "onAfterOrderUpdate" trigger and check the $order->order_status and the $order->old->order_status so that you can see the order is going from "created" to "confirmed" and then run your code.
Doing it like this will indeed work regardless of the payment method being used (unless the payment plugin directly creates the order as confirmed, in that case, you'll want to also implement the onAfterOrderCreate trigger and check the order status in $order->order_status).
When we develop such plugin to act upon an order being paid, we usually implement both the onAfterOrderUpdate and onAfterOrderCreate so that we can take into account all the ways different payment plugins can work.

Please Log in or Create an account to join the conversation.

  • Posts: 10
  • Thank you received: 0
6 months 1 week ago #319619

Got it, thanks so much!

Please Log in or Create an account to join the conversation.

  • Posts: 10
  • Thank you received: 0
6 months 1 week ago #319755

so if payment plugin sends back payment confirmation change order to confim, onAfterOrderUpdate the trigger should be
if( $order->old->order_status =='created' && $order->order_status == 'confirmed') correct?

But if I have a trigger that is order_status == confirm (and ignore the ->old->order_status, then the function would be sent twice if an admin changed the order created -> to confirmed manually from back end. I hope I'm making sense...

Thanks!

Please Log in or Create an account to join the conversation.

  • Posts: 10
  • Thank you received: 0
6 months 1 week ago #319756

also, it works for manual backend set to confirm, but if payment gateway sends back confirmation after paid and order status is changed to confirm, the plugin doesn't work

Please Log in or Create an account to join the conversation.

  • Posts: 71219
  • Thank you received: 10726
  • MODERATOR
6 months 1 week ago #319776

Hi,

The plugin will also be triggered for the onAfterOrderUpdate when the payment plugin changes the status of the order to confirmed after the payment. That is unless the payment plugin isn't coded properly.
Note however that in such case, the order confirmation usually happens with a direct request from the payment gateway server to your server. So as a customer you don't see anything on the interface.
If you want to check that the trigger is called in such case, you need to write text in a file and then check that file content.

Please Log in or Create an account to join the conversation.

  • Posts: 10
  • Thank you received: 0
6 months 1 week ago #319804

Thank you, I found out the problem is payment notification can't run " $orderInDb = $orderClass->loadFullOrder($order->order_id); "
that's correct right?

Please Log in or Create an account to join the conversation.

  • Posts: 71219
  • Thank you received: 10726
  • MODERATOR
6 months 1 week ago #319809

Hi,

Well, yes and no.
If you call it like that, it will only work if the current user session is the owner of the order.
Otherwise, if you want to load the data regardless, you want to do like that :
$orderInDb = $orderClass->loadFullOrder($order->order_id, false, false);
That will deactivate the check of the user.

Please Log in or Create an account to join the conversation.

  • Posts: 10
  • Thank you received: 0
6 months 1 week ago #319829

I get it now, thanks!

Please Log in or Create an account to join the conversation.

Time to create page: 0.066 seconds
Powered by Kunena Forum