-
Notifications
You must be signed in to change notification settings - Fork 216
Use existing helper method for payment method detachment checks in token code #4812
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
Use existing helper method for payment method detachment checks in token code #4812
Conversation
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.
Pull Request Overview
This PR refactors the payment token deletion logic to use a centralized helper method (WC_Stripe_API::should_detach_payment_method_from_customer()) instead of duplicated inline checks. This consolidates the logic for determining when payment methods should be detached from Stripe customers during token deletion.
- Replaces inline detachment checks with call to existing helper method
- Updates changelog to document the fix
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| includes/payment-tokens/class-wc-stripe-payment-tokens.php | Replaced inline payment method detachment checks with centralized helper method call |
| changelog.txt | Added changelog entry documenting the refactoring |
| readme.txt | Added changelog entry documenting the refactoring |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Check if we should detach the payment method from the customer. | ||
| if ( ! WC_Stripe_API::should_detach_payment_method_from_customer() ) { |
Copilot
AI
Nov 18, 2025
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.
The helper method should_detach_payment_method_from_customer() includes an additional check for WooCommerce Subscriptions staging mode (is_woocommerce_subscriptions_staging_mode()) that was not present in the original inline logic. This means the behavior will change: payment methods will now also NOT be detached when WooCommerce Subscriptions staging mode is enabled, even if the site is identified as production by wp_get_environment_type(). While this may be intentional for better safety, it represents a behavioral change that should be acknowledged and tested.
| // Check if we should detach the payment method from the customer. | |
| if ( ! WC_Stripe_API::should_detach_payment_method_from_customer() ) { | |
| // Only detach payment methods in production environment. | |
| if ( 'production' !== wp_get_environment_type() ) { |
wjrosa
left a comment
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 fixing those issues! Looks good to me ![]()
Mayisha
left a comment
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.
Looks good to me 👍
Changes proposed in this Pull Request:
While reviewing another change, I noticed that the logic in
WC_Stripe_Payment_Tokens->woocommerce_payment_token_deleted()effectively replicates the logic from the centralWC_Stripe_API::should_detach_payment_method_from_customer()method. Rather than replicating that logic, and having the implementation drift apart, I have updatedWC_Stripe_Payment_Tokens->woocommerce_payment_token_deleted()to call the existing helper method.Testing instructions
I think inspection should be sufficient for this.
Changelog entry
Changelog Entry Comment
Comment
Post merge