-
Notifications
You must be signed in to change notification settings - Fork 2
Fix webhook race condition where paid_out event arrives after failed … #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Fix webhook race condition where paid_out event arrives after failed … #91
Conversation
…event - Fixes issue gocardless#7: gocardless#7 - Handle case where paid_out/confirmed events arrive after order is marked as failed - Transition order status from failed/cancelled to processing before payment_complete() - Add comprehensive logging for debugging race conditions - Include unit tests for all scenarios (failed->paid_out, cancelled->paid_out, normal flow) - Maintain backward compatibility with existing functionality The fix ensures orders are properly marked as completed when GoCardless webhook events arrive out of order due to network delays or retries.
if ( 'failed' === $current_status ) { | ||
wc_gocardless()->log( sprintf( '%s - Order #%s is in failed status, transitioning to processing before payment_complete()', __METHOD__, $order->get_order_number() ) ); | ||
$order->update_status( 'processing', __( 'Payment received after initial failure - updating status', 'woocommerce-gateway-gocardless' ) ); | ||
} elseif ( 'cancelled' === $current_status ) { | ||
wc_gocardless()->log( sprintf( '%s - Order #%s is in cancelled status, transitioning to processing before payment_complete()', __METHOD__, $order->get_order_number() ) ); | ||
$order->update_status( 'processing', __( 'Payment received after cancellation - updating status', 'woocommerce-gateway-gocardless' ) ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iamdharmesh Code here looks fine to me but curious for your thoughts on this, if there's any scenario where we wouldn't want to change a failed or cancelled order to processing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, @sidshas03.
@dkotter I don’t see an issue with changing a failed or cancelled order to processing. However, I’m not sure what we are fixing here. We already have a $order->payment_complete()
call after these changes, so the order status will be updated to processing, and we don’t need to update it explicitly here. Also, updating it to processing directly will skip the $order->payment_complete()
logic due to the internal check, and it will also skip updating the transaction ID in the order.
where a
paid_out
event arrives after afailed
event, causing orders to remain in failed status even though the payment was successful.
@sidshas03 Could you please provide detailed steps to reproduce the issue? I’ve tried running different scenarios here, but I’m not able to reproduce it on trunk
. Any help in reproducing the issue would be greatly appreciated.
Thanks!
Description
This PR fixes the race condition described in issue #7 where a
paid_out
event arrives after afailed
event, causing orders to remain in failed status even though the payment was successful.Problem
failed
event arrives first, it sets the order status tofailed
and removes_gocardless_temporary_activated
paid_out
event callspayment_complete()
but the order is already infailed
stateSolution
failed
orcancelled
status whenpaid_out
/confirmed
events are receivedprocessing
before callingpayment_complete()
Changes
Modified:
includes/class-wc-gocardless-gateway.php
_process_payment_event()
method to handle race conditionsfailed
→paid_out
andcancelled
→paid_out
scenariosAdded:
tests/phpunit/test-webhook-race-condition.php
Testing
Fixes
#7