CheckoutOrderSchema
extends CheckoutSchema
in package
CheckoutOrderSchema class.
Table of Contents
- EXTENDING_KEY = 'extensions'
- Extending key that gets added to endpoint.
- IDENTIFIER = 'checkout-order'
- The schema item identifier.
- $additional_fields_controller : CheckoutFields
- Additional fields controller.
- $billing_address_schema : BillingAddressSchema
- Billing address schema instance.
- $controller : SchemaController
- Schema Controller instance.
- $extend : ExtendSchema
- Rest extend instance.
- $image_attachment_schema : ImageAttachmentSchema
- Image Attachment schema instance.
- $shipping_address_schema : ShippingAddressSchema
- Shipping address schema instance.
- $title : string
- The schema item name.
- __construct() : mixed
- Constructor.
- get_endpoint_args_for_item_schema() : array<string|int, mixed>
- Retrieves an array of endpoint arguments from the item schema for the controller.
- get_item_response() : array<string|int, mixed>|stdClass
- Returns the full item response.
- get_item_schema() : array<string|int, mixed>
- Returns the full item schema.
- get_properties() : array<string|int, mixed>
- Checkout schema properties.
- get_public_item_schema() : array<string|int, mixed>
- Returns the public schema.
- sanitize_additional_fields() : array<string|int, mixed>
- Sanitize and format additional fields object.
- validate_additional_fields() : true|WP_Error
- Validate additional fields object.
- force_schema_readonly() : array<string|int, mixed>
- Force all schema properties to be readonly.
- generate_additional_fields_schema() : array<string|int, mixed>
- Generate the schema for additional fields.
- get_additional_fields_response() : array<string|int, mixed>
- Get the additional fields response.
- get_additional_fields_schema() : array<string|int, mixed>
- Get the schema for additional fields.
- get_checkout_response() : array<string|int, mixed>
- Get the checkout response based on the current order and any payments.
- get_extended_data() : object
- Returns extended data for a specific endpoint.
- get_extended_schema() : array<string|int, mixed>
- Returns extended schema for a specific endpoint.
- get_item_responses_from_schema() : array<string|int, mixed>
- Apply a schema get_item_response callback to an array of items and return the result.
- get_recursive_sanitize_callback() : function
- Gets a function that sanitizes recursively.
- get_recursive_schema_property_defaults() : array<string|int, mixed>
- Gets an array of schema defaults recursively.
- get_recursive_validate_callback() : function
- Gets a function that validates recursively.
- get_store_currency_properties() : array<string|int, mixed>
- Returns consistent currency schema used across endpoints for prices.
- prepare_currency_response() : array<string|int, mixed>
- Adds currency data to an array of monetary values.
- prepare_html_response() : string|array<string|int, mixed>
- Prepares HTML based content, such as post titles and content, for the API response.
- prepare_money_response() : string
- Convert monetary values from WooCommerce to string based integers, using the smallest unit of a currency.
- prepare_payment_details_for_response() : array<string|int, mixed>
- This prepares the payment details for the response so it's following the schema where it's an array of objects.
- remove_arg_options() : mixed
- Recursive removal of arg_options.
- schema_has_required_property() : bool
- Check if any additional field is required, so that the parent item is required as well.
Constants
EXTENDING_KEY
Extending key that gets added to endpoint.
public
string
EXTENDING_KEY
= 'extensions'
IDENTIFIER
The schema item identifier.
public
string
IDENTIFIER
= 'checkout-order'
Properties
$additional_fields_controller
Additional fields controller.
protected
CheckoutFields
$additional_fields_controller
$billing_address_schema
Billing address schema instance.
protected
BillingAddressSchema
$billing_address_schema
$controller
Schema Controller instance.
protected
SchemaController
$controller
$extend
Rest extend instance.
protected
ExtendSchema
$extend
$image_attachment_schema
Image Attachment schema instance.
protected
ImageAttachmentSchema
$image_attachment_schema
$shipping_address_schema
Shipping address schema instance.
protected
ShippingAddressSchema
$shipping_address_schema
$title
The schema item name.
protected
string
$title
= 'checkout-order'
Methods
__construct()
Constructor.
public
__construct(ExtendSchema $extend, SchemaController $controller) : mixed
Parameters
- $extend : ExtendSchema
-
Rest Extending instance.
- $controller : SchemaController
-
Schema Controller instance.
Return values
mixed —get_endpoint_args_for_item_schema()
Retrieves an array of endpoint arguments from the item schema for the controller.
public
get_endpoint_args_for_item_schema([string $method = WP_REST_Server::CREATABLE ]) : array<string|int, mixed>
Parameters
- $method : string = WP_REST_Server::CREATABLE
-
Optional. HTTP method of the request.
Tags
Return values
array<string|int, mixed> — Endpoint arguments.get_item_response()
Returns the full item response.
public
get_item_response(mixed $item) : array<string|int, mixed>|stdClass
Parameters
- $item : mixed
-
Item to get response for.
Return values
array<string|int, mixed>|stdClass —get_item_schema()
Returns the full item schema.
public
get_item_schema() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_properties()
Checkout schema properties.
public
get_properties() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_public_item_schema()
Returns the public schema.
public
get_public_item_schema() : array<string|int, mixed>
Return values
array<string|int, mixed> —sanitize_additional_fields()
Sanitize and format additional fields object.
public
sanitize_additional_fields(array<string|int, mixed> $fields) : array<string|int, mixed>
Parameters
- $fields : array<string|int, mixed>
-
Values being sanitized.
Return values
array<string|int, mixed> —validate_additional_fields()
Validate additional fields object.
public
validate_additional_fields(array<string|int, mixed> $fields, WP_REST_Request $request) : true|WP_Error
Parameters
- $fields : array<string|int, mixed>
-
Value being sanitized.
- $request : WP_REST_Request
-
The Request.
Tags
Return values
true|WP_Error —force_schema_readonly()
Force all schema properties to be readonly.
protected
force_schema_readonly(array<string|int, mixed> $properties) : array<string|int, mixed>
Parameters
- $properties : array<string|int, mixed>
-
Schema.
Return values
array<string|int, mixed> — Updated schema.generate_additional_fields_schema()
Generate the schema for additional fields.
protected
generate_additional_fields_schema(array<string|int, array<string|int, mixed>> ...$args) : array<string|int, mixed>
Parameters
- $args : array<string|int, array<string|int, mixed>>
-
One or more arrays of additional fields.
Return values
array<string|int, mixed> —get_additional_fields_response()
Get the additional fields response.
protected
get_additional_fields_response(WC_Order $order) : array<string|int, mixed>
Parameters
- $order : WC_Order
-
Order object.
Return values
array<string|int, mixed> —get_additional_fields_schema()
Get the schema for additional fields.
protected
get_additional_fields_schema() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_checkout_response()
Get the checkout response based on the current order and any payments.
protected
get_checkout_response(WC_Order $order[, PaymentResult $payment_result = null ]) : array<string|int, mixed>
Parameters
- $order : WC_Order
-
Order object.
- $payment_result : PaymentResult = null
-
Payment result object.
Return values
array<string|int, mixed> —get_extended_data()
Returns extended data for a specific endpoint.
protected
get_extended_data(string $endpoint, array<string|int, mixed> ...$passed_args) : object
Parameters
- $endpoint : string
-
The endpoint identifier.
- $passed_args : array<string|int, mixed>
-
An array of arguments to be passed to callbacks.
Return values
object — the data that will get added.get_extended_schema()
Returns extended schema for a specific endpoint.
protected
get_extended_schema(string $endpoint, array<string|int, mixed> ...$passed_args) : array<string|int, mixed>
Parameters
- $endpoint : string
-
The endpoint identifer.
- $passed_args : array<string|int, mixed>
-
An array of arguments to be passed to callbacks.
Return values
array<string|int, mixed> — the data that will get added.get_item_responses_from_schema()
Apply a schema get_item_response callback to an array of items and return the result.
protected
get_item_responses_from_schema(AbstractSchema $schema, array<string|int, mixed> $items) : array<string|int, mixed>
Parameters
- $schema : AbstractSchema
-
Schema class instance.
- $items : array<string|int, mixed>
-
Array of items.
Return values
array<string|int, mixed> — Array of values from the callback function.get_recursive_sanitize_callback()
Gets a function that sanitizes recursively.
protected
get_recursive_sanitize_callback(array<string|int, mixed> $properties) : function
Parameters
- $properties : array<string|int, mixed>
-
Schema property data.
Return values
function — Anonymous validation callback.get_recursive_schema_property_defaults()
Gets an array of schema defaults recursively.
protected
get_recursive_schema_property_defaults(array<string|int, mixed> $properties) : array<string|int, mixed>
Parameters
- $properties : array<string|int, mixed>
-
Schema property data.
Return values
array<string|int, mixed> — Array of defaults, pulled from arg_optionsget_recursive_validate_callback()
Gets a function that validates recursively.
protected
get_recursive_validate_callback(array<string|int, mixed> $properties) : function
Parameters
- $properties : array<string|int, mixed>
-
Schema property data.
Return values
function — Anonymous validation callback.get_store_currency_properties()
Returns consistent currency schema used across endpoints for prices.
protected
get_store_currency_properties() : array<string|int, mixed>
Return values
array<string|int, mixed> —prepare_currency_response()
Adds currency data to an array of monetary values.
protected
prepare_currency_response(array<string|int, mixed> $values) : array<string|int, mixed>
Parameters
- $values : array<string|int, mixed>
-
Monetary amounts.
Return values
array<string|int, mixed> — Monetary amounts with currency data appended.prepare_html_response()
Prepares HTML based content, such as post titles and content, for the API response.
protected
prepare_html_response(string|array<string|int, mixed> $response) : string|array<string|int, mixed>
Parameters
- $response : string|array<string|int, mixed>
-
Data to format.
Return values
string|array<string|int, mixed> — Formatted data.prepare_money_response()
Convert monetary values from WooCommerce to string based integers, using the smallest unit of a currency.
protected
prepare_money_response(string|float $amount[, int $decimals = 2 ][, int $rounding_mode = PHP_ROUND_HALF_UP ]) : string
Parameters
- $amount : string|float
-
Monetary amount with decimals.
- $decimals : int = 2
-
Number of decimals the amount is formatted with.
- $rounding_mode : int = PHP_ROUND_HALF_UP
-
Defaults to the PHP_ROUND_HALF_UP constant.
Return values
string — The new amount.prepare_payment_details_for_response()
This prepares the payment details for the response so it's following the schema where it's an array of objects.
protected
prepare_payment_details_for_response(array<string|int, mixed> $payment_details) : array<string|int, mixed>
Parameters
- $payment_details : array<string|int, mixed>
-
An array of payment details from the processed payment.
Return values
array<string|int, mixed> — An array of objects where each object has the key and value as distinct properties.remove_arg_options()
Recursive removal of arg_options.
protected
remove_arg_options(array<string|int, mixed> $properties) : mixed
Parameters
- $properties : array<string|int, mixed>
-
Schema properties.
Return values
mixed —schema_has_required_property()
Check if any additional field is required, so that the parent item is required as well.
protected
schema_has_required_property(array<string|int, mixed> $additional_fields_schema) : bool
Parameters
- $additional_fields_schema : array<string|int, mixed>
-
Additional fields schema.