Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Update - Removes unnecessary legacy checkout gateway instantiations and UPE disablement code
* Dev - Renames previous Order Helper class methods to use the `_id` suffix
* Dev - Expands the Stripe Order Helper class to handle customer ID, card ID, UPE payment type, and UPE redirect status metas
* Add - Fetch account data before account cache expires

= 10.0.1 - 2025-10-15 =
* Fix - Remove persistent reconnection notices
Expand Down
13 changes: 8 additions & 5 deletions includes/class-wc-stripe-account.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,21 @@ public function __construct( WC_Stripe_Connect $connect, $stripe_api ) {
/**
* Gets and caches the data for the account connected to this site.
*
* @param string|null $mode Optional. The mode to get the account data for. 'live' or 'test'. Default will use the current mode.
* @param string|null $mode Optional. The mode to get the account data for. 'live' or 'test'. Default will use the current mode.
* @param bool $bypass_cache Optional. Whether to bypass the cache and retrieve the account data from Stripe. Default is false.
* @return array Account data or empty if failed to retrieve account data.
*/
public function get_cached_account_data( $mode = null ) {
public function get_cached_account_data( $mode = null, bool $bypass_cache = false ) {
if ( ! $this->connect->is_connected( $mode ) ) {
return [];
}

$account = $this->read_account_from_cache();
if ( ! $bypass_cache ) {
$account = $this->read_account_from_cache();

if ( ! empty( $account ) ) {
return $account;
if ( ! empty( $account ) ) {
return $account;
}
}

return $this->cache_account( $mode );
Expand Down
5 changes: 5 additions & 0 deletions includes/class-wc-stripe-database-cache-prefetch.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class WC_Stripe_Database_Cache_Prefetch {
* @var int[]
*/
protected const PREFETCH_CONFIG = [
WC_Stripe_Account::ACCOUNT_CACHE_KEY => 10,
WC_Stripe_Payment_Method_Configurations::CONFIGURATION_CACHE_KEY => 10,
];

Expand Down Expand Up @@ -194,6 +195,10 @@ protected function prefetch_cache_key( string $key ): ?bool {
$prefetched = null;

switch ( $key ) {
case WC_Stripe_Account::ACCOUNT_CACHE_KEY:
$account_data = WC_Stripe::get_instance()->account->get_cached_account_data( null, true );
$prefetched = ! empty( $account_data );
break;
case WC_Stripe_Payment_Method_Configurations::CONFIGURATION_CACHE_KEY:
if ( WC_Stripe_Payment_Method_Configurations::is_enabled() ) {
WC_Stripe_Payment_Method_Configurations::get_upe_enabled_payment_method_ids( true );
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,6 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
* Update - Removes unnecessary legacy checkout gateway instantiations and UPE disablement code
* Dev - Renames previous Order Helper class methods to use the `_id` suffix
* Dev - Expands the Stripe Order Helper class to handle customer ID, card ID, UPE payment type, and UPE redirect status metas
* Add - Fetch account data before account cache expires

[See changelog for full details across versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).
21 changes: 14 additions & 7 deletions tests/phpunit/WC_Stripe_Database_Cache_Prefetch_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function provide_handle_prefetch_action_test_cases(): array {
return [
'pmc_key_exists_and_should_prefetch' => [ \WC_Stripe_Payment_Method_Configurations::CONFIGURATION_CACHE_KEY, true ],
'invalid_key_should_not_prefetch' => [ 'invalid_test_key', false ],
'account_key_should_prefetch' => [ \WC_Stripe_Account::ACCOUNT_CACHE_KEY, true ],
];
}

Expand Down Expand Up @@ -54,13 +55,19 @@ public function test_handle_prefetch_action( string $key, bool $should_prefetch
*/
public function provide_maybe_queue_prefetch_test_cases(): array {
return [
'invalid_key_should_not_prefetch' => [ 'invalid_test_key', 5, false ],
'pmc_key_expires_in_60_seconds_should_not_prefetch' => [ \WC_Stripe_Payment_Method_Configurations::CONFIGURATION_CACHE_KEY, 60, false ],
'pmc_key_expires_in_5_seconds_should_prefetch' => [ \WC_Stripe_Payment_Method_Configurations::CONFIGURATION_CACHE_KEY, 5, true ],
'pmc_key_expires_in_5_seconds_with_option_set_2s_should_not_prefetch' => [ \WC_Stripe_Payment_Method_Configurations::CONFIGURATION_CACHE_KEY, 5, false, 2 ],
'pmc_key_expires_in_5_seconds_with_option_set_-2s_should_not_prefetch' => [ \WC_Stripe_Payment_Method_Configurations::CONFIGURATION_CACHE_KEY, 5, false, -2 ],
'pmc_key_expires_in_5_seconds_with_option_set_-11s_should_prefetch' => [ \WC_Stripe_Payment_Method_Configurations::CONFIGURATION_CACHE_KEY, 5, true, -11 ],
'pmc_key_expires_in_5_seconds_with_invalid_option_should_prefetch' => [ \WC_Stripe_Payment_Method_Configurations::CONFIGURATION_CACHE_KEY, 5, true, 'invalid' ],
'invalid_key_should_not_prefetch' => [ 'invalid_test_key', 5, false ],
'pmc_key_expires_in_60_seconds_should_not_prefetch' => [ \WC_Stripe_Payment_Method_Configurations::CONFIGURATION_CACHE_KEY, 60, false ],
'pmc_key_expires_in_5_seconds_should_prefetch' => [ \WC_Stripe_Payment_Method_Configurations::CONFIGURATION_CACHE_KEY, 5, true ],
'pmc_key_expires_in_5_seconds_with_option_set_2s_should_not_prefetch' => [ \WC_Stripe_Payment_Method_Configurations::CONFIGURATION_CACHE_KEY, 5, false, 2 ],
'pmc_key_expires_in_5_seconds_with_option_set_-2s_should_not_prefetch' => [ \WC_Stripe_Payment_Method_Configurations::CONFIGURATION_CACHE_KEY, 5, false, -2 ],
'pmc_key_expires_in_5_seconds_with_option_set_-11s_should_prefetch' => [ \WC_Stripe_Payment_Method_Configurations::CONFIGURATION_CACHE_KEY, 5, true, -11 ],
'pmc_key_expires_in_5_seconds_with_invalid_option_should_prefetch' => [ \WC_Stripe_Payment_Method_Configurations::CONFIGURATION_CACHE_KEY, 5, true, 'invalid' ],
'account_key_expires_in_60_seconds_should_not_prefetch' => [ \WC_Stripe_Account::ACCOUNT_CACHE_KEY, 60, false ],
'account_key_expires_in_5_seconds_should_prefetch' => [ \WC_Stripe_Account::ACCOUNT_CACHE_KEY, 5, true ],
'account_key_expires_in_5_seconds_with_option_set_2s_should_not_prefetch' => [ \WC_Stripe_Account::ACCOUNT_CACHE_KEY, 5, false, 2 ],
'account_key_expires_in_5_seconds_with_option_set_-2s_should_not_prefetch' => [ \WC_Stripe_Account::ACCOUNT_CACHE_KEY, 5, false, -2 ],
'account_key_expires_in_5_seconds_with_option_set_-11s_should_prefetch' => [ \WC_Stripe_Account::ACCOUNT_CACHE_KEY, 5, true, -11 ],
'account_key_expires_in_5_seconds_with_invalid_option_should_prefetch' => [ \WC_Stripe_Account::ACCOUNT_CACHE_KEY, 5, true, 'invalid' ],
];
}

Expand Down
Loading