Skip to content

Commit 7953774

Browse files
authored
Add order lock for legacy redirect payments (#3442)
* add order lock during legacy redirect payments * address feedback * unlock before retry * add changelog entry
1 parent 38def86 commit 7953774

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* Fix - Resolved an issue which caused the WeChat Pay payment icon to not be displayed on shortcode checkout pages.
3131
* Fix - Set order payment method title to the customizable title setting rather than the default label.
3232
* Fix - Update Cash App payments to avoid confirming on creation, resolving issues with generic payment failures in live mode.
33+
* Tweak - Add order lock for redirect payments.
3334

3435
= 8.7.0 - 2024-09-16 =
3536
* Add - Introduces a new promotional surface to encourage merchants with the legacy checkout experience and APMs enabled to use the new checkout experience.

includes/class-wc-stripe-order-handler.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ public function process_redirect_payment( $order_id, $retry = true, $previous_er
8282

8383
WC_Stripe_Logger::log( "Info: (Redirect) Begin processing payment for order $order_id for the amount of {$order->get_total()}" );
8484

85+
// Lock the order or return if the order is already locked.
86+
if ( $this->lock_order_payment( $order ) ) {
87+
return;
88+
}
89+
8590
/**
8691
* First check if the source is chargeable at this time. If not,
8792
* webhook will take care of it later.
@@ -142,6 +147,9 @@ public function process_redirect_payment( $order_id, $retry = true, $previous_er
142147

143148
// We want to retry.
144149
if ( $this->is_retryable_error( $response->error ) ) {
150+
// Unlock the order before retrying.
151+
$this->unlock_order_payment( $order );
152+
145153
if ( $retry ) {
146154
// Don't do anymore retries after this.
147155
if ( 5 <= $this->retry_interval ) {
@@ -187,10 +195,16 @@ public function process_redirect_payment( $order_id, $retry = true, $previous_er
187195
/* translators: error message */
188196
$order->update_status( 'failed', sprintf( __( 'Stripe payment failed: %s', 'woocommerce-gateway-stripe' ), $e->getLocalizedMessage() ) );
189197

198+
// Unlock the order.
199+
$this->unlock_order_payment( $order );
200+
190201
wc_add_notice( $e->getLocalizedMessage(), 'error' );
191202
wp_safe_redirect( wc_get_checkout_url() );
192203
exit;
193204
}
205+
206+
// Unlock the order.
207+
$this->unlock_order_payment( $order );
194208
}
195209

196210
/**

includes/class-wc-stripe-webhook-handler.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ public function process_webhook_payment( $notification, $retry = true ) {
220220

221221
$is_pending_receiver = ( 'receiver' === $notification->data->object->flow );
222222

223+
if ( $this->lock_order_payment( $order ) ) {
224+
return;
225+
}
226+
223227
try {
224228
if ( $order->has_status( [ 'processing', 'completed' ] ) ) {
225229
return;
@@ -264,6 +268,9 @@ public function process_webhook_payment( $notification, $retry = true ) {
264268

265269
// We want to retry.
266270
if ( $this->is_retryable_error( $response->error ) ) {
271+
// Unlock the order before retrying.
272+
$this->unlock_order_payment( $order );
273+
267274
if ( $retry ) {
268275
// Don't do anymore retries after this.
269276
if ( 5 <= $this->retry_interval ) {
@@ -315,6 +322,8 @@ public function process_webhook_payment( $notification, $retry = true ) {
315322
$this->send_failed_order_email( $order_id );
316323
}
317324
}
325+
326+
$this->unlock_order_payment( $order );
318327
}
319328

320329
/**

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,5 +158,6 @@ If you get stuck, you can ask for help in the Plugin Forum.
158158
* Fix - Resolved an issue which caused the WeChat Pay payment icon to not be displayed on shortcode checkout pages.
159159
* Fix - Set order payment method title to the customizable title setting rather than the default label.
160160
* Fix - Update Cash App payments to avoid confirming on creation, resolving issues with generic payment failures in live mode.
161+
* Tweak - Add order lock for redirect payments.
161162

162163
[See changelog for all versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).

0 commit comments

Comments
 (0)