Closed guzzilar closed 4 years ago
I'll write out some more test cases this evening for those failure, pending, authorized cases.
Not sure if this PR is concerning too many areas. Let me know if it'd be better to split some changes out to another different PR. (i.e. the Webhook's payload format from Object to array)
I think fine to keep as one.
A new approach has been provided at #179
1. Objective
In a race-condition where Omise Webhook is fired at the same time as buyer returns to the Callback URI (
return_uri
). A particular WooCommerce Order object will get updated its status twice which creates a consequence of a confirmation email is being sent to the recipient twice causing a confusion in a business flow that rely on this particular email.This happens because at the moment where Omise Webhook and Callback URI are triggered asynchronously at the same time, they both retrieve WC Order object with the
pending
status and update it toprocessing
usingWC_Order::payment_complete()
, which triggers an email function to be executed twice.This pull request is providing a solution to prevent the async request from creating a race-condition, by integrating with WC_Queue feature to handle those async request by executing it by order.
Related information: Related issue(s): T22125 (internal ticket)
2. Description of change
3. Quality assurance
🔧 Environments:
✏️ Details:
Once everything is in placed and you have set Webhook properly, you may try to place an order again until the Webhook is finally arrived to the store first before the Callback URI being executed.
If you check at the Admin Order Detail page, there will no longer be a double customer note (meaning that the request does not reach to the
WC_Order::payment_complete()
function).4. Impact of the change
There is a limitation of concurrent that
Action Scheduler
library can handle. Please check the following document as reference: https://actionscheduler.org/perfAlso
However, it shall not effect to its capability to handle the queue. Just for some high-volume transaction per minute website, it may take some seconds or minutes until all the queue get executed.
As stated in WP-Cron: https://developer.wordpress.org/plugins/cron/#what-is-wp-cron
5. Priority of change
Immediate.
6. Additional Notes
Just to clarify the relationship between 3 names.
However, there is one point that we should understand of WP-Cron behaviour, to understand how the WC_Queue work. As stated in WP-Cron document: https://developer.wordpress.org/plugins/cron/#what-is-wp-cron
The WP-Cron is only working when "any" of page get loaded. It's not time-based as a typical system scheduler. Meaning that, even though we set some schedule to be executed after "5" mins, but if there is no one open "any" page of the WordPress website, then that schedule won't be triggered.