Automattic\WooCommerce\Internal\RestApi\Routes\V4\Refunds\Schema

RefundSchema::prepare_line_itemprotectedWC 1.0

Standardize the line item response.

Method of the class: RefundSchema{}

No Hooks.

Returns

Array.

Usage

// protected - for code of main (parent) or child class
$result = $this->prepare_line_item( $line_item, $request );
$line_item(WC_Order_Item) (required)
Line item instance.
$request(WP_REST_Request) (required)
Request object.

RefundSchema::prepare_line_item() code WC 10.4.3

protected function prepare_line_item( $line_item, WP_REST_Request $request ) {
	$dp           = is_null( $request['num_decimals'] ) ? wc_get_price_decimals() : absint( $request['num_decimals'] );
	$tax_response = array();
	$taxes        = $line_item->get_taxes();
	foreach ( $taxes['total'] ?? array() as $tax_rate_id => $tax ) {
		$tax_response[] = array(
			'id'           => absint( $tax_rate_id ),
			'refund_total' => wc_format_decimal( abs( (float) $tax ), $dp ),
		);
	}
	return array(
		'id'           => absint( $line_item->get_id() ),
		'line_item_id' => absint( $line_item->get_meta( '_refunded_item_id' ) ),
		'quantity'     => wc_stock_amount( abs( (float) $line_item->get_quantity() ) ),
		'refund_total' => wc_format_decimal( abs( (float) $line_item->get_total() ), $dp ),
		'refund_tax'   => $tax_response,
	);
}