Skip to content

Use database cache for all customer payment methods #4570

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

Draft
wants to merge 19 commits into
base: develop
Choose a base branch
from

Conversation

daledupreez
Copy link
Contributor

Related to #4567

Changes proposed in this Pull Request:

As per the discussion in #4567, this PR builds on the code from that PR to use WC_Stripe_Database_Cache instead of built-in WordPress transients.

I've put this PR together so we can quickly absorb these changes into the main PR if needed.

Testing instructions

The best approach will be to follow the testing instructions from #4567.


  • Covered with tests (or have a good reason not to test in description ☝️)
  • Tested on mobile (or does not apply)

Changelog entry

  • This Pull Request does not require a changelog entry. (Comment required below)
Changelog Entry Comment

Comment

Post merge

@daledupreez daledupreez self-assigned this Aug 11, 2025
@daledupreez daledupreez requested a review from Copilot August 11, 2025 10:34
Copy link
Contributor

@Copilot Copilot AI left a 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 transitions the customer payment methods caching system from WordPress transients to a custom database cache implementation. It specifically updates the caching mechanism for "all payment methods" functionality to use WC_Stripe_Database_Cache instead of built-in WordPress transients, building on changes from a related PR.

Key changes:

  • Replaces WordPress transient functions with WC_Stripe_Database_Cache methods for all payment methods caching
  • Introduces a new cache prefix constant for consistency
  • Updates documentation to reflect the caching improvements

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
includes/class-wc-stripe-customer.php Implements database cache for all payment methods instead of transients
readme.txt Adds changelog entry for caching improvements
changelog.txt Documents the caching enhancement as a tweak

@@ -15,6 +15,11 @@ class WC_Stripe_Customer {
*/
const PAYMENT_METHODS_TRANSIENT_KEY = 'stripe_payment_methods_';

/**
* Cache prefix for all saved payment methods per customer..
Copy link
Preview

Copilot AI Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the extra period at the end of the comment. It should be 'per customer.'

Suggested change
* Cache prefix for all saved payment methods per customer..
* Cache prefix for all saved payment methods per customer.

Copilot uses AI. Check for mistakes.

@@ -940,7 +945,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() );
Copy link
Preview

Copilot AI Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clear_cache method has inconsistent caching mechanisms - it still uses delete_transient for individual payment method types but WC_Stripe_Database_Cache::delete for all payment methods. Consider updating all cache clearing to use the same mechanism for consistency.

Suggested change
delete_transient( self::PAYMENT_METHODS_TRANSIENT_KEY . $payment_method_type . $this->get_id() );
WC_Stripe_Database_Cache::delete( self::PAYMENT_METHODS_TRANSIENT_KEY . $payment_method_type . $this->get_id() );

Copilot uses AI. Check for mistakes.

Base automatically changed from refactor/fetching-all-customer-payment-methods to develop August 11, 2025 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant