Skip to content

Commit 3f4a907

Browse files
authored
Use existing helper method for payment method detachment checks in token code (#4812)
* Use central method for payment detachment checks in payment tokens code * Changelog * Improve changelog entry
1 parent baef416 commit 3f4a907

File tree

3 files changed

+4
-12
lines changed

3 files changed

+4
-12
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* Fix - Don't allow WP-Cron jobs to detach payment methods on staging sites
1919
* Update - Add minimum transaction amounts for BRL, INR, NZD, THB, CZK, HUF, AED, MYR, PLN, RON
2020
* Dev - Add additional context data to the OAuth connect flow verbose debug logging mode
21+
* Fix - Make token detachment checks use shared logic for detaching payment methods
2122

2223
= 10.1.0 - 2025-11-11 =
2324
* Dev - Remove unused `shouldShowPaymentRequestButton` parameter and calculations from backend

includes/payment-tokens/class-wc-stripe-payment-tokens.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -480,18 +480,8 @@ public function woocommerce_payment_token_deleted( $token_id, $token ) {
480480
return;
481481
}
482482

483-
/**
484-
* 1. Check if it's live mode.
485-
* 2. Check if it's admin.
486-
* 3. Check if it's not production environment.
487-
* When all conditions are met, we don't want to delete the payment method from Stripe.
488-
* This is to avoid detaching the payment method from the live stripe account on non production environments.
489-
*/
490-
if (
491-
WC_Stripe_Mode::is_live() &&
492-
is_admin() &&
493-
'production' !== wp_get_environment_type()
494-
) {
483+
// Check if we should detach the payment method from the customer.
484+
if ( ! WC_Stripe_API::should_detach_payment_method_from_customer() ) {
495485
return;
496486
}
497487

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,6 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
128128
* Fix - Don't allow WP-Cron jobs to detach payment methods on staging sites
129129
* Update - Add minimum transaction amounts for BRL, INR, NZD, THB, CZK, HUF, AED, MYR, PLN, RON
130130
* Dev - Add additional context data to the OAuth connect flow verbose debug logging mode
131+
* Fix - Make token detachment checks use shared logic for detaching payment methods
131132

132133
[See changelog for full details across versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).

0 commit comments

Comments
 (0)