Skip to content

Commit 2d3ea34

Browse files
committed
Protect against potential for multiple renewal charges on one Order (#4014)
* Update maybe_init_subscriptions() to only run once for each Gateway ID * Add changelog entry
1 parent 5c25402 commit 2d3ea34

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
* Fix - Fix issue where Legacy Checkout settings get overwritten with old value.
4141
* Add - Add WooCommerce Pre-Orders support to Bacs.
4242
* Tweak - Fix background in express checkout settings.
43+
* Fix - Prevent potential duplicate renewal charges by ensuring subscription integration hooks are only attached once per Gateway ID
4344
* Update - Update Amazon Pay icon to use image from WooCommerce Design Library.
4445

4546
= 9.2.0 - 2025-02-13 =

includes/compat/trait-wc-stripe-subscriptions.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ public function maybe_init_subscriptions() {
2929
return;
3030
}
3131

32+
/**
33+
* We need to attach the callbacks below once per Gateway (CC, SEPA, etc.), but only once.
34+
* Therefore, we use a static flag at class level to indicate that they have been attached.
35+
*/
36+
if ( self::$has_attached_integration_hooks ) {
37+
return;
38+
}
39+
3240
$this->supports = array_merge(
3341
$this->supports,
3442
[
@@ -61,16 +69,16 @@ public function maybe_init_subscriptions() {
6169
// Validate the payment method meta data set on a subscription.
6270
add_filter( 'woocommerce_subscription_validate_payment_meta', [ $this, 'validate_subscription_payment_meta' ], 10, 2 );
6371

72+
self::$has_attached_integration_hooks = true;
73+
6474
/**
6575
* The callbacks attached below only need to be attached once. We don't need each gateway instance to have its own callback.
6676
* Therefore we only attach them once on the main `stripe` gateway and store a flag to indicate that they have been attached.
6777
*/
68-
if ( self::$has_attached_integration_hooks || WC_Gateway_Stripe::ID !== $this->id ) {
78+
if ( WC_Gateway_Stripe::ID !== $this->id ) {
6979
return;
7080
}
7181

72-
self::$has_attached_integration_hooks = true;
73-
7482
add_action( 'woocommerce_subscriptions_change_payment_before_submit', [ $this, 'differentiate_change_payment_method_form' ] );
7583
add_action( 'wcs_resubscribe_order_created', [ $this, 'delete_resubscribe_meta' ], 10 );
7684
add_action( 'wcs_renewal_order_created', [ $this, 'delete_renewal_meta' ], 10 );

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
150150
* Fix - Fix issue where Legacy Checkout settings get overwritten with old value.
151151
* Add - Add WooCommerce Pre-Orders support to Bacs.
152152
* Tweak - Fix background in express checkout settings.
153+
* Fix - Prevent potential duplicate renewal charges by ensuring subscription integration hooks are only attached once per Gateway ID
153154
* Update - Update Amazon Pay icon to use image from WooCommerce Design Library.
154155

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

0 commit comments

Comments
 (0)