Automattic\WooCommerce\Internal\Admin\Settings

PaymentsRestController::get_providers()protectedWC 1.0

Get the payment providers for the given location.

Метод класса: PaymentsRestController{}

Хуков нет.

Возвращает

WP_Error|WP_REST_Response.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_providers( $request );
$request(WP_REST_Request) (обязательный)
The request object.

Код PaymentsRestController::get_providers() WC 9.6.1

protected function get_providers( WP_REST_Request $request ) {
	$location = $request->get_param( 'location' );
	if ( empty( $location ) ) {
		// Fall back to the providers country if no location is provided.
		$location = $this->payments->get_country();
	}

	try {
		$providers = $this->payments->get_payment_providers( $location );
	} catch ( Exception $e ) {
		return new WP_Error( 'woocommerce_rest_payment_providers_error', $e->getMessage(), array( 'status' => 500 ) );
	}

	try {
		$suggestions = $this->get_extension_suggestions( $location );
	} catch ( Exception $e ) {
		return new WP_Error( 'woocommerce_rest_payment_providers_error', $e->getMessage(), array( 'status' => 500 ) );
	}

	// Separate the offline PMs from the main providers list.
	$offline_payment_providers = array_values(
		array_filter(
			$providers,
			fn( $provider ) => PaymentProviders::TYPE_OFFLINE_PM === $provider['_type']
		)
	);
	$providers                 = array_values(
		array_filter(
			$providers,
			fn( $provider ) => PaymentProviders::TYPE_OFFLINE_PM !== $provider['_type']
		)
	);

	$response = array(
		'providers'               => $providers,
		'offline_payment_methods' => $offline_payment_providers,
		'suggestions'             => $suggestions,
		'suggestion_categories'   => $this->payments->get_payment_extension_suggestion_categories(),
	);

	return rest_ensure_response( $this->prepare_payment_providers_response( $response ) );
}