equest $request ) { static $payment_data = []; if ( ! empty( $payment_data ) ) { return $payment_data; } if ( ! empty( $request['payment_data'] ) ) { foreach ( $request['payment_data'] as $data ) { $payment_data[ sanitize_key( $data['key'] ) ] = wc_clean( $data['value'] ); } } return $payment_data; } /** * Update the current order using the posted values from the request. * * @param \WP_REST_Request $request Full details about the request. */ private function update_order_from_request( \WP_REST_Request $request ) { $this->order->set_customer_note( $request['customer_note'] ?? '' ); $this->order->set_payment_method( $this->get_request_payment_method_id( $request ) ); $this->order->set_payment_method_title( $this->get_request_payment_method_title( $request ) ); $this->persist_additional_fields_for_order( $request ); wc_do_deprecated_action( '__experimental_woocommerce_blocks_checkout_update_order_from_request', array( $this->order, $request, ), '6.3.0', 'woocommerce_store_api_checkout_update_order_from_request', 'This action was deprecated in WooCommerce Blocks version 6.3.0. Please use woocommerce_store_api_checkout_update_order_from_request instead.' ); wc_do_deprecated_action( 'woocommerce_blocks_checkout_update_order_from_request', array( $this->order, $request, ), '7.2.0', 'woocommerce_store_api_checkout_update_order_from_request', 'This action was deprecated in WooCommerce Blocks version 7.2.0. Please use woocommerce_store_api_checkout_update_order_from_request instead.' ); /** * Fires when the Checkout Block/Store API updates an order's from the API request data. * * This hook gives extensions the chance to update orders based on the data in the request. This can be used in * conjunction with the ExtendSchema class to post custom data and then process it. * * @since 7.2.0 * * @param \WC_Order $order Order object. * @param \WP_REST_Request $request Full details about the request. */ do_action( 'woocommerce_store_api_checkout_update_order_from_request', $this->order, $request ); $this->order->save(); } /** * Gets the chosen payment method title from the request. * * @throws RouteException On error. * @param \WP_REST_Request $request Request object. * @return string */ private function get_request_payment_method_title( \WP_REST_Request $request ) { $payment_method = $this->get_request_payment_method( $request ); return is_null( $payment_method ) ? '' : $payment_method->get_title(); } /** * Persist additional fields for the order after validating them. * * @param \WP_REST_Request $request Full details about the request. * * @throws RouteException On error. */ private function persist_additional_fields_for_order( \WP_REST_Request $request ) { $errors = new \WP_Error(); $request_fields = $request['additional_fields'] ?? []; foreach ( $request_fields as $key => $value ) { try { $this->additional_fields_controller->validate_field_for_location( $key, $value, 'additional' ); } catch ( \Exception $e ) { $errors[] = $e->getMessage(); continue; } $this->additional_fields_controller->persist_field_for_order( $key, $value, $this->order, false ); } if ( $errors->has_errors() ) { throw new RouteException( 'woocommerce_rest_checkout_invalid_additional_fields', $errors->get_error_messages(), 400 ); } } }