diff --git a/modules/ppcp-api-client/src/Entity/PurchaseUnit.php b/modules/ppcp-api-client/src/Entity/PurchaseUnit.php
index a0af31b30..5f7e416a0 100644
--- a/modules/ppcp-api-client/src/Entity/PurchaseUnit.php
+++ b/modules/ppcp-api-client/src/Entity/PurchaseUnit.php
@@ -308,15 +308,20 @@ class PurchaseUnit {
return false;
}
- $fee_items_total = $breakdown->item_total() ? $breakdown->item_total()->value() : null;
- $fee_tax_total = $breakdown->tax_total() ? $breakdown->tax_total()->value() : null;
+ $item_total = $breakdown->item_total();
+ $tax_total = $breakdown->tax_total();
+
+ $fee_items_total = $item_total ? $item_total->value() : null;
+ $fee_tax_total = $tax_total ? $tax_total->value() : null;
foreach ( $items as $item ) {
if ( null !== $fee_items_total ) {
- $fee_items_total -= $item->unit_amount()->value() * $item->quantity();
+ $fee_items_total -= $item->unit_amount()->value() * (float) $item->quantity();
}
- if ( null !== $fee_tax_total ) {
- $fee_tax_total -= $item->tax()->value() * $item->quantity();
+
+ $tax = $item->tax();
+ if ( $tax && null !== $fee_tax_total ) {
+ $fee_tax_total -= $tax->value() * (float) $item->quantity();
}
}
@@ -327,27 +332,33 @@ class PurchaseUnit {
return true;
}
- $amount_total = 0;
- if ( $breakdown->shipping() ) {
- $amount_total += $breakdown->shipping()->value();
+ $shipping = $breakdown->shipping();
+ $discount = $breakdown->discount();
+ $shipping_discount = $breakdown->shipping_discount();
+ $handling = $breakdown->handling();
+ $insurance = $breakdown->insurance();
+
+ $amount_total = 0.0;
+ if ( $shipping ) {
+ $amount_total += $shipping->value();
}
- if ( $breakdown->item_total() ) {
- $amount_total += $breakdown->item_total()->value();
+ if ( $item_total ) {
+ $amount_total += $item_total->value();
}
- if ( $breakdown->discount() ) {
- $amount_total -= $breakdown->discount()->value();
+ if ( $discount ) {
+ $amount_total -= $discount->value();
}
- if ( $breakdown->tax_total() ) {
- $amount_total += $breakdown->tax_total()->value();
+ if ( $tax_total ) {
+ $amount_total += $tax_total->value();
}
- if ( $breakdown->shipping_discount() ) {
- $amount_total -= $breakdown->shipping_discount()->value();
+ if ( $shipping_discount ) {
+ $amount_total -= $shipping_discount->value();
}
- if ( $breakdown->handling() ) {
- $amount_total += $breakdown->handling()->value();
+ if ( $handling ) {
+ $amount_total += $handling->value();
}
- if ( $breakdown->insurance() ) {
- $amount_total += $breakdown->insurance()->value();
+ if ( $insurance ) {
+ $amount_total += $insurance->value();
}
$amount_value = $amount->value();
diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index 1cbd88402..e2aa3df83 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -159,35 +159,10 @@
-
- $amount_total += $breakdown->handling()->value()
- $amount_total += $breakdown->insurance()->value()
- $amount_total += $breakdown->item_total()->value()
- $amount_total += $breakdown->shipping()->value()
- $amount_total += $breakdown->tax_total()->value()
- $amount_total -= $breakdown->discount()->value()
- $amount_total -= $breakdown->shipping_discount()->value()
- $item->tax()->value() * $item->quantity()
- $item->unit_amount()->value() * $item->quantity()
-
-
- item_total
- item_total
- tax_total
- tax_total
+
to_array
to_array
to_array
- value
- value
- value
- value
- value
- value
- value
- value
- value
- value
@@ -768,9 +743,6 @@
-
- set_order_transaction_id
-
card
@@ -928,25 +900,6 @@
$request['resource']['purchase_units']
-
-
- rest_ensure_response( $response )
- rest_ensure_response( $response )
- rest_ensure_response( $response )
- rest_ensure_response( $response )
-
-
- \WP_REST_Response
-
-
- $request['resource']['custom_id']
- isset( $request['id'] ) ? $request['id'] : ''
- isset( $request['id'] ) ? $request['id'] : ''
-
-
- $request['resource']['custom_id']
-
-
rest_ensure_response( $response )