diff --git a/changelog.txt b/changelog.txt index 9a566e03cd..0a9bc7c026 100644 --- a/changelog.txt +++ b/changelog.txt @@ -13,6 +13,7 @@ * Tweak - Small improvements to e2e tests * Fix - Prevent the PMC migration to run when the plugin is not connected to Stripe * Fix - Fixes a fatal error in the OC inbox note when the new checkout is disabled +* Tweak - Improve how we cache saved payment methods for customers = 9.8.0 - 2025-08-11 = * Add - Adds the current setting value for the Optimized Checkout to the Stripe System Status Report data @@ -46,6 +47,7 @@ * Update - Copy for the Optimized Checkout settings and notices * Update - Removes the ability to change the title for the Optimized Checkout payment element, as it is now set to "Stripe" by default * Fix - Handle missing customer when calling payment_methods API +* Dev - Fix some e2e issues: timing, optional flows, and WooCommerce RC support * Fix - Reduce number of calls to Stripe payment_methods API * Fix - Add `get_icon_url()` to Payment Method base class diff --git a/includes/class-wc-stripe-customer.php b/includes/class-wc-stripe-customer.php index a67b3e3a04..3e52bcdd4d 100644 --- a/includes/class-wc-stripe-customer.php +++ b/includes/class-wc-stripe-customer.php @@ -33,6 +33,11 @@ class WC_Stripe_Customer { */ const PAYMENT_METHODS_TRANSIENT_KEY = 'stripe_payment_methods_'; + /** + * Cache prefix for all saved payment methods per customer. + */ + protected const ALL_PAYMENT_METHODS_CACHE_PREFIX = 'all_payment_methods_'; + /** * Queryable Stripe payment method types. */ @@ -806,8 +811,8 @@ public function get_all_payment_methods( array $payment_method_types = [], int $ return []; } - $cache_key = self::PAYMENT_METHODS_TRANSIENT_KEY . '__all_' . $this->get_id(); - $all_payment_methods = get_transient( $cache_key ); + $cache_key = self::ALL_PAYMENT_METHODS_CACHE_PREFIX . $this->get_id(); + $all_payment_methods = WC_Stripe_Database_Cache::get( $cache_key ); if ( false === $all_payment_methods || ! is_array( $all_payment_methods ) ) { $all_payment_methods = []; @@ -832,7 +837,7 @@ public function get_all_payment_methods( array $payment_method_types = [], int $ && 'resource_missing' === $response->error->code ) { // If the customer doesn't exist, cache an empty array. - set_transient( $cache_key, [], DAY_IN_SECONDS ); + WC_Stripe_Database_Cache::set( $cache_key, [], DAY_IN_SECONDS ); } return []; } @@ -855,7 +860,7 @@ public function get_all_payment_methods( array $payment_method_types = [], int $ } while ( null !== $last_payment_method_id ); // Always cache the result without any filters applied. - set_transient( $cache_key, $all_payment_methods, DAY_IN_SECONDS ); + WC_Stripe_Database_Cache::set( $cache_key, $all_payment_methods, DAY_IN_SECONDS ); } // If there are no payment methods, no need to apply any filters below. @@ -986,7 +991,7 @@ public function clear_cache( $payment_method_id = null ) { foreach ( self::STRIPE_PAYMENT_METHODS as $payment_method_type ) { delete_transient( self::PAYMENT_METHODS_TRANSIENT_KEY . $payment_method_type . $this->get_id() ); } - delete_transient( self::PAYMENT_METHODS_TRANSIENT_KEY . '__all_' . $this->get_id() ); + WC_Stripe_Database_Cache::delete( self::ALL_PAYMENT_METHODS_CACHE_PREFIX . $this->get_id() ); // Clear cache for the specific payment method if provided. if ( $payment_method_id ) { WC_Stripe_Database_Cache::delete( 'payment_method_for_source_' . $payment_method_id ); diff --git a/readme.txt b/readme.txt index aec906c596..6d681cca79 100644 --- a/readme.txt +++ b/readme.txt @@ -123,5 +123,6 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o * Tweak - Small improvements to e2e tests * Fix - Prevent the PMC migration to run when the plugin is not connected to Stripe * Fix - Fixes a fatal error in the OC inbox note when the new checkout is disabled +* Tweak - Improve how we cache saved payment methods for customers [See changelog for full details across versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).