Automattic\WooCommerce\Gateways\PayPal

Request::get_paypal_order_custom_idprivateWC 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.

Method of the class: Request{}

No Hooks.

Returns

String.

Usage

// private - for code of main (parent) class only
$result = $this->get_paypal_order_custom_id( $order ): string;
$order(WC_Order) (required)
Order object.

Request::get_paypal_order_custom_id() code WC 10.8.1

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 : '';
}