Skip to content

Fix handling for "no such customer" response for customer payment_methods query #4561

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

Conversation

daledupreez
Copy link
Contributor

Related to #4560

Changes proposed in this Pull Request:

This PR ensures that when we receive an HTTP error from the Stripe payment_methods API, we now check if the customer doesn't exist based on the error.type, error.param, and error.code fields in the response from Stripe. If the customer doesn't exist, we now populate the cached data with an empty array to prevent unnecessary repeat calls to Stripe.

Testing instructions

  • Set up a test site that uses a test connection to Stripe using the code from trunk
    • To really see the problem, you can also enable Optimized Checkout and ensure you're using block checkout
  • While logged in as a user, make a purchase (or perform another action) to get a Stripe customer ID assigned to your user
  • Install a plugin like Debug Bar so you can see what HTTP requests are being made from PHP during page loads
  • Add another product to your cart, and navigate to checkout -- keep this tab open
  • Use Debug Bar to inspect the outbound HTTP requests for the site -- you may or may not see a number of HTTP requests to the Stripe payment_methods API
  • Now reconnect Stripe and use a different test Stripe account
  • Reload your checkout tab
  • Inspect the outbound HTTP requests -- you should see a number of calls to the Stripe payment_methods API that all return 400 statuses
  • Reload your checkout tab again, and verify that all the payment_methods API calls are repeated
  • Now load the code from this branch
  • Reload your checkout tab, and verify that all the payment_methods API calls are repeated
  • Now load the checkout tab again, and verify that no payment_methods API calls are made, as we now have the data cached

  • 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 requested review from a team and Copilot August 6, 2025 14:02
@daledupreez daledupreez self-assigned this Aug 6, 2025
@daledupreez daledupreez requested review from malithsen and wjrosa and removed request for a team August 6, 2025 14:02
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 fixes an issue where the Stripe payment methods API repeatedly fails when a customer doesn't exist in Stripe, by properly caching empty results to prevent unnecessary repeat API calls.

  • Adds error handling to detect when a Stripe customer doesn't exist based on specific error response fields
  • Caches an empty array result when a customer is missing to prevent redundant API calls
  • Updates changelog and readme to document the fix

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
includes/class-wc-stripe-customer.php Adds error detection logic and caching for missing customers in payment methods API
readme.txt Documents the fix in the readme changelog
changelog.txt Records the fix in the main changelog

Copy link
Contributor

@malithsen malithsen left a comment

Choose a reason for hiding this comment

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

Nice find. I've replicated the issue and can confirm it's fixed on this branch.

Copy link
Contributor

@wjrosa wjrosa left a comment

Choose a reason for hiding this comment

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

Nice fix, Dale! Looks good to me ✅

@daledupreez daledupreez merged commit 678c3ad into develop Aug 6, 2025
45 checks passed
@daledupreez daledupreez deleted the add/check-for-missing-customer-response-in-payment-methods-fetch branch August 6, 2025 20:38
diegocurbelo pushed a commit that referenced this pull request Aug 11, 2025
…hods query (#4561)

* Return and cache no payment methods when customer doesn't exist
* Changelog
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.

3 participants