Automattic\WooCommerce\StoreApi\Routes\V1\Agentic

CheckoutSessionsComplete::get_request_payment_method_idprivateWC 1.0

Gets the chosen payment method (gateway) ID for CheckoutTrait.

Method of the class: CheckoutSessionsComplete{}

No Hooks.

Returns

String.

Usage

// private - for code of main (parent) class only
$result = $this->get_request_payment_method_id( $request );
$request(WP_REST_Request) (required)
Request object.

CheckoutSessionsComplete::get_request_payment_method_id() code WC 10.7.0

private function get_request_payment_method_id( \WP_REST_Request $request ) {
	$available_gateways = WC()->payment_gateways()->get_available_payment_gateways();

	if ( empty( $available_gateways ) ) {
		throw new RouteException(
			'woocommerce_checkout_session_no_payment_gateway_available',
			esc_html__( 'No payment gateway available.', 'woocommerce' ),
			400
		);
	}

	// Look for gateway with agentic_commerce capability.
	$gateway = AgenticCheckoutUtils::get_agentic_commerce_gateway( $available_gateways );

	if ( null === $gateway ) {
		throw new RouteException(
			'woocommerce_checkout_session_no_agentic_payment_gateway_available',
			esc_html__( 'No agentic-supported payment gateway available.', 'woocommerce' ),
			400
		);
	}

	return $gateway->id;
}