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

DataUtils::normalize_refund_totalspublicWC 10.9.0

Round every caller-supplied refund_total to currency precision.

Applied at the entry of both the preview and create flows so a value the client sends is validated, summed, split, and stored at the same precision. A previewed amount therefore always matches the created refund to the cent. A missing or null refund_total (the auto-compute form) is left untouched — those are computed later and already rounded by {@see compute_line_item_refund_total()}.

Method of the class: DataUtils{}

No Hooks.

Returns

Array. Line items with numeric refund_total values rounded to wc_get_price_decimals().

Usage

$DataUtils = new DataUtils();
$DataUtils->normalize_refund_totals( $line_items ): array;
$line_items(array) (required)
Line items in schema format.

Changelog

Since 10.9.0 Introduced.

DataUtils::normalize_refund_totals() code WC 11.0.1

public function normalize_refund_totals( array $line_items ): array {
	$price_decimals = wc_get_price_decimals();
	foreach ( $line_items as $key => $line_item ) {
		if ( isset( $line_item['refund_total'] ) && is_numeric( $line_item['refund_total'] ) ) {
			$line_items[ $key ]['refund_total'] = NumberUtil::round( (float) $line_item['refund_total'], $price_decimals );
		}
	}
	return $line_items;
}