Automattic\WooCommerce\StoreApi\Routes\V1

CheckoutOrder::get_route_post_response │ protected │ WC 1.0

Process an order.

  1. Process Request
  2. Process Customer
  3. Validate Order
  4. Process Payment

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

Возвращает

\WP_REST_Response.

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

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

Код CheckoutOrder::get_route_post_response() WC 11.2.2

protected function get_route_post_response( \WP_REST_Request $request ) {
	$order_id = absint( $request['id'] );
	$order    = wc_get_order( $order_id );

	if ( ! $order instanceof \WC_Order || ! $order->needs_payment() ) {
		return new \WP_Error(
			'invalid_order_update_status',
			__( 'This order cannot be paid for.', 'woocommerce' )
		);
	}
	$this->order = $order;

	/**
	 * Process request data.
	 *
	 * The order address is validated before anything is persisted, so a rejected request
	 * cannot mutate the existing order or the customer record.
	 */
	$this->update_billing_address( $request );
	$this->update_order_from_request( $request );

	/**
	 * Process customer data.
	 *
	 * Update order with customer details, and sign up a user account as necessary.
	 */
	$this->process_customer( $request );

	/**
	 * Validate order.
	 *
	 * This logic ensures the order is valid before payment is attempted.
	 */
	$this->order_controller->validate_existing_order_before_payment( $this->order );

	/**
	 * Fires after the Checkout Block/Store API request has populated and validated the order.
	 *
	 * The action runs before payment is processed, so callbacks can still act on the order
	 * on its way to the gateway.
	 *
	 * This is similar to existing core hook woocommerce_checkout_order_processed. We're using a new action:
	 * - To keep the interface focused (only pass $order, not passing request data).
	 * - This also explicitly indicates these orders are from checkout block/StoreAPI.
	 *
	 * @since 7.2.0
	 *
	 * @see https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/3238
	 * @example docs/examples/checkout-order-processed.md
	 *
	 * @param \WC_Order $order Order object.
	 */
	do_action( 'woocommerce_store_api_checkout_order_processed', $this->order );

	/**
	 * Process the payment and return the results.
	 */
	$payment_result = new PaymentResult();
	$needs_payment  = $this->order->needs_payment();

	// Callbacks on the action above, or on the needs_payment() filters, may have saved the order.
	$this->validate_order_was_saved();

	if ( $needs_payment ) {
		$this->process_payment( $request, $payment_result );
	} else {
		$this->process_without_payment( $request, $payment_result );
	}

	return $this->prepare_item_for_response(
		(object) [
			'order'          => wc_get_order( $this->order ),
			'payment_result' => $payment_result,
		],
		$request
	);
}