Automattic\WooCommerce\Gateways\PayPal

Request::get_paypal_order_custom_id │ private │ WC 1.0

Build the custom ID for the PayPal order. The custom ID will be used by the proxy for webhook forwarding, and by later steps to identify the order.

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

Хуков нет.

Возвращает

string.

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

// private - только в коде основоного (родительского) класса
$result = $this->get_paypal_order_custom_id( $order ): string;
$order(WC_Order) (обязательный)
Order object.

Код Request::get_paypal_order_custom_id() WC 11.2.2

private function get_paypal_order_custom_id( WC_Order $order ): string {
	$custom_id = wp_json_encode(
		array(
			'order_id'  => $order->get_id(),
			'order_key' => $order->get_order_key(),
			// Endpoint for the proxy to forward webhooks to.
			'site_url'  => home_url(),
			'site_id'   => class_exists( '\Jetpack_Options' ) ? \Jetpack_Options::get_option( 'id' ) : null,
			'v'         => defined( 'WC_VERSION' ) ? WC_VERSION : WC()->version,
		)
	);

	if ( false === $custom_id ) {
		throw new Exception( 'Failed to encode custom ID.' );
	}

	if ( strlen( $custom_id ) > 255 ) {
		throw new Exception( 'PayPal order custom ID is too long. Max length is 255 chars.' );
	}

	return $custom_id ? $custom_id : '';
}