diff --git a/changelog.txt b/changelog.txt index b34f858335..89b1363294 100644 --- a/changelog.txt +++ b/changelog.txt @@ -32,6 +32,7 @@ * Dev - Move some testing and compiler node dependencies to devDependencies * Dev - Minor CSS change to comply with a SASS rule deprecation * Dev - Update SCSS to replace @import with @use and @forward +* Fix - Handle missing customer when calling payment_methods API = 9.7.1 - 2025-07-28 = * Add - Add state mapping for Lithuania in express checkout diff --git a/includes/class-wc-stripe-customer.php b/includes/class-wc-stripe-customer.php index b6e5a036c3..11c658c437 100644 --- a/includes/class-wc-stripe-customer.php +++ b/includes/class-wc-stripe-customer.php @@ -719,6 +719,15 @@ public function get_payment_methods( $payment_method_type ) { ); if ( ! empty( $response->error ) ) { + if ( + isset( $response->error->code, $response->error->param, $response->error->type ) + && 'customer' === $response->error->param + && 'resource_missing' === $response->error->code + && 'invalid_request_error' === $response->error->type + ) { + // If the customer doesn't exist, cache an empty array as a result. + set_transient( self::PAYMENT_METHODS_TRANSIENT_KEY . $payment_method_type . $this->get_id(), [], DAY_IN_SECONDS ); + } return []; } diff --git a/readme.txt b/readme.txt index 2254373487..a328f57b96 100644 --- a/readme.txt +++ b/readme.txt @@ -141,5 +141,6 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o * Dev - Move some testing and compiler node dependencies to devDependencies * Dev - Minor CSS change to comply with a SASS rule deprecation * Dev - Update SCSS to replace @import with @use and @forward +* Fix - Handle missing customer when calling payment_methods API [See changelog for full details across versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).