Skip to content

Commit a3abb57

Browse files
lipematdiegocurbeloCopilot
authored
Only clear customer cache when an action has been performed (#4542)
* Only clear customer cache when an action has been performed * Prevents endless loops of clearing the cache and then reloading the customer data. --------- Co-authored-by: Diego Curbelo <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent a0b8670 commit a3abb57

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* Fix - Free trial subscription orders with payment methods that require redirection (eg: iDeal, Bancontact)
2222
* Tweak - Update checkout error message for invalid API key to be more generic and user-friendly
2323
* Tweak - Disable Amazon Pay in the merchant's Payment Method Configuration object if it is still behind a feature flag
24+
* Fix - Only clear customer cache when an action has been performed
2425

2526
= 9.7.1 - 2025-07-28 =
2627
* Add - Add state mapping for Lithuania in express checkout

includes/class-wc-stripe-customer.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -744,9 +744,8 @@ public function delete_source( $source_id ) {
744744

745745
$response = WC_Stripe_API::detach_payment_method_from_customer( $this->get_id(), $source_id );
746746

747-
$this->clear_cache( $source_id );
748-
749747
if ( empty( $response->error ) ) {
748+
$this->clear_cache( $source_id );
750749
do_action( 'wc_stripe_delete_source', $this->get_id(), $response );
751750

752751
return true;
@@ -767,9 +766,8 @@ public function detach_payment_method( $payment_method_id ) {
767766

768767
$response = WC_Stripe_API::detach_payment_method_from_customer( $this->get_id(), $payment_method_id );
769768

770-
$this->clear_cache( $payment_method_id );
771-
772769
if ( empty( $response->error ) ) {
770+
$this->clear_cache( $payment_method_id );
773771
do_action( 'wc_stripe_detach_payment_method', $this->get_id(), $response );
774772

775773
return true;
@@ -792,9 +790,8 @@ public function set_default_source( $source_id ) {
792790
'POST'
793791
);
794792

795-
$this->clear_cache();
796-
797793
if ( empty( $response->error ) ) {
794+
$this->clear_cache();
798795
do_action( 'wc_stripe_set_default_source', $this->get_id(), $response );
799796

800797
return true;
@@ -819,9 +816,8 @@ public function set_default_payment_method( $payment_method_id ) {
819816
'POST'
820817
);
821818

822-
$this->clear_cache();
823-
824819
if ( empty( $response->error ) ) {
820+
$this->clear_cache();
825821
do_action( 'wc_stripe_set_default_payment_method', $this->get_id(), $response );
826822

827823
return true;

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,22 +560,24 @@ private function is_valid_payment_method_type_for_gateway( $payment_method_type,
560560
* @return WC_Payment_Token The WC object for the payment token.
561561
*/
562562
private function add_token_to_user( $payment_method, WC_Stripe_Customer $customer, $payment_method_ids = [] ) {
563-
// Clear cached payment methods.
564-
$customer->clear_cache();
565-
566563
$payment_method_type = $this->get_original_payment_method_type( $payment_method );
567564
$gateway_id = self::UPE_REUSABLE_GATEWAYS_BY_PAYMENT_METHOD[ $payment_method_type ];
568565

569566
$found_token = $this->get_duplicate_token( $payment_method, $customer->get_user_id(), $gateway_id );
570567
if ( $found_token ) {
571568
// Update the token with the new payment method ID if the current payment method ID is not in the list of payment method IDs retrieved from Stripe.
572569
if ( ! in_array( $found_token->get_token(), $payment_method_ids, true ) ) {
570+
// Clear cached payment methods.
571+
$customer->clear_cache();
573572
$found_token->set_token( $payment_method->id );
574573
$found_token->save();
575574
}
576575
return $found_token;
577576
}
578577

578+
// Clear cached payment methods.
579+
$customer->clear_cache();
580+
579581
switch ( $payment_method_type ) {
580582
case WC_Stripe_UPE_Payment_Method_CC::STRIPE_ID:
581583
$token = new WC_Stripe_Payment_Token_CC();

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,6 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
130130
* Fix - Free trial subscription orders with payment methods that require redirection (eg: iDeal, Bancontact)
131131
* Tweak - Update checkout error message for invalid API key to be more generic and user-friendly
132132
* Tweak - Disable Amazon Pay in the merchant's Payment Method Configuration object if it is still behind a feature flag
133+
* Fix - Only clear customer cache when an action has been performed
133134

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

0 commit comments

Comments
 (0)