WC_Gateway_Paypal_Response::get_paypal_order()protectedWC 1.0

Get the order from the PayPal 'Custom' variable.

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

Хуков нет.

Возвращает

true|false|WC_Order. object

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_paypal_order( $raw_custom );
$raw_custom(строка) (обязательный)
JSON Data passed back by PayPal.

Код WC_Gateway_Paypal_Response::get_paypal_order() WC 8.7.0

protected function get_paypal_order( $raw_custom ) {
	// We have the data in the correct format, so get the order.
	$custom = json_decode( $raw_custom );
	if ( $custom && is_object( $custom ) ) {
		$order_id  = $custom->order_id;
		$order_key = $custom->order_key;
	} else {
		// Nothing was found.
		WC_Gateway_Paypal::log( 'Order ID and key were not found in "custom".', 'error' );
		return false;
	}

	$order = wc_get_order( $order_id );

	if ( ! $order ) {
		// We have an invalid $order_id, probably because invoice_prefix has changed.
		$order_id = wc_get_order_id_by_order_key( $order_key );
		$order    = wc_get_order( $order_id );
	}

	if ( ! $order || ! hash_equals( $order->get_order_key(), $order_key ) ) {
		WC_Gateway_Paypal::log( 'Order Keys do not match.', 'error' );
		return false;
	}

	return $order;
}