Automattic\WooCommerce\StoreApi\Routes\V1

Checkout::get_request_payment_method()privateWC 1.0

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() WC 6.7.0

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 ];
}