diff --git a/src/StoreApi/Routes/V1/Checkout.php b/src/StoreApi/Routes/V1/Checkout.php index f7dd60702b4..6251b9c707d 100644 --- a/src/StoreApi/Routes/V1/Checkout.php +++ b/src/StoreApi/Routes/V1/Checkout.php @@ -617,12 +617,14 @@ private function get_request_payment_method( \WP_REST_Request $request ) { } if ( ! isset( $available_gateways[ $request_payment_method ] ) ) { + $all_payment_gateways = WC()->payment_gateways->payment_gateways(); + $gateway_title = isset( $all_payment_gateways[ $request_payment_method ] ) ? $all_payment_gateways[ $request_payment_method ]->get_title() : $request_payment_method; throw new RouteException( 'woocommerce_rest_checkout_payment_method_disabled', sprintf( // Translators: %s Payment method ID. - __( 'The %s payment gateway is not available.', 'woo-gutenberg-products-block' ), - esc_html( $request_payment_method ) + __( '%s is not available for this order—please choose a different payment method', 'woo-gutenberg-products-block' ), + esc_html( $gateway_title ) ), 400 ); diff --git a/src/StoreApi/Schemas/V1/CheckoutSchema.php b/src/StoreApi/Schemas/V1/CheckoutSchema.php index 483d424fa76..61445c896fe 100644 --- a/src/StoreApi/Schemas/V1/CheckoutSchema.php +++ b/src/StoreApi/Schemas/V1/CheckoutSchema.php @@ -119,7 +119,9 @@ public function get_properties() { 'description' => __( 'The ID of the payment method being used to process the payment.', 'woo-gutenberg-products-block' ), 'type' => 'string', 'context' => [ 'view', 'edit' ], - 'enum' => array_values( wp_list_pluck( WC()->payment_gateways->get_available_payment_gateways(), 'id' ) ), + // Validation may be based on cart contents which is not available here; this returns all enabled + // gateways. Further validation occurs during the request. + 'enum' => array_values( WC()->payment_gateways->get_payment_gateway_ids() ), ], 'create_account' => [ 'description' => __( 'Whether to create a new user account as part of order processing.', 'woo-gutenberg-products-block' ),