Skip to content

Conversation

daledupreez
Copy link
Contributor

@daledupreez daledupreez commented Aug 11, 2025

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 initially kept this work separate as we didn't have a mechanism to clean up stale entries in the database cache, but we addressed that shortcoming in #4609, which was merged earlier this week.

At an implementation level, this PR does the following:

  • Change the all payment methods cache to use the database cache instead of a transient
  • Implement a new, static WC_Stripe_Customer::clear_customer_cache() method, which clears the transients and the all-payments database cache
  • Refactor the WC_Stripe_Customer->clear_cache() method to call the new static function
  • Update WC_Stripe_API::attach_payment_method_to_customer() and WC_Stripe_API::detach_payment_method_from_customer() to call the new static cache clear function when the APIs don't return an error
  • Update the attach_source(), delete_source(), and detach_payment_method() methods in WC_Stripe_Customer to clear their local customer data instead of clearing their full cache
    • It's worth noting that the logic in attach_source() was not there before

Concerns

Given that this cache is going to be more durable, I am not 100% sure that we have all the use cases covered for saving a new payment method, especially because the POST /v1/payment_methods API call is made directly from the front-end, and we only get the payment method ID and make a decision about saving the payment method in Woo later.

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 ☝️)
  • [N/A] 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
Copilot

This comment was marked as outdated.

Base automatically changed from refactor/fetching-all-customer-payment-methods to develop August 11, 2025 14:52
@daledupreez daledupreez requested a review from Copilot August 29, 2025 09:50
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 improves payment method caching by replacing WordPress transients with the WC_Stripe_Database_Cache for storing all customer payment methods, while maintaining backward compatibility for individual payment method type caches.

  • Migrates the get_all_payment_methods() caching from WordPress transients to WC_Stripe_Database_Cache
  • Refactors cache clearing logic to use a static method that can be called from API operations
  • Adds automatic cache invalidation when payment methods are attached or detached from customers

Reviewed Changes

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

File Description
includes/class-wc-stripe-customer.php Updates caching mechanism and adds static cache clearing method
includes/class-wc-stripe-api.php Adds cache invalidation calls after successful payment method operations
readme.txt Documents the caching improvements in changelog
changelog.txt Documents the caching improvements in changelog

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

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