Automattic\WooCommerce\StoreApi\Routes\V1
Checkout::get_request_payment_method()
Gets the chosen payment method from the request.
Метод класса: Checkout{}
Хуков нет.
Возвращает
\WC_Payment_Gateway|null
.
Использование
// private - только в коде основоного (родительского) класса $result = $this->get_request_payment_method( $request );
- $request(\WP_REST_Request) (обязательный)
- Request object.
Код Checkout::get_request_payment_method() Checkout::get request payment method WC 7.5.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 ]; }