WC_Gateway_Paypal_Request::line_items_valid( WC_Order $order )
Check if the order has valid line items to use for PayPal request.
Description Description
The line items are invalid in case of mismatch in totals or if any amount < 0.
Parameters Parameters
- $order
-
(Required) Order to be examined.
Return Return
(bool)
Source Source
File: includes/gateways/paypal/includes/class-wc-gateway-paypal-request.php
protected function line_items_valid( $order ) { $negative_item_amount = false; $calculated_total = 0; // Products. foreach ( $order->get_items( array( 'line_item', 'fee' ) ) as $item ) { if ( 'fee' === $item['type'] ) { $item_line_total = $this->number_format( $item['line_total'], $order ); $calculated_total += $item_line_total; } else { $item_line_total = $this->number_format( $order->get_item_subtotal( $item, false ), $order ); $calculated_total += $item_line_total * $item->get_quantity(); } if ( $item_line_total < 0 ) { $negative_item_amount = true; } } $mismatched_totals = $this->number_format( $calculated_total + $order->get_total_tax() + $this->round( $order->get_shipping_total(), $order ) - $this->round( $order->get_total_discount(), $order ), $order ) !== $this->number_format( $order->get_total(), $order ); return ! $negative_item_amount && ! $mismatched_totals; }