| Conditions | 5 |
| Paths | 6 |
| Total Lines | 27 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 21 | public function refund(OrderInterface $order, array $orderItemUnitRefund, int $totalToRefund): array |
||
| 22 | { |
||
| 23 | /** @var AdjustmentInterface $refundedShipment */ |
||
| 24 | $refundedShipment = $order->getAdjustments('shipping')->first(); |
||
| 25 | |||
| 26 | $totalRefunded = 0; |
||
| 27 | if (!empty($orderItemUnitRefund)) { |
||
| 28 | /** @var OrderItemUnitRefund $item */ |
||
| 29 | foreach ($orderItemUnitRefund as $item) { |
||
| 30 | $totalRefunded += $item->total(); |
||
| 31 | } |
||
| 32 | |||
| 33 | $totalToRefund -= $totalRefunded; |
||
| 34 | } |
||
| 35 | |||
| 36 | if ($totalToRefund <= 0) { |
||
| 37 | return []; |
||
| 38 | } |
||
| 39 | |||
| 40 | if ($totalToRefund > $refundedShipment->getAmount()) { |
||
| 41 | $totalToRefund = $refundedShipment->getAmount(); |
||
| 42 | } |
||
| 43 | |||
| 44 | return [ |
||
| 45 | new ShipmentRefund( |
||
| 46 | $refundedShipment->getId(), |
||
| 47 | $totalToRefund |
||
| 48 | ), |
||
| 52 |