Automattic\WooCommerce\Internal\RestApi\Routes\V4\Refunds
DataUtils::get_preview_line_items_arg_schema
Get the REST argument schema for a preview request's line_items parameter.
Shared by the wc/v3 and wc/v4 preview endpoints so the accepted payload cannot drift between versions.
Method of the class: DataUtils{}
No Hooks.
Returns
array.
Usage
$DataUtils = new DataUtils(); $DataUtils->get_preview_line_items_arg_schema(): array;
Changelog
| Since 11.1.0 | Introduced. |
DataUtils::get_preview_line_items_arg_schema() DataUtils::get preview line items arg schema code WC 11.1.2
public function get_preview_line_items_arg_schema(): array {
return array(
'description' => __( 'Line items to include in the refund preview.', 'woocommerce' ),
'type' => 'array',
'required' => true,
'minItems' => 1,
'validate_callback' => 'rest_validate_request_arg',
// Hand-registered args get no default sanitizer; this coerces validated
// values to their schema types (numeric strings become numbers) like the
// args generated from an item schema.
'sanitize_callback' => 'rest_sanitize_request_arg',
'items' => array(
'type' => 'object',
'required' => array( 'line_item_id' ),
'additionalProperties' => false,
'properties' => array(
'line_item_id' => array(
'description' => __( 'ID of the original order line item.', 'woocommerce' ),
'type' => 'integer',
'minimum' => 1,
),
'quantity' => array(
'description' => __( 'Quantity to refund. Required when refund_total is omitted.', 'woocommerce' ),
'type' => 'integer',
'minimum' => 1,
),
'refund_total' => array(
// No `minimum` here on purpose: validate_preview_line_items() owns
// the sign rule and returns the actionable `invalid_refund_total`
// code. A refund_total must be non-zero and match the line's sign —
// negative is valid for a discount/credit line, positive for a normal
// line; zero and wrong-sign values are rejected. A schema `minimum`
// would wrongly forbid the negative form, and a generic
// `rest_invalid_param` is less useful to clients.
'description' => __( 'Tax-inclusive amount to refund for this line item. Must be non-zero and match the line\'s sign (negative for discount or credit lines, positive otherwise). Required when quantity is omitted.', 'woocommerce' ),
'type' => array( 'number', 'null' ),
),
),
),
);
}