mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
Check null instead of float cast
This commit is contained in:
parent
ea462af3bf
commit
fdbbfd8dec
1 changed files with 29 additions and 15 deletions
|
@ -309,28 +309,42 @@ class PurchaseUnit {
|
|||
}
|
||||
|
||||
$item_total = $breakdown->item_total();
|
||||
$tax_total = $breakdown->tax_total();
|
||||
if ( $item_total ) {
|
||||
$remaining_item_total = array_reduce(
|
||||
$items,
|
||||
function ( float $total, Item $item ): float {
|
||||
return $total - $item->unit_amount()->value() * (float) $item->quantity();
|
||||
},
|
||||
$item_total->value()
|
||||
);
|
||||
|
||||
$fee_items_total = $item_total ? $item_total->value() : null;
|
||||
$fee_tax_total = $tax_total ? $tax_total->value() : null;
|
||||
$remaining_item_total = round( $remaining_item_total, 2 );
|
||||
|
||||
foreach ( $items as $item ) {
|
||||
if ( null !== $fee_items_total ) {
|
||||
$fee_items_total -= $item->unit_amount()->value() * (float) $item->quantity();
|
||||
}
|
||||
|
||||
$tax = $item->tax();
|
||||
if ( $tax && null !== $fee_tax_total ) {
|
||||
$fee_tax_total -= $tax->value() * (float) $item->quantity();
|
||||
}
|
||||
}
|
||||
|
||||
$fee_items_total = round( (float) $fee_items_total, 2 );
|
||||
$fee_tax_total = round( (float) $fee_tax_total, 2 );
|
||||
|
||||
if ( 0.0 !== $fee_items_total || 0.0 !== $fee_tax_total ) {
|
||||
if ( 0.0 !== $remaining_item_total ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$tax_total = $breakdown->tax_total();
|
||||
if ( $tax_total ) {
|
||||
$remaining_tax_total = array_reduce(
|
||||
$items,
|
||||
function ( float $total, Item $item ): float {
|
||||
$tax = $item->tax();
|
||||
if ( $tax ) {
|
||||
$total -= $tax->value() * (float) $item->quantity();
|
||||
}
|
||||
return $total;
|
||||
},
|
||||
$tax_total->value()
|
||||
);
|
||||
|
||||
$remaining_tax_total = round( $remaining_tax_total, 2 );
|
||||
|
||||
if ( 0.0 !== $remaining_tax_total ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$shipping = $breakdown->shipping();
|
||||
$discount = $breakdown->discount();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue