Skip to content

Commit e2fa33d

Browse files
daledupreezdiegocurbelo
authored andcommitted
Fix handling for "no such customer" response for customer payment_methods query (#4561)
* Return and cache no payment methods when customer doesn't exist * Changelog
1 parent fad8b35 commit e2fa33d

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
* Update - Copy for the Optimized Checkout settings and notices
3333
* Dev - Implements WooCommerce constants for the tax statuses
3434
* Update - Removes the ability to change the title for the Optimized Checkout payment element, as it is now set to "Stripe" by default
35+
* Fix - Handle missing customer when calling payment_methods API
3536

3637
= 9.7.1 - 2025-07-28 =
3738
* Add - Add state mapping for Lithuania in express checkout

includes/class-wc-stripe-customer.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,15 @@ public function get_payment_methods( $payment_method_type ) {
719719
);
720720

721721
if ( ! empty( $response->error ) ) {
722+
if (
723+
isset( $response->error->code, $response->error->param, $response->error->type )
724+
&& 'customer' === $response->error->param
725+
&& 'resource_missing' === $response->error->code
726+
&& 'invalid_request_error' === $response->error->type
727+
) {
728+
// If the customer doesn't exist, cache an empty array as a result.
729+
set_transient( self::PAYMENT_METHODS_TRANSIENT_KEY . $payment_method_type . $this->get_id(), [], DAY_IN_SECONDS );
730+
}
722731
return [];
723732
}
724733

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,6 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
141141
* Update - Copy for the Optimized Checkout settings and notices
142142
* Dev - Implements WooCommerce constants for the tax statuses
143143
* Update - Removes the ability to change the title for the Optimized Checkout payment element, as it is now set to "Stripe" by default
144+
* Fix - Handle missing customer when calling payment_methods API
144145

145146
[See changelog for full details across versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).

0 commit comments

Comments
 (0)