CheckoutSessionsComplete
extends AbstractCartRoute
in package
Uses
CheckoutTrait
CheckoutSessionsComplete class.
Handles the Agentic Checkout API checkout sessions complete endpoint. This endpoint allows AI agents to complete checkout sessions with payment.
Table of Contents
- IDENTIFIER = 'agentic-checkout-sessions-complete'
- The route identifier.
- SCHEMA_TYPE = AutomatticWooCommerceStoreApiSchemasV1AgenticCheckoutSessionSchema::IDENTIFIER
- The route's schema type.
- SCHEMA_VERSION = 1
- The routes schema version.
- $additional_fields_controller : CheckoutFields
- Additional fields controller class instance.
- $cart_controller : CartController
- Cart controller for managing cart operations.
- $cart_item_schema : CartItemSchema
- Schema class for the cart item.
- $cart_schema : CartSchema
- Schema class for the cart.
- $has_cart_token : bool|null
- True when this route has been requested with a valid cart token.
- $namespace : string
- Route namespace.
- $order : WC_Order|null
- The order object for the current request.
- $order_controller : OrderController
- Order controller for managing orders.
- $schema : AbstractSchema
- Schema class instance.
- $schema_controller : SchemaController
- Schema Controller instance.
- __construct() : mixed
- Constructor.
- get_args() : array<string|int, mixed>
- Get method arguments for this REST route.
- get_collection_params() : array<string|int, mixed>
- Retrieves the query params for the collections.
- get_document_object_from_rest_request() : DocumentObject
- Returns a document object from a REST request.
- get_item_schema() : array<string|int, mixed>
- Get item schema properties.
- get_namespace() : string
- Get the namespace for this route.
- get_path() : string
- Get the path of this REST route.
- get_path_regex() : string
- Get the path regex for this REST route.
- get_response() : WP_REST_Response
- Get the route response based on the type of request.
- is_authorized() : bool|WP_Error
- Check if the request is authorized.
- prepare_item_for_response() : WP_REST_Response
- Prepare a single item for response.
- set_namespace() : mixed
- Set the namespace for this route.
- add_response_headers() : WP_REST_Response
- Add nonce headers to a response object.
- cart_updated() : mixed
- Triggered after an update to cart data. Re-calculates totals and updates draft orders (if they already exist) to keep all data in sync.
- check_nonce() : WP_Error|bool
- For non-GET endpoints, require and validate a nonce to prevent CSRF attacks.
- error_to_response() : WP_REST_Response
- Converts an error to a response object. Based on \WP_REST_Server.
- get_cart_token() : string
- Generates a cart token for the response headers.
- get_complete_params() : array<string|int, mixed>
- Get the parameters for completing a checkout session.
- get_context_param() : array<string|int, mixed>
- Retrieves the context param.
- get_draft_order() : WC_Order|null
- Uses the draft order ID to return an order object, if valid.
- get_draft_order_id() : int
- Gets draft order data from the customer session.
- get_response_by_request_method() : WP_REST_Response
- Get the route response based on the type of request.
- get_route_delete_response() : WP_REST_Response
- Get route response for DELETE requests.
- get_route_error_response() : WP_Error
- Get route response when something went wrong.
- get_route_error_response_from_object() : WP_Error
- Get route response when something went wrong and the supplied error is a WP_Error. This currently only happens when an item in the cart is out of stock, partially out of stock, can only be bought individually, or when the item is not purchasable.
- get_route_post_response() : WP_REST_Response|WP_Error
- Handle the request and return a valid response for this endpoint.
- get_route_response() : WP_REST_Response
- Get route response for GET requests.
- get_route_update_response() : WP_REST_Response
- Get route response for PUT requests.
- has_cart_token() : bool|null
- Use the checkout_session_id as Cart-Token, and set the respective values to HTTP header and request.
- is_update_request() : bool
- Are we updating data or getting data?
- is_valid_draft_order() : bool
- Whether the passed argument is a draft order or an order that is pending/failed and the cart hasn't changed.
- load_cart_session() : mixed
- Load the cart session before handling responses.
- prepare_links() : array<string|int, mixed>
- Prepare links for the request.
- prepare_response_for_collection() : array<string|int, mixed>|mixed
- Prepares a response for insertion into a collection.
- requires_nonce() : bool
- Check if a nonce is required for the route.
- set_draft_order_id() : mixed
- Updates draft order data in the customer session.
- get_request_payment_data() : array<string|int, mixed>
- Gets and formats payment request data for CheckoutTrait.
- get_request_payment_method_id() : string
- Gets the chosen payment method (gateway) ID for CheckoutTrait.
- get_request_payment_method_title() : string
- Gets the chosen payment method title from the request.
- persist_additional_fields_for_order() : mixed
- Persist additional fields for the order after validating them.
- process_payment() : mixed
- Fires an action hook instructing active payment gateways to process the payment for an order and provide a result.
- process_without_payment() : mixed
- For orders which do not require payment, just update status.
- update_order_from_request() : mixed
- Update the current order using the posted values from the request.
Constants
IDENTIFIER
The route identifier.
public
string
IDENTIFIER
= 'agentic-checkout-sessions-complete'
SCHEMA_TYPE
The route's schema type.
public
string
SCHEMA_TYPE
= AutomatticWooCommerceStoreApiSchemasV1AgenticCheckoutSessionSchema::IDENTIFIER
SCHEMA_VERSION
The routes schema version.
public
int
SCHEMA_VERSION
= 1
Properties
$additional_fields_controller
Additional fields controller class instance.
protected
CheckoutFields
$additional_fields_controller
$cart_controller
Cart controller for managing cart operations.
protected
CartController
$cart_controller
$cart_item_schema
Schema class for the cart item.
protected
CartItemSchema
$cart_item_schema
$cart_schema
Schema class for the cart.
protected
CartSchema
$cart_schema
$has_cart_token
True when this route has been requested with a valid cart token.
protected
bool|null
$has_cart_token
= null
$namespace
Route namespace.
protected
string
$namespace
= 'wc/store/v1'
$order
The order object for the current request.
protected
WC_Order|null
$order
$order_controller
Order controller for managing orders.
protected
OrderController
$order_controller
$schema
Schema class instance.
protected
AbstractSchema
$schema
$schema_controller
Schema Controller instance.
protected
SchemaController
$schema_controller
Methods
__construct()
Constructor.
public
__construct(SchemaController $schema_controller, AbstractSchema $schema) : mixed
Parameters
- $schema_controller : SchemaController
-
Schema Controller instance.
- $schema : AbstractSchema
-
Schema class instance.
Return values
mixed —get_args()
Get method arguments for this REST route.
public
get_args() : array<string|int, mixed>
Return values
array<string|int, mixed> — An array of endpoints.get_collection_params()
Retrieves the query params for the collections.
public
get_collection_params() : array<string|int, mixed>
Return values
array<string|int, mixed> — Query parameters for the collection.get_document_object_from_rest_request()
Returns a document object from a REST request.
public
get_document_object_from_rest_request(WP_REST_Request $request) : DocumentObject
Parameters
- $request : WP_REST_Request
-
The REST request.
Return values
DocumentObject — The document object or null if experimental blocks are not enabled.get_item_schema()
Get item schema properties.
public
get_item_schema() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_namespace()
Get the namespace for this route.
public
get_namespace() : string
Return values
string —get_path()
Get the path of this REST route.
public
get_path() : string
Return values
string —get_path_regex()
Get the path regex for this REST route.
public
static get_path_regex() : string
Return values
string —get_response()
Get the route response based on the type of request.
public
get_response(WP_REST_Request $request) : WP_REST_Response
Parameters
- $request : WP_REST_Request
-
Request object.
Return values
WP_REST_Response —is_authorized()
Check if the request is authorized.
public
is_authorized(WP_REST_Request $request) : bool|WP_Error
Checks feature enablement and cart token validity.
Parameters
- $request : WP_REST_Request
-
Request object.
Return values
bool|WP_Error — True if authorized, WP_Error otherwise.prepare_item_for_response()
Prepare a single item for response.
public
prepare_item_for_response(mixed $item, WP_REST_Request $request) : WP_REST_Response
Parameters
- $item : mixed
-
Item to format to schema.
- $request : WP_REST_Request
-
Request object.
Return values
WP_REST_Response — $response Response data.set_namespace()
Set the namespace for this route.
public
set_namespace(string $namespace) : mixed
Parameters
- $namespace : string
-
Given namespace.
Return values
mixed —add_response_headers()
Add nonce headers to a response object.
protected
add_response_headers(WP_REST_Response $response) : WP_REST_Response
Parameters
- $response : WP_REST_Response
-
The response object.
Return values
WP_REST_Response —cart_updated()
Triggered after an update to cart data. Re-calculates totals and updates draft orders (if they already exist) to keep all data in sync.
protected
cart_updated(WP_REST_Request $request) : mixed
Parameters
- $request : WP_REST_Request
-
Request object.
Return values
mixed —check_nonce()
For non-GET endpoints, require and validate a nonce to prevent CSRF attacks.
protected
check_nonce(WP_REST_Request $request) : WP_Error|bool
Nonces will mismatch if the logged in session cookie is different! If using a client to test, set this cookie to match the logged in cookie in your browser.
Parameters
- $request : WP_REST_Request
-
Request object.
Return values
WP_Error|bool —error_to_response()
Converts an error to a response object. Based on \WP_REST_Server.
protected
error_to_response(WP_Error $error) : WP_REST_Response
Parameters
- $error : WP_Error
-
WP_Error instance.
Return values
WP_REST_Response — List of associative arrays with code and message keys.get_cart_token()
Generates a cart token for the response headers.
protected
get_cart_token() : string
Current namespace is used as the token Issuer. *
Return values
string —get_complete_params()
Get the parameters for completing a checkout session.
protected
get_complete_params() : array<string|int, mixed>
Return values
array<string|int, mixed> — Parameters array.get_context_param()
Retrieves the context param.
protected
get_context_param([array<string|int, mixed> $args = array() ]) : array<string|int, mixed>
Ensures consistent descriptions between endpoints, and populates enum from schema.
Parameters
- $args : array<string|int, mixed> = array()
-
Optional. Additional arguments for context parameter. Default empty array.
Return values
array<string|int, mixed> — Context parameter details.get_draft_order()
Uses the draft order ID to return an order object, if valid.
protected
get_draft_order() : WC_Order|null
Return values
WC_Order|null —get_draft_order_id()
Gets draft order data from the customer session.
protected
get_draft_order_id() : int
Return values
int —get_response_by_request_method()
Get the route response based on the type of request.
protected
get_response_by_request_method(WP_REST_Request $request) : WP_REST_Response
Parameters
- $request : WP_REST_Request
-
Request object.
Return values
WP_REST_Response —get_route_delete_response()
Get route response for DELETE requests.
protected
get_route_delete_response(WP_REST_Request $request) : WP_REST_Response
When implemented, should return a \WP_REST_Response.
Parameters
- $request : WP_REST_Request
-
Request object.
Tags
Return values
WP_REST_Response —get_route_error_response()
Get route response when something went wrong.
protected
get_route_error_response(string $error_code, string $error_message[, int $http_status_code = 500 ][, array<string|int, mixed> $additional_data = [] ]) : WP_Error
Parameters
- $error_code : string
-
String based error code.
- $error_message : string
-
User facing error message.
- $http_status_code : int = 500
-
HTTP status. Defaults to 500.
- $additional_data : array<string|int, mixed> = []
-
Extra data (key value pairs) to expose in the error response.
Return values
WP_Error — WP Error object.get_route_error_response_from_object()
Get route response when something went wrong and the supplied error is a WP_Error. This currently only happens when an item in the cart is out of stock, partially out of stock, can only be bought individually, or when the item is not purchasable.
protected
get_route_error_response_from_object(WP_Error $error_object[, int $http_status_code = 500 ][, array<string|int, mixed> $additional_data = [] ]) : WP_Error
Parameters
- $error_object : WP_Error
-
The WP_Error object containing the error.
- $http_status_code : int = 500
-
HTTP status. Defaults to 500.
- $additional_data : array<string|int, mixed> = []
-
Extra data (key value pairs) to expose in the error response.
Return values
WP_Error — WP Error object.get_route_post_response()
Handle the request and return a valid response for this endpoint.
protected
get_route_post_response(WP_REST_Request $request) : WP_REST_Response|WP_Error
Parameters
- $request : WP_REST_Request
-
Request object.
Return values
WP_REST_Response|WP_Error —get_route_response()
Get route response for GET requests.
protected
get_route_response(WP_REST_Request $request) : WP_REST_Response
When implemented, should return a \WP_REST_Response.
Parameters
- $request : WP_REST_Request
-
Request object.
Tags
Return values
WP_REST_Response —get_route_update_response()
Get route response for PUT requests.
protected
get_route_update_response(WP_REST_Request $request) : WP_REST_Response
When implemented, should return a \WP_REST_Response.
Parameters
- $request : WP_REST_Request
-
Request object.
Tags
Return values
WP_REST_Response —has_cart_token()
Use the checkout_session_id as Cart-Token, and set the respective values to HTTP header and request.
protected
has_cart_token(WP_REST_Request $request) : bool|null
Parameters
- $request : WP_REST_Request
-
Request object.
Return values
bool|null —is_update_request()
Are we updating data or getting data?
protected
is_update_request(WP_REST_Request $request) : bool
Parameters
- $request : WP_REST_Request
-
Request object.
Return values
bool —is_valid_draft_order()
Whether the passed argument is a draft order or an order that is pending/failed and the cart hasn't changed.
protected
is_valid_draft_order(WC_Order $order_object) : bool
Parameters
- $order_object : WC_Order
-
Order object to check.
Return values
bool — Whether the order is valid as a draft order.load_cart_session()
Load the cart session before handling responses.
protected
load_cart_session(WP_REST_Request $request) : mixed
Parameters
- $request : WP_REST_Request
-
Request object.
Return values
mixed —prepare_links()
Prepare links for the request.
protected
prepare_links(mixed $item, WP_REST_Request $request) : array<string|int, mixed>
Parameters
- $item : mixed
-
Item to prepare.
- $request : WP_REST_Request
-
Request object.
Return values
array<string|int, mixed> —prepare_response_for_collection()
Prepares a response for insertion into a collection.
protected
prepare_response_for_collection(WP_REST_Response $response) : array<string|int, mixed>|mixed
Parameters
- $response : WP_REST_Response
-
Response object.
Return values
array<string|int, mixed>|mixed — Response data, ready for insertion into collection data.requires_nonce()
Check if a nonce is required for the route.
protected
requires_nonce(WP_REST_Request $request) : bool
Parameters
- $request : WP_REST_Request
-
Request object.
Return values
bool — False, Bearer token auth used instead.set_draft_order_id()
Updates draft order data in the customer session.
protected
set_draft_order_id(int $order_id) : mixed
Parameters
- $order_id : int
-
Draft order ID.
Return values
mixed —get_request_payment_data()
Gets and formats payment request data for CheckoutTrait.
private
get_request_payment_data(WP_REST_Request $request) : array<string|int, mixed>
Transforms agentic payment_data format to Store API format.
Parameters
- $request : WP_REST_Request
-
Request object.
Return values
array<string|int, mixed> —get_request_payment_method_id()
Gets the chosen payment method (gateway) ID for CheckoutTrait.
private
get_request_payment_method_id(WP_REST_Request $request) : string
Parameters
- $request : WP_REST_Request
-
Request object.
Tags
Return values
string —get_request_payment_method_title()
Gets the chosen payment method title from the request.
private
get_request_payment_method_title(WP_REST_Request $request) : string
Parameters
- $request : WP_REST_Request
-
Request object.
Tags
Return values
string —persist_additional_fields_for_order()
Persist additional fields for the order after validating them.
private
persist_additional_fields_for_order(WP_REST_Request $request) : mixed
Parameters
- $request : WP_REST_Request
-
Full details about the request.
Return values
mixed —process_payment()
Fires an action hook instructing active payment gateways to process the payment for an order and provide a result.
private
process_payment(WP_REST_Request $request, PaymentResult $payment_result) : mixed
Parameters
- $request : WP_REST_Request
-
Request object.
- $payment_result : PaymentResult
-
Payment result object.
Tags
Return values
mixed —process_without_payment()
For orders which do not require payment, just update status.
private
process_without_payment(WP_REST_Request $request, PaymentResult $payment_result) : mixed
Parameters
- $request : WP_REST_Request
-
Request object.
- $payment_result : PaymentResult
-
Payment result object.
Return values
mixed —update_order_from_request()
Update the current order using the posted values from the request.
private
update_order_from_request(WP_REST_Request $request) : mixed
Parameters
- $request : WP_REST_Request
-
Full details about the request.
