Store API: Fix payment method validation (fixes COD) (https://github.com/woocommerce/woocommerce-blocks/pull/9375)
* Widen enum for validation before cart is loaded * Improve error message on checkout
This commit is contained in:
parent
1b71b06b33
commit
bb1f578002
|
@ -617,12 +617,14 @@ class Checkout extends AbstractCartRoute {
|
|||
}
|
||||
|
||||
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
|
||||
);
|
||||
|
|
|
@ -119,7 +119,9 @@ class CheckoutSchema extends AbstractSchema {
|
|||
'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' ),
|
||||
|
|
Loading…
Reference in New Issue