Automattic\WooCommerce\StoreApi\Routes\V1
CheckoutOrder::get_request_payment_method
Gets the chosen payment method from the request.
Method of the class: CheckoutOrder{}
No Hooks.
Returns
\WC_Payment_Gateway|null.
Usage
// private - for code of main (parent) class only $result = $this->get_request_payment_method( $request );
- $request(WP_REST_Request) (required)
- Request object.
CheckoutOrder::get_request_payment_method() CheckoutOrder::get request payment method code WC 10.8.1
private function get_request_payment_method( \WP_REST_Request $request ) {
$available_gateways = WC()->payment_gateways->get_available_payment_gateways();
$request_payment_method = wc_clean( wp_unslash( $request['payment_method'] ?? '' ) );
$requires_payment_method = $this->order->needs_payment();
if ( empty( $request_payment_method ) ) {
if ( $requires_payment_method ) {
throw new RouteException(
'woocommerce_rest_checkout_missing_payment_method',
__( 'No payment method provided.', 'woocommerce' ),
400
);
}
return null;
}
if ( ! isset( $available_gateways[ $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.', 'woocommerce' ),
esc_html( $request_payment_method )
),
400
);
}
return $available_gateways[ $request_payment_method ];
}