From 15d0422a7651fc8b4ef92611ec67c42ff009b5eb Mon Sep 17 00:00:00 2001 From: Spencer Date: Thu, 16 Feb 2023 16:31:56 +0100 Subject: [PATCH 01/11] wip: deleting the already refunded items --- .../RefundCollection/RefundCollection.php | 51 +++++++++++++++++++ .../RefundManager/RefundManager.php | 41 ++++++++++++--- 2 files changed, 84 insertions(+), 8 deletions(-) create mode 100644 src/Components/RefundManager/RefundCollection/RefundCollection.php diff --git a/src/Components/RefundManager/RefundCollection/RefundCollection.php b/src/Components/RefundManager/RefundCollection/RefundCollection.php new file mode 100644 index 000000000..fe64dfac1 --- /dev/null +++ b/src/Components/RefundManager/RefundCollection/RefundCollection.php @@ -0,0 +1,51 @@ +refundArray = []; + } + + /** + * @param string $mollieLineId + * @param int $quantity + * @return void + */ + public function addRefund(string $mollieLineId, int $quantity) + { + if (isset($this->refundArray[$mollieLineId])) { + $this->refundArray[$mollieLineId] = $this->refundArray[$mollieLineId] + $quantity; + } else { + $this->refundArray[$mollieLineId] = $quantity; + } + } + + /** + * @return array + */ + public function getRefundArray(): array + { + return $this->refundArray; + } + + /** + * @param $orderLineId + * @return int + */ + public function getRefundQuantityForMollieId($orderLineId): int + { + if (isset($this->refundArray[$orderLineId])) { + return $this->refundArray[$orderLineId]; + } + return 0; + } + + +} diff --git a/src/Components/RefundManager/RefundManager.php b/src/Components/RefundManager/RefundManager.php index b1de086ce..66ab9847f 100644 --- a/src/Components/RefundManager/RefundManager.php +++ b/src/Components/RefundManager/RefundManager.php @@ -4,22 +4,19 @@ use Kiener\MolliePayments\Compatibility\Bundles\FlowBuilder\FlowBuilderDispatcherAdapterInterface; use Kiener\MolliePayments\Compatibility\Bundles\FlowBuilder\FlowBuilderEventFactory; -use Kiener\MolliePayments\Compatibility\Bundles\FlowBuilder\FlowBuilderFactory; use Kiener\MolliePayments\Compatibility\Bundles\FlowBuilder\FlowBuilderFactoryInterface; use Kiener\MolliePayments\Components\RefundManager\Builder\RefundDataBuilder; use Kiener\MolliePayments\Components\RefundManager\Integrators\StockManagerInterface; +use Kiener\MolliePayments\Components\RefundManager\RefundCollection\RefundCollection; use Kiener\MolliePayments\Components\RefundManager\RefundData\RefundData; use Kiener\MolliePayments\Components\RefundManager\Request\RefundRequest; use Kiener\MolliePayments\Components\RefundManager\Request\RefundRequestItem; use Kiener\MolliePayments\Components\RefundManager\Request\RefundRequestItemRoundingDiff; use Kiener\MolliePayments\Exception\CouldNotCreateMollieRefundException; use Kiener\MolliePayments\Service\MollieApi\Order; -use Kiener\MolliePayments\Service\OrderService; use Kiener\MolliePayments\Service\OrderServiceInterface; use Kiener\MolliePayments\Service\Refund\Item\RefundItem; -use Kiener\MolliePayments\Service\Refund\RefundService; use Kiener\MolliePayments\Service\Refund\RefundServiceInterface; -use Kiener\MolliePayments\Service\Stock\StockManager; use Kiener\MolliePayments\Struct\MollieApi\OrderLineMetaDataStruct; use Kiener\MolliePayments\Struct\Order\OrderAttributes; use Kiener\MolliePayments\Struct\OrderLineItemEntity\OrderLineItemEntityAttributes; @@ -27,6 +24,7 @@ use Mollie\Api\Resources\Refund; use Psr\Log\LoggerInterface; use Shopware\Core\Checkout\Order\Aggregate\OrderDelivery\OrderDeliveryCollection; +use Shopware\Core\Checkout\Order\Aggregate\OrderDelivery\OrderDeliveryEntity; use Shopware\Core\Checkout\Order\Aggregate\OrderLineItem\OrderLineItemCollection; use Shopware\Core\Checkout\Order\Aggregate\OrderLineItem\OrderLineItemEntity; use Shopware\Core\Checkout\Order\OrderEntity; @@ -116,8 +114,8 @@ public function getData(OrderEntity $order, Context $context): RefundData * @param OrderEntity $order * @param RefundRequest $request * @param Context $context - * @throws \Mollie\Api\Exceptions\ApiException * @return Refund + * @throws \Mollie\Api\Exceptions\ApiException */ public function refund(OrderEntity $order, RefundRequest $request, Context $context): Refund { @@ -213,7 +211,7 @@ public function refund(OrderEntity $order, RefundRequest $request, Context $cont } - if (! $refund instanceof Refund) { + if (!$refund instanceof Refund) { # a problem happened, lets finish with an exception throw new CouldNotCreateMollieRefundException('', (string)$order->getOrderNumber()); } @@ -300,21 +298,48 @@ private function getOrderItem(OrderEntity $orderEntity, string $lineID): ?OrderL */ private function buildRequestItemsFromOrder(OrderEntity $order) { + + $refunds = $this->refundService->getRefunds($order); +// dump($refunds); + $refundCollection = new RefundCollection(); + foreach ($refunds as $refund) { + if (!isset($refund['metadata'])) { + continue; + } + + $metadata = $refund['metadata']; + if (!isset($metadata['composition'])) { + continue; + } + + $composition = $metadata['composition']; + foreach ($composition as $lineItem) { + $refundCollection->addRefund($lineItem['mollieLineId'], $lineItem['quantity']); + + } + } + $items = []; if ($order->getLineItems() instanceof OrderLineItemCollection) { + /** @var OrderLineItemEntity $lineItem */ foreach ($order->getLineItems() as $lineItem) { + $orderLineId = $lineItem->getCustomFields()['mollie_payments']['order_line_id']; + $alreadyRefundedQuantity = $refundCollection->getRefundQuantityForMollieId($orderLineId); $items[] = new RefundRequestItem( $lineItem->getId(), $lineItem->getTotalPrice(), - $lineItem->getQuantity(), + $lineItem->getQuantity() - $alreadyRefundedQuantity, 0 ); } } if ($order->getDeliveries() instanceof OrderDeliveryCollection) { + /** @var OrderDeliveryEntity $delivery */ foreach ($order->getDeliveries() as $delivery) { +// dump($delivery); + $alreadyRefundedQuantity = $refundCollection->getRefundQuantityForMollieId($orderLineId); $items[] = new RefundRequestItem( $delivery->getId(), $delivery->getShippingCosts()->getTotalPrice(), @@ -323,7 +348,7 @@ private function buildRequestItemsFromOrder(OrderEntity $order) ); } } - +// dd($items); return $items; } From e577b629b59d1feb3fa6d26499b834a70045b2ef Mon Sep 17 00:00:00 2001 From: Smemoict Date: Wed, 22 Feb 2023 10:27:18 +0100 Subject: [PATCH 02/11] add: metadata added to delivery for later use. --- src/Resources/config/services/services.xml | 1 + src/Service/Order/UpdateOrderLineItems.php | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Resources/config/services/services.xml b/src/Resources/config/services/services.xml index 6e8593bf6..601525ff7 100644 --- a/src/Resources/config/services/services.xml +++ b/src/Resources/config/services/services.xml @@ -95,6 +95,7 @@ + diff --git a/src/Service/Order/UpdateOrderLineItems.php b/src/Service/Order/UpdateOrderLineItems.php index cddedf201..35fe3ce84 100644 --- a/src/Service/Order/UpdateOrderLineItems.php +++ b/src/Service/Order/UpdateOrderLineItems.php @@ -17,13 +17,19 @@ class UpdateOrderLineItems */ private $orderLineRepository; + /** + * @var EntityRepositoryInterface + */ + private $orderDeliveryRepository; + /** * @param EntityRepositoryInterface $orderLineRepository */ - public function __construct(EntityRepositoryInterface $orderLineRepository) + public function __construct(EntityRepositoryInterface $orderLineRepository, EntityRepositoryInterface $orderDeliveryRepository) { $this->orderLineRepository = $orderLineRepository; + $this->orderDeliveryRepository = $orderDeliveryRepository; } /** @@ -34,10 +40,7 @@ public function updateOrderLineItems(Order $mollieOrder, SalesChannelContext $sa { /** @var OrderLine $orderLine */ foreach ($mollieOrder->lines() as $orderLine) { - if ($orderLine->type === OrderLineType::TYPE_SHIPPING_FEE) { - continue; - } - + ##Contrary to the name, this can also be an order_delivery id since these are also kind of line items $shopwareLineItemId = (string)$orderLine->metadata->orderLineItemId; if (empty($shopwareLineItemId)) { @@ -53,7 +56,11 @@ public function updateOrderLineItems(Order $mollieOrder, SalesChannelContext $sa ] ]; - $this->orderLineRepository->update([$data], $salesChannelContext->getContext()); + if ($orderLine->type === OrderLineType::TYPE_SHIPPING_FEE) { + $this->orderDeliveryRepository->update([$data], $salesChannelContext->getContext()); + } else { + $this->orderLineRepository->update([$data], $salesChannelContext->getContext()); + } } } } From 1d8a04d542cbf775fb56324adddcda6ef8fe248d Mon Sep 17 00:00:00 2001 From: Smemoict Date: Wed, 22 Feb 2023 10:29:31 +0100 Subject: [PATCH 03/11] add: remove already refunded delivery --- src/Components/RefundManager/RefundManager.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Components/RefundManager/RefundManager.php b/src/Components/RefundManager/RefundManager.php index 66ab9847f..2caabbe25 100644 --- a/src/Components/RefundManager/RefundManager.php +++ b/src/Components/RefundManager/RefundManager.php @@ -300,7 +300,7 @@ private function buildRequestItemsFromOrder(OrderEntity $order) { $refunds = $this->refundService->getRefunds($order); -// dump($refunds); + $refundCollection = new RefundCollection(); foreach ($refunds as $refund) { if (!isset($refund['metadata'])) { @@ -315,7 +315,6 @@ private function buildRequestItemsFromOrder(OrderEntity $order) $composition = $metadata['composition']; foreach ($composition as $lineItem) { $refundCollection->addRefund($lineItem['mollieLineId'], $lineItem['quantity']); - } } @@ -338,17 +337,17 @@ private function buildRequestItemsFromOrder(OrderEntity $order) if ($order->getDeliveries() instanceof OrderDeliveryCollection) { /** @var OrderDeliveryEntity $delivery */ foreach ($order->getDeliveries() as $delivery) { -// dump($delivery); + $orderLineId = $delivery->getCustomFields()['mollie_payments']['order_line_id']; $alreadyRefundedQuantity = $refundCollection->getRefundQuantityForMollieId($orderLineId); $items[] = new RefundRequestItem( $delivery->getId(), $delivery->getShippingCosts()->getTotalPrice(), - $delivery->getShippingCosts()->getQuantity(), + $delivery->getShippingCosts()->getQuantity() - $alreadyRefundedQuantity, 0 ); } } -// dd($items); + return $items; } From 37810d0f2bfe4d978e74bf2ab2f99ea68b692573 Mon Sep 17 00:00:00 2001 From: Smemoict Date: Wed, 22 Feb 2023 10:53:16 +0100 Subject: [PATCH 04/11] cha: name to be more descriptive and less confusing --- .../RefundCalculationHelper.php} | 8 +++----- src/Components/RefundManager/RefundManager.php | 13 ++++++------- 2 files changed, 9 insertions(+), 12 deletions(-) rename src/Components/RefundManager/{RefundCollection/RefundCollection.php => RefundCalculationHelper/RefundCalculationHelper.php} (93%) diff --git a/src/Components/RefundManager/RefundCollection/RefundCollection.php b/src/Components/RefundManager/RefundCalculationHelper/RefundCalculationHelper.php similarity index 93% rename from src/Components/RefundManager/RefundCollection/RefundCollection.php rename to src/Components/RefundManager/RefundCalculationHelper/RefundCalculationHelper.php index fe64dfac1..e5691b3aa 100644 --- a/src/Components/RefundManager/RefundCollection/RefundCollection.php +++ b/src/Components/RefundManager/RefundCalculationHelper/RefundCalculationHelper.php @@ -1,12 +1,12 @@ refundService->getRefunds($order); - $refundCollection = new RefundCollection(); + $refundCalculationHelper = new RefundCalculationHelper(); foreach ($refunds as $refund) { if (!isset($refund['metadata'])) { continue; @@ -314,7 +313,7 @@ private function buildRequestItemsFromOrder(OrderEntity $order) $composition = $metadata['composition']; foreach ($composition as $lineItem) { - $refundCollection->addRefund($lineItem['mollieLineId'], $lineItem['quantity']); + $refundCalculationHelper->addRefund($lineItem['mollieLineId'], $lineItem['quantity']); } } @@ -324,7 +323,7 @@ private function buildRequestItemsFromOrder(OrderEntity $order) /** @var OrderLineItemEntity $lineItem */ foreach ($order->getLineItems() as $lineItem) { $orderLineId = $lineItem->getCustomFields()['mollie_payments']['order_line_id']; - $alreadyRefundedQuantity = $refundCollection->getRefundQuantityForMollieId($orderLineId); + $alreadyRefundedQuantity = $refundCalculationHelper->getRefundQuantityForMollieId($orderLineId); $items[] = new RefundRequestItem( $lineItem->getId(), $lineItem->getTotalPrice(), @@ -338,7 +337,7 @@ private function buildRequestItemsFromOrder(OrderEntity $order) /** @var OrderDeliveryEntity $delivery */ foreach ($order->getDeliveries() as $delivery) { $orderLineId = $delivery->getCustomFields()['mollie_payments']['order_line_id']; - $alreadyRefundedQuantity = $refundCollection->getRefundQuantityForMollieId($orderLineId); + $alreadyRefundedQuantity = $refundCalculationHelper->getRefundQuantityForMollieId($orderLineId); $items[] = new RefundRequestItem( $delivery->getId(), $delivery->getShippingCosts()->getTotalPrice(), From aa1c922ffcbda1612ac8d70f887eb1d1580c577b Mon Sep 17 00:00:00 2001 From: Smemoict Date: Wed, 22 Feb 2023 12:02:57 +0100 Subject: [PATCH 05/11] fix: stan --- .../RefundCalculationHelper.php | 14 ++------ .../RefundManager/RefundManager.php | 34 ++++++++++++++++--- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/Components/RefundManager/RefundCalculationHelper/RefundCalculationHelper.php b/src/Components/RefundManager/RefundCalculationHelper/RefundCalculationHelper.php index e5691b3aa..53073e779 100644 --- a/src/Components/RefundManager/RefundCalculationHelper/RefundCalculationHelper.php +++ b/src/Components/RefundManager/RefundCalculationHelper/RefundCalculationHelper.php @@ -5,7 +5,7 @@ class RefundCalculationHelper { - /** @var array */ + /** @var array */ protected $refundArray; public function __construct() @@ -28,18 +28,10 @@ public function addRefund(string $mollieLineId, int $quantity) } /** - * @return array - */ - public function getRefundArray(): array - { - return $this->refundArray; - } - - /** - * @param $orderLineId + * @param string $orderLineId * @return int */ - public function getRefundQuantityForMollieId($orderLineId): int + public function getRefundQuantityForMollieId(string $orderLineId): int { if (isset($this->refundArray[$orderLineId])) { return $this->refundArray[$orderLineId]; diff --git a/src/Components/RefundManager/RefundManager.php b/src/Components/RefundManager/RefundManager.php index 3acaaecc6..70a4d48ff 100644 --- a/src/Components/RefundManager/RefundManager.php +++ b/src/Components/RefundManager/RefundManager.php @@ -301,12 +301,13 @@ private function buildRequestItemsFromOrder(OrderEntity $order) $refunds = $this->refundService->getRefunds($order); $refundCalculationHelper = new RefundCalculationHelper(); + foreach ($refunds as $refund) { - if (!isset($refund['metadata'])) { + if (!isset($refund->metadata)) { continue; } - $metadata = $refund['metadata']; + $metadata = $refund->metadata; if (!isset($metadata['composition'])) { continue; } @@ -322,7 +323,7 @@ private function buildRequestItemsFromOrder(OrderEntity $order) if ($order->getLineItems() instanceof OrderLineItemCollection) { /** @var OrderLineItemEntity $lineItem */ foreach ($order->getLineItems() as $lineItem) { - $orderLineId = $lineItem->getCustomFields()['mollie_payments']['order_line_id']; + $orderLineId = $this->getOrderLineId($lineItem); $alreadyRefundedQuantity = $refundCalculationHelper->getRefundQuantityForMollieId($orderLineId); $items[] = new RefundRequestItem( $lineItem->getId(), @@ -336,7 +337,7 @@ private function buildRequestItemsFromOrder(OrderEntity $order) if ($order->getDeliveries() instanceof OrderDeliveryCollection) { /** @var OrderDeliveryEntity $delivery */ foreach ($order->getDeliveries() as $delivery) { - $orderLineId = $delivery->getCustomFields()['mollie_payments']['order_line_id']; + $orderLineId = $this->getOrderLineId($delivery); $alreadyRefundedQuantity = $refundCalculationHelper->getRefundQuantityForMollieId($orderLineId); $items[] = new RefundRequestItem( $delivery->getId(), @@ -449,4 +450,29 @@ private function convertToRefundItems(RefundRequest $request, OrderEntity $order return $serviceItems; } + + /** + * @param OrderDeliveryEntity|OrderLineItemEntity $lineItem + * @return string + */ + public function getOrderLineId($lineItem): string + { + $customFields = $lineItem->getCustomFields(); + + if (!isset($customFields)) { + return ""; + } + + if (!isset($customFields['mollie_payments'])) { + return ""; + } + + $molliePayments = $customFields['mollie_payments']; + + if (!isset($molliePayments['order_line_id'])) { + return ""; + } + + return $molliePayments['order_line_id']; + } } From 3b25086f63dd93c7bc05f66e853be9378cda332f Mon Sep 17 00:00:00 2001 From: Smemoict Date: Wed, 22 Feb 2023 13:05:12 +0100 Subject: [PATCH 06/11] add: refund amount calculation on full refund --- .../RefundCalculationHelper.php | 43 +++++++++++++------ .../RefundManager/RefundManager.php | 33 ++++++++++---- 2 files changed, 54 insertions(+), 22 deletions(-) diff --git a/src/Components/RefundManager/RefundCalculationHelper/RefundCalculationHelper.php b/src/Components/RefundManager/RefundCalculationHelper/RefundCalculationHelper.php index 53073e779..e710aa516 100644 --- a/src/Components/RefundManager/RefundCalculationHelper/RefundCalculationHelper.php +++ b/src/Components/RefundManager/RefundCalculationHelper/RefundCalculationHelper.php @@ -3,28 +3,25 @@ namespace Kiener\MolliePayments\Components\RefundManager\RefundCalculationHelper; +use Kiener\MolliePayments\Service\Refund\Item\RefundItem; + class RefundCalculationHelper { - /** @var array */ - protected $refundArray; + /** @var RefundItem[] */ + protected $refundItems; public function __construct() { - $this->refundArray = []; + $this->refundItems = []; } /** - * @param string $mollieLineId - * @param int $quantity + * @param RefundItem $refundItem * @return void */ - public function addRefund(string $mollieLineId, int $quantity) + public function addRefundItem(RefundItem $refundItem) { - if (isset($this->refundArray[$mollieLineId])) { - $this->refundArray[$mollieLineId] = $this->refundArray[$mollieLineId] + $quantity; - } else { - $this->refundArray[$mollieLineId] = $quantity; - } + $this->refundItems[] = $refundItem; } /** @@ -33,9 +30,27 @@ public function addRefund(string $mollieLineId, int $quantity) */ public function getRefundQuantityForMollieId(string $orderLineId): int { - if (isset($this->refundArray[$orderLineId])) { - return $this->refundArray[$orderLineId]; + $refundQuantity = 0; + foreach ($this->refundItems as $refundItem) { + if ($refundItem->getMollieLineID()===$orderLineId){ + $refundQuantity += $refundItem->getQuantity(); + } + } + return $refundQuantity; + } + + /** + * @param string $orderLineId + * @return float + */ + public function getRefundAmountForMollieId(string $orderLineId): float + { + $refundAmount = 0; + foreach ($this->refundItems as $refundItem) { + if ($refundItem->getMollieLineID()===$orderLineId){ + $refundAmount += $refundItem->getAmount(); + } } - return 0; + return $refundAmount; } } diff --git a/src/Components/RefundManager/RefundManager.php b/src/Components/RefundManager/RefundManager.php index 70a4d48ff..214977982 100644 --- a/src/Components/RefundManager/RefundManager.php +++ b/src/Components/RefundManager/RefundManager.php @@ -114,8 +114,8 @@ public function getData(OrderEntity $order, Context $context): RefundData * @param OrderEntity $order * @param RefundRequest $request * @param Context $context - * @throws \Mollie\Api\Exceptions\ApiException * @return Refund + * @throws \Mollie\Api\Exceptions\ApiException */ public function refund(OrderEntity $order, RefundRequest $request, Context $context): Refund { @@ -301,20 +301,29 @@ private function buildRequestItemsFromOrder(OrderEntity $order) $refunds = $this->refundService->getRefunds($order); $refundCalculationHelper = new RefundCalculationHelper(); - + /** @var array $refund */ foreach ($refunds as $refund) { - if (!isset($refund->metadata)) { + if (!isset($refund['metadata'])) { continue; } - $metadata = $refund->metadata; + $metadata = $refund['metadata']; if (!isset($metadata['composition'])) { continue; } $composition = $metadata['composition']; - foreach ($composition as $lineItem) { - $refundCalculationHelper->addRefund($lineItem['mollieLineId'], $lineItem['quantity']); + + foreach ($composition as $compositionItem) { + + $refundCalculationHelper->addRefundItem( + new RefundItem( + $compositionItem['swLineId'], + $compositionItem['mollieLineId'], + $compositionItem['swReference'], + $compositionItem['quantity'], + $compositionItem['amount'] + )); } } @@ -323,11 +332,15 @@ private function buildRequestItemsFromOrder(OrderEntity $order) if ($order->getLineItems() instanceof OrderLineItemCollection) { /** @var OrderLineItemEntity $lineItem */ foreach ($order->getLineItems() as $lineItem) { + $orderLineId = $this->getOrderLineId($lineItem); + $alreadyRefundedQuantity = $refundCalculationHelper->getRefundQuantityForMollieId($orderLineId); + $alreadyRefundedAmount = $refundCalculationHelper->getRefundAmountForMollieId($orderLineId); + $items[] = new RefundRequestItem( $lineItem->getId(), - $lineItem->getTotalPrice(), + $lineItem->getTotalPrice() - $alreadyRefundedAmount, $lineItem->getQuantity() - $alreadyRefundedQuantity, 0 ); @@ -337,11 +350,15 @@ private function buildRequestItemsFromOrder(OrderEntity $order) if ($order->getDeliveries() instanceof OrderDeliveryCollection) { /** @var OrderDeliveryEntity $delivery */ foreach ($order->getDeliveries() as $delivery) { + $orderLineId = $this->getOrderLineId($delivery); + $alreadyRefundedQuantity = $refundCalculationHelper->getRefundQuantityForMollieId($orderLineId); + $alreadyRefundedAmount = $refundCalculationHelper->getRefundAmountForMollieId($orderLineId); + $items[] = new RefundRequestItem( $delivery->getId(), - $delivery->getShippingCosts()->getTotalPrice(), + $delivery->getShippingCosts()->getTotalPrice() - $alreadyRefundedAmount, $delivery->getShippingCosts()->getQuantity() - $alreadyRefundedQuantity, 0 ); From 378c813547a7a66eb69068b84661c3f8ff783892 Mon Sep 17 00:00:00 2001 From: Smemoict Date: Wed, 22 Feb 2023 13:17:30 +0100 Subject: [PATCH 07/11] add: empty return on refund service getRefunds --- tests/PHPUnit/Fakes/FakeRefundService.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/PHPUnit/Fakes/FakeRefundService.php b/tests/PHPUnit/Fakes/FakeRefundService.php index a97485601..2cc46f0c4 100644 --- a/tests/PHPUnit/Fakes/FakeRefundService.php +++ b/tests/PHPUnit/Fakes/FakeRefundService.php @@ -111,7 +111,8 @@ public function cancel(OrderEntity $order, string $refundId): bool */ public function getRefunds(OrderEntity $order): array { - // TODO: Implement getRefunds() method. + // FIXME: Only implements that nothing has been refunded yet, this might have to be changed. + return []; } /** From 30d2d0b838e808f283c6c3847e648ca79b237d59 Mon Sep 17 00:00:00 2001 From: Smemoict Date: Wed, 22 Feb 2023 13:18:12 +0100 Subject: [PATCH 08/11] cha: make pr --- .../RefundCalculationHelper.php | 4 ++-- src/Components/RefundManager/RefundManager.php | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Components/RefundManager/RefundCalculationHelper/RefundCalculationHelper.php b/src/Components/RefundManager/RefundCalculationHelper/RefundCalculationHelper.php index e710aa516..ced084e0b 100644 --- a/src/Components/RefundManager/RefundCalculationHelper/RefundCalculationHelper.php +++ b/src/Components/RefundManager/RefundCalculationHelper/RefundCalculationHelper.php @@ -32,7 +32,7 @@ public function getRefundQuantityForMollieId(string $orderLineId): int { $refundQuantity = 0; foreach ($this->refundItems as $refundItem) { - if ($refundItem->getMollieLineID()===$orderLineId){ + if ($refundItem->getMollieLineID()===$orderLineId) { $refundQuantity += $refundItem->getQuantity(); } } @@ -47,7 +47,7 @@ public function getRefundAmountForMollieId(string $orderLineId): float { $refundAmount = 0; foreach ($this->refundItems as $refundItem) { - if ($refundItem->getMollieLineID()===$orderLineId){ + if ($refundItem->getMollieLineID()===$orderLineId) { $refundAmount += $refundItem->getAmount(); } } diff --git a/src/Components/RefundManager/RefundManager.php b/src/Components/RefundManager/RefundManager.php index 214977982..f2dba6e76 100644 --- a/src/Components/RefundManager/RefundManager.php +++ b/src/Components/RefundManager/RefundManager.php @@ -114,8 +114,8 @@ public function getData(OrderEntity $order, Context $context): RefundData * @param OrderEntity $order * @param RefundRequest $request * @param Context $context - * @return Refund * @throws \Mollie\Api\Exceptions\ApiException + * @return Refund */ public function refund(OrderEntity $order, RefundRequest $request, Context $context): Refund { @@ -301,7 +301,7 @@ private function buildRequestItemsFromOrder(OrderEntity $order) $refunds = $this->refundService->getRefunds($order); $refundCalculationHelper = new RefundCalculationHelper(); - /** @var array $refund */ + /** @var array $refund */ foreach ($refunds as $refund) { if (!isset($refund['metadata'])) { continue; @@ -315,7 +315,6 @@ private function buildRequestItemsFromOrder(OrderEntity $order) $composition = $metadata['composition']; foreach ($composition as $compositionItem) { - $refundCalculationHelper->addRefundItem( new RefundItem( $compositionItem['swLineId'], @@ -323,7 +322,8 @@ private function buildRequestItemsFromOrder(OrderEntity $order) $compositionItem['swReference'], $compositionItem['quantity'], $compositionItem['amount'] - )); + ) + ); } } @@ -332,7 +332,6 @@ private function buildRequestItemsFromOrder(OrderEntity $order) if ($order->getLineItems() instanceof OrderLineItemCollection) { /** @var OrderLineItemEntity $lineItem */ foreach ($order->getLineItems() as $lineItem) { - $orderLineId = $this->getOrderLineId($lineItem); $alreadyRefundedQuantity = $refundCalculationHelper->getRefundQuantityForMollieId($orderLineId); @@ -350,7 +349,6 @@ private function buildRequestItemsFromOrder(OrderEntity $order) if ($order->getDeliveries() instanceof OrderDeliveryCollection) { /** @var OrderDeliveryEntity $delivery */ foreach ($order->getDeliveries() as $delivery) { - $orderLineId = $this->getOrderLineId($delivery); $alreadyRefundedQuantity = $refundCalculationHelper->getRefundQuantityForMollieId($orderLineId); From d1e6c3abff9a852bbaf1a071af12ef143437fc93 Mon Sep 17 00:00:00 2001 From: Spencer Date: Wed, 1 Mar 2023 09:02:06 +0100 Subject: [PATCH 09/11] del: duplicate operation --- .../RefundManager/RefundManager.php | 33 +++---------------- 1 file changed, 4 insertions(+), 29 deletions(-) diff --git a/src/Components/RefundManager/RefundManager.php b/src/Components/RefundManager/RefundManager.php index f2dba6e76..62b16e038 100644 --- a/src/Components/RefundManager/RefundManager.php +++ b/src/Components/RefundManager/RefundManager.php @@ -332,8 +332,8 @@ private function buildRequestItemsFromOrder(OrderEntity $order) if ($order->getLineItems() instanceof OrderLineItemCollection) { /** @var OrderLineItemEntity $lineItem */ foreach ($order->getLineItems() as $lineItem) { - $orderLineId = $this->getOrderLineId($lineItem); - + $orderItemAttributes = new OrderLineItemEntityAttributes($lineItem); + $orderLineId = $orderItemAttributes->getMollieOrderLineID(); $alreadyRefundedQuantity = $refundCalculationHelper->getRefundQuantityForMollieId($orderLineId); $alreadyRefundedAmount = $refundCalculationHelper->getRefundAmountForMollieId($orderLineId); @@ -349,8 +349,8 @@ private function buildRequestItemsFromOrder(OrderEntity $order) if ($order->getDeliveries() instanceof OrderDeliveryCollection) { /** @var OrderDeliveryEntity $delivery */ foreach ($order->getDeliveries() as $delivery) { - $orderLineId = $this->getOrderLineId($delivery); - + $orderItemAttributes = new OrderLineItemEntityAttributes($lineItem); + $orderLineId = $orderItemAttributes->getMollieOrderLineID(); $alreadyRefundedQuantity = $refundCalculationHelper->getRefundQuantityForMollieId($orderLineId); $alreadyRefundedAmount = $refundCalculationHelper->getRefundAmountForMollieId($orderLineId); @@ -465,29 +465,4 @@ private function convertToRefundItems(RefundRequest $request, OrderEntity $order return $serviceItems; } - - /** - * @param OrderDeliveryEntity|OrderLineItemEntity $lineItem - * @return string - */ - public function getOrderLineId($lineItem): string - { - $customFields = $lineItem->getCustomFields(); - - if (!isset($customFields)) { - return ""; - } - - if (!isset($customFields['mollie_payments'])) { - return ""; - } - - $molliePayments = $customFields['mollie_payments']; - - if (!isset($molliePayments['order_line_id'])) { - return ""; - } - - return $molliePayments['order_line_id']; - } } From 74ff6bcc5ac6fe4b85b4776dc2d0f2517aed7adf Mon Sep 17 00:00:00 2001 From: Spencer Date: Wed, 1 Mar 2023 16:12:40 +0100 Subject: [PATCH 10/11] wip: rewrite --- .../RefundData/OrderItem/DeliveryItem.php | 8 ++ .../RefundData/OrderItem/ProductItem.php | 8 ++ .../RefundManager/RefundData/RefundData.php | 64 ++++++++++++++ .../RefundManager/RefundManager.php | 83 ++++++++--------- .../OrderDeliveryEntityAttributes.php | 19 ++++ .../OrderLineItemEntityAttributes.php | 88 +++++-------------- src/Struct/OrderXEntityAttributes.php | 72 +++++++++++++++ 7 files changed, 237 insertions(+), 105 deletions(-) create mode 100644 src/Struct/OrderDeliveryEntity/OrderDeliveryEntityAttributes.php create mode 100644 src/Struct/OrderXEntityAttributes.php diff --git a/src/Components/RefundManager/RefundData/OrderItem/DeliveryItem.php b/src/Components/RefundManager/RefundData/OrderItem/DeliveryItem.php index 7844a861b..85cf0a7e8 100644 --- a/src/Components/RefundManager/RefundData/OrderItem/DeliveryItem.php +++ b/src/Components/RefundManager/RefundData/OrderItem/DeliveryItem.php @@ -53,4 +53,12 @@ public function toArray(): array $this->alreadyRefundedQty ); } + + /** + * @return OrderDeliveryEntity + */ + public function getDelivery(): OrderDeliveryEntity + { + return $this->delivery; + } } diff --git a/src/Components/RefundManager/RefundData/OrderItem/ProductItem.php b/src/Components/RefundManager/RefundData/OrderItem/ProductItem.php index f809f1ac5..1aebc1c0b 100644 --- a/src/Components/RefundManager/RefundData/OrderItem/ProductItem.php +++ b/src/Components/RefundManager/RefundData/OrderItem/ProductItem.php @@ -99,4 +99,12 @@ private function getProductNumber(): string return (string)$this->lineItem->getPayload()['productNumber']; } + + /** + * @return OrderLineItemEntity + */ + public function getLineItem(): OrderLineItemEntity + { + return $this->lineItem; + } } diff --git a/src/Components/RefundManager/RefundData/RefundData.php b/src/Components/RefundManager/RefundData/RefundData.php index b96c93cd3..3b7b3b9b1 100644 --- a/src/Components/RefundManager/RefundData/RefundData.php +++ b/src/Components/RefundManager/RefundData/RefundData.php @@ -3,6 +3,11 @@ namespace Kiener\MolliePayments\Components\RefundManager\RefundData; use Kiener\MolliePayments\Components\RefundManager\RefundData\OrderItem\AbstractItem; +use Kiener\MolliePayments\Components\RefundManager\RefundData\OrderItem\DeliveryItem; +use Kiener\MolliePayments\Components\RefundManager\RefundData\OrderItem\ProductItem; +use Kiener\MolliePayments\Service\Refund\Item\RefundItem; +use Kiener\MolliePayments\Struct\OrderDeliveryEntity\OrderDeliveryEntityAttributes; +use Kiener\MolliePayments\Struct\OrderLineItemEntity\OrderLineItemEntityAttributes; use Mollie\Api\Resources\Refund; class RefundData @@ -43,6 +48,7 @@ class RefundData */ private $roundingItemTotal; + /** * @param AbstractItem[] $cartItems * @param Refund[] $refunds @@ -156,4 +162,62 @@ public function toArray() 'refunds' => $refundsArray, ]; } + + /** + * @param string $mollieId + * @return int + */ + public function getRefundedQuantity(string $mollieId): int + { + foreach ($this->orderItems as $orderItem) { + if ($orderItem instanceof ProductItem) { + $orderItemAttributes = new OrderLineItemEntityAttributes($orderItem->getLineItem()); + } + + if ($orderItem instanceof DeliveryItem) { + $orderItemAttributes = new OrderDeliveryEntityAttributes($orderItem->getDelivery()); + } + + if (empty($orderItemAttributes)) { + continue; + } + + if ($mollieId === $orderItemAttributes->getMollieOrderLineID()) { + $refundArray = $orderItem->toArray(); + return $refundArray['refunded']; + } + } + return 0; + } + + /** + * @param string $mollieId + * @return float + */ + public function getRefundedAmount(string $mollieId):float + { + $totalAmount = 0; + + ## The amount is being calculated via the refunds because it might have been a custom amount. + foreach ($this->refunds as $refund) { + if (!isset($refund['metadata'])) { + continue; + } + + $metadata = $refund['metadata']; + if (!isset($metadata['composition'])) { + continue; + } + + $composition = $metadata['composition']; + + foreach ($composition as $compositionItem) { + if ($compositionItem['mollieLineId']===$mollieId){ + $totalAmount+=$compositionItem['amount']; + } + + } + } + return $totalAmount; + } } diff --git a/src/Components/RefundManager/RefundManager.php b/src/Components/RefundManager/RefundManager.php index 62b16e038..ff6f234f9 100644 --- a/src/Components/RefundManager/RefundManager.php +++ b/src/Components/RefundManager/RefundManager.php @@ -7,7 +7,6 @@ use Kiener\MolliePayments\Compatibility\Bundles\FlowBuilder\FlowBuilderFactoryInterface; use Kiener\MolliePayments\Components\RefundManager\Builder\RefundDataBuilder; use Kiener\MolliePayments\Components\RefundManager\Integrators\StockManagerInterface; -use Kiener\MolliePayments\Components\RefundManager\RefundCalculationHelper\RefundCalculationHelper; use Kiener\MolliePayments\Components\RefundManager\RefundData\RefundData; use Kiener\MolliePayments\Components\RefundManager\Request\RefundRequest; use Kiener\MolliePayments\Components\RefundManager\Request\RefundRequestItem; @@ -19,6 +18,7 @@ use Kiener\MolliePayments\Service\Refund\RefundServiceInterface; use Kiener\MolliePayments\Struct\MollieApi\OrderLineMetaDataStruct; use Kiener\MolliePayments\Struct\Order\OrderAttributes; +use Kiener\MolliePayments\Struct\OrderDeliveryEntity\OrderDeliveryEntityAttributes; use Kiener\MolliePayments\Struct\OrderLineItemEntity\OrderLineItemEntityAttributes; use Mollie\Api\Resources\OrderLine; use Mollie\Api\Resources\Refund; @@ -114,8 +114,8 @@ public function getData(OrderEntity $order, Context $context): RefundData * @param OrderEntity $order * @param RefundRequest $request * @param Context $context - * @throws \Mollie\Api\Exceptions\ApiException * @return Refund + * @throws \Mollie\Api\Exceptions\ApiException */ public function refund(OrderEntity $order, RefundRequest $request, Context $context): Refund { @@ -153,7 +153,7 @@ public function refund(OrderEntity $order, RefundRequest $request, Context $cont # we have a full refund, but only with amount # and no items. to make sure that we have clean data # we have to extract all items, so that they will be added to the metadata - $requestItems = $this->buildRequestItemsFromOrder($order); + $requestItems = $this->buildRequestItemsFromOrder($order, $context); $request->setItems($requestItems); $this->appendRoundingItemFromMollieOrder($request, $mollieOrder); @@ -296,47 +296,20 @@ private function getOrderItem(OrderEntity $orderEntity, string $lineID): ?OrderL * @param OrderEntity $order * @return array */ - private function buildRequestItemsFromOrder(OrderEntity $order) + private function buildRequestItemsFromOrder(OrderEntity $order, Context $context) { - $refunds = $this->refundService->getRefunds($order); - - $refundCalculationHelper = new RefundCalculationHelper(); - /** @var array $refund */ - foreach ($refunds as $refund) { - if (!isset($refund['metadata'])) { - continue; - } - - $metadata = $refund['metadata']; - if (!isset($metadata['composition'])) { - continue; - } - - $composition = $metadata['composition']; - - foreach ($composition as $compositionItem) { - $refundCalculationHelper->addRefundItem( - new RefundItem( - $compositionItem['swLineId'], - $compositionItem['mollieLineId'], - $compositionItem['swReference'], - $compositionItem['quantity'], - $compositionItem['amount'] - ) - ); - } - } - $items = []; + $refundData = $this->builderData->buildRefundData($order, $context); + if ($order->getLineItems() instanceof OrderLineItemCollection) { /** @var OrderLineItemEntity $lineItem */ foreach ($order->getLineItems() as $lineItem) { - $orderItemAttributes = new OrderLineItemEntityAttributes($lineItem); - $orderLineId = $orderItemAttributes->getMollieOrderLineID(); - $alreadyRefundedQuantity = $refundCalculationHelper->getRefundQuantityForMollieId($orderLineId); - $alreadyRefundedAmount = $refundCalculationHelper->getRefundAmountForMollieId($orderLineId); + $orderLineItemAttributes = new OrderLineItemEntityAttributes($lineItem); + $alreadyRefundedQuantity = $refundData->getRefundedQuantity($orderLineItemAttributes->getMollieOrderLineID()); + $alreadyRefundedAmount = $refundData->getRefundedAmount($orderLineItemAttributes->getMollieOrderLineID()); + dump($alreadyRefundedQuantity,$alreadyRefundedAmount); $items[] = new RefundRequestItem( $lineItem->getId(), $lineItem->getTotalPrice() - $alreadyRefundedAmount, @@ -349,11 +322,11 @@ private function buildRequestItemsFromOrder(OrderEntity $order) if ($order->getDeliveries() instanceof OrderDeliveryCollection) { /** @var OrderDeliveryEntity $delivery */ foreach ($order->getDeliveries() as $delivery) { - $orderItemAttributes = new OrderLineItemEntityAttributes($lineItem); - $orderLineId = $orderItemAttributes->getMollieOrderLineID(); - $alreadyRefundedQuantity = $refundCalculationHelper->getRefundQuantityForMollieId($orderLineId); - $alreadyRefundedAmount = $refundCalculationHelper->getRefundAmountForMollieId($orderLineId); + $orderLineItemAttributes = new OrderDeliveryEntityAttributes($delivery); + $alreadyRefundedQuantity = $refundData->getRefundedQuantity($orderLineItemAttributes->getMollieOrderLineID()); + $alreadyRefundedAmount = $refundData->getRefundedAmount($orderLineItemAttributes->getMollieOrderLineID()); + dump($alreadyRefundedQuantity,$alreadyRefundedAmount); $items[] = new RefundRequestItem( $delivery->getId(), $delivery->getShippingCosts()->getTotalPrice() - $alreadyRefundedAmount, @@ -465,4 +438,32 @@ private function convertToRefundItems(RefundRequest $request, OrderEntity $order return $serviceItems; } + + + /** + * Get the orderLineId from both OrderDeliveryEntity and OrderLineItemEntity + * @param OrderDeliveryEntity|OrderLineItemEntity $lineItem + * @return string + */ + public function getOrderLineId($lineItem): string + { + $customFields = $lineItem->getCustomFields(); + + if (!isset($customFields)) { + return ""; + } + + if (!isset($customFields['mollie_payments'])) { + return ""; + } + + $molliePayments = $customFields['mollie_payments']; + + if (!isset($molliePayments['order_line_id'])) { + return ""; + } + + return $molliePayments['order_line_id']; + } + } diff --git a/src/Struct/OrderDeliveryEntity/OrderDeliveryEntityAttributes.php b/src/Struct/OrderDeliveryEntity/OrderDeliveryEntityAttributes.php new file mode 100644 index 000000000..71c5688bc --- /dev/null +++ b/src/Struct/OrderDeliveryEntity/OrderDeliveryEntityAttributes.php @@ -0,0 +1,19 @@ +deliveryEntity = $entity; + } +} diff --git a/src/Struct/OrderLineItemEntity/OrderLineItemEntityAttributes.php b/src/Struct/OrderLineItemEntity/OrderLineItemEntityAttributes.php index 69a7dafc0..d22a01272 100644 --- a/src/Struct/OrderLineItemEntity/OrderLineItemEntityAttributes.php +++ b/src/Struct/OrderLineItemEntity/OrderLineItemEntityAttributes.php @@ -2,18 +2,13 @@ namespace Kiener\MolliePayments\Struct\OrderLineItemEntity; +use Kiener\MolliePayments\Struct\OrderXEntityAttributes; use Kiener\MolliePayments\Struct\Voucher\VoucherType; use Shopware\Core\Checkout\Order\Aggregate\OrderLineItem\OrderLineItemEntity; +use Shopware\Core\Framework\DataAbstractionLayer\Entity; -class OrderLineItemEntityAttributes +class OrderLineItemEntityAttributes extends OrderXEntityAttributes { - - /** - * @var OrderLineItemEntity - */ - private $item; - - /** * @var string */ @@ -24,11 +19,6 @@ class OrderLineItemEntityAttributes */ private $subscriptionProduct; - /** - * @var string - */ - private $mollieOrderLineID; - /** * @var int */ @@ -44,21 +34,26 @@ class OrderLineItemEntityAttributes */ private $subscriptionRepetitionCount; + /** + * @var OrderLineItemEntity + */ + private $item; + /** - * @param OrderLineItemEntity $lineItem + * @param OrderLineItemEntity $entity */ - public function __construct(OrderLineItemEntity $lineItem) + public function __construct(OrderLineItemEntity $entity) { - $this->item = $lineItem; + parent::__construct($entity); + $this->item = $entity; + $this->voucherType = $this->getCustomFieldValue($entity, 'voucher_type'); - $this->voucherType = $this->getCustomFieldValue($lineItem, 'voucher_type'); - $this->mollieOrderLineID = $this->getCustomFieldValue($lineItem, 'order_line_id'); + $this->subscriptionProduct = (bool)$this->getCustomFieldValue($entity, 'subscription_enabled'); + $this->subscriptionInterval = (int)$this->getCustomFieldValue($entity, 'subscription_interval'); + $this->subscriptionIntervalUnit = (string)$this->getCustomFieldValue($entity, 'subscription_interval_unit'); + $this->subscriptionRepetitionCount = (int)$this->getCustomFieldValue($entity, 'subscription_repetition'); - $this->subscriptionProduct = (bool)$this->getCustomFieldValue($lineItem, 'subscription_enabled'); - $this->subscriptionInterval = (int)$this->getCustomFieldValue($lineItem, 'subscription_interval'); - $this->subscriptionIntervalUnit = (string)$this->getCustomFieldValue($lineItem, 'subscription_interval_unit'); - $this->subscriptionRepetitionCount = (int)$this->getCustomFieldValue($lineItem, 'subscription_repetition'); } /** @@ -80,14 +75,6 @@ public function getVoucherType() return $this->voucherType; } - /** - * @return string - */ - public function getMollieOrderLineID(): string - { - return $this->mollieOrderLineID; - } - /** * @return bool */ @@ -142,25 +129,18 @@ public function isPromotion(): bool return false; } - /** - * Somehow there are 2 custom fields? in payload and custom fields? - * ....mhm...lets test always both - * @param OrderLineItemEntity $lineItem - * @param string $keyName - * @return string - */ - private function getCustomFieldValue(OrderLineItemEntity $lineItem, string $keyName): string + protected function getCustomFieldValue(Entity $entity, string $keyName): string { $foundValue = ''; # --------------------------------------------------------------------------- - # search in payload + # first search in payload - if ($lineItem->getPayload() !== null) { + if ($entity instanceof OrderLineItemEntity && $entity->getPayload() !== null) { # check if we have customFields in our payload - if (array_key_exists('customFields', $lineItem->getPayload())) { + if (array_key_exists('customFields', $entity->getPayload())) { # load the custom fields - $customFields = $lineItem->getPayload()['customFields']; + $customFields = $entity->getPayload()['customFields']; if (is_array($customFields)) { # --------------------------------------------------------------------------- @@ -180,28 +160,8 @@ private function getCustomFieldValue(OrderLineItemEntity $lineItem, string $keyN } } - # --------------------------------------------------------------------------- - # search in custom fields - - if ($foundValue === '') { - # check if we have customFields - $customFields = $lineItem->getCustomFields(); - - if ($customFields !== null) { - # --------------------------------------------------------------------------- - # search in new structure - $fullKey = 'mollie_payments_product_' . $keyName; - $foundValue = (array_key_exists($fullKey, $customFields)) ? (string)$customFields[$fullKey] : ''; - - # old structure - # check if we have a mollie entry - if ($foundValue === '' && array_key_exists('mollie_payments', $customFields)) { - # load the mollie entry - $mollieData = $customFields['mollie_payments']; - # assign our value if we have it - $foundValue = (array_key_exists($keyName, $mollieData)) ? (string)$mollieData[$keyName] : ''; - } - } + if ($foundValue == '') { + $foundValue = parent::getCustomFieldValue($entity, $keyName); } return $foundValue; diff --git a/src/Struct/OrderXEntityAttributes.php b/src/Struct/OrderXEntityAttributes.php new file mode 100644 index 000000000..f6aab818c --- /dev/null +++ b/src/Struct/OrderXEntityAttributes.php @@ -0,0 +1,72 @@ +entity = $entity; + + $this->mollieOrderLineID = $this->getCustomFieldValue($entity, 'order_line_id'); + } + + /** + * @return string + */ + public function getMollieOrderLineID(): string + { + return $this->mollieOrderLineID; + } + + /** + * Somehow there are 2 custom fields? in payload and custom fields? + * ....mhm...lets test always both + * @param Entity $entity + * @param string $keyName + * @return string + */ + protected function getCustomFieldValue(Entity $entity, string $keyName): string + { + $foundValue = ''; + + # --------------------------------------------------------------------------- + # search in custom fields + + if (method_exists($entity, 'getCustomFields')) { + + # check if we have customFields + $customFields = $entity->getCustomFields(); + + if ($customFields !== null) { + # --------------------------------------------------------------------------- + # search in new structure + $fullKey = 'mollie_payments_product_' . $keyName; + $foundValue = (array_key_exists($fullKey, $customFields)) ? (string)$customFields[$fullKey] : ''; + + # old structure + # check if we have a mollie entry + if ($foundValue === '' && array_key_exists('mollie_payments', $customFields)) { + # load the mollie entry + $mollieData = $customFields['mollie_payments']; + # assign our value if we have it + $foundValue = (array_key_exists($keyName, $mollieData)) ? (string)$mollieData[$keyName] : ''; + } + } + } + + return $foundValue; + } +} From 58b5eeead67e8fa5b555929b6c1855eb9429324b Mon Sep 17 00:00:00 2001 From: Smemoict Date: Thu, 2 Mar 2023 09:58:39 +0100 Subject: [PATCH 11/11] cha: stan and dump removal --- src/Components/RefundManager/RefundData/RefundData.php | 4 ++-- src/Components/RefundManager/RefundManager.php | 7 +++---- .../OrderDeliveryEntity/OrderDeliveryEntityAttributes.php | 3 --- .../OrderLineItemEntity/OrderLineItemEntityAttributes.php | 3 +-- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/Components/RefundManager/RefundData/RefundData.php b/src/Components/RefundManager/RefundData/RefundData.php index 3b7b3b9b1..6291d1d6c 100644 --- a/src/Components/RefundManager/RefundData/RefundData.php +++ b/src/Components/RefundManager/RefundData/RefundData.php @@ -199,6 +199,7 @@ public function getRefundedAmount(string $mollieId):float $totalAmount = 0; ## The amount is being calculated via the refunds because it might have been a custom amount. + /** @var array $refund */ foreach ($this->refunds as $refund) { if (!isset($refund['metadata'])) { continue; @@ -212,10 +213,9 @@ public function getRefundedAmount(string $mollieId):float $composition = $metadata['composition']; foreach ($composition as $compositionItem) { - if ($compositionItem['mollieLineId']===$mollieId){ + if ($compositionItem['mollieLineId']===$mollieId) { $totalAmount+=$compositionItem['amount']; } - } } return $totalAmount; diff --git a/src/Components/RefundManager/RefundManager.php b/src/Components/RefundManager/RefundManager.php index ff6f234f9..92912425b 100644 --- a/src/Components/RefundManager/RefundManager.php +++ b/src/Components/RefundManager/RefundManager.php @@ -114,8 +114,8 @@ public function getData(OrderEntity $order, Context $context): RefundData * @param OrderEntity $order * @param RefundRequest $request * @param Context $context - * @return Refund * @throws \Mollie\Api\Exceptions\ApiException + * @return Refund */ public function refund(OrderEntity $order, RefundRequest $request, Context $context): Refund { @@ -309,7 +309,7 @@ private function buildRequestItemsFromOrder(OrderEntity $order, Context $context $alreadyRefundedQuantity = $refundData->getRefundedQuantity($orderLineItemAttributes->getMollieOrderLineID()); $alreadyRefundedAmount = $refundData->getRefundedAmount($orderLineItemAttributes->getMollieOrderLineID()); - dump($alreadyRefundedQuantity,$alreadyRefundedAmount); + $items[] = new RefundRequestItem( $lineItem->getId(), $lineItem->getTotalPrice() - $alreadyRefundedAmount, @@ -326,7 +326,7 @@ private function buildRequestItemsFromOrder(OrderEntity $order, Context $context $alreadyRefundedQuantity = $refundData->getRefundedQuantity($orderLineItemAttributes->getMollieOrderLineID()); $alreadyRefundedAmount = $refundData->getRefundedAmount($orderLineItemAttributes->getMollieOrderLineID()); - dump($alreadyRefundedQuantity,$alreadyRefundedAmount); + $items[] = new RefundRequestItem( $delivery->getId(), $delivery->getShippingCosts()->getTotalPrice() - $alreadyRefundedAmount, @@ -465,5 +465,4 @@ public function getOrderLineId($lineItem): string return $molliePayments['order_line_id']; } - } diff --git a/src/Struct/OrderDeliveryEntity/OrderDeliveryEntityAttributes.php b/src/Struct/OrderDeliveryEntity/OrderDeliveryEntityAttributes.php index 71c5688bc..1c666861f 100644 --- a/src/Struct/OrderDeliveryEntity/OrderDeliveryEntityAttributes.php +++ b/src/Struct/OrderDeliveryEntity/OrderDeliveryEntityAttributes.php @@ -9,11 +9,8 @@ class OrderDeliveryEntityAttributes extends OrderXEntityAttributes { - private OrderDeliveryEntity $deliveryEntity; - public function __construct(OrderDeliveryEntity $entity) { parent::__construct($entity); - $this->deliveryEntity = $entity; } } diff --git a/src/Struct/OrderLineItemEntity/OrderLineItemEntityAttributes.php b/src/Struct/OrderLineItemEntity/OrderLineItemEntityAttributes.php index d22a01272..2f7ed041c 100644 --- a/src/Struct/OrderLineItemEntity/OrderLineItemEntityAttributes.php +++ b/src/Struct/OrderLineItemEntity/OrderLineItemEntityAttributes.php @@ -53,7 +53,6 @@ public function __construct(OrderLineItemEntity $entity) $this->subscriptionInterval = (int)$this->getCustomFieldValue($entity, 'subscription_interval'); $this->subscriptionIntervalUnit = (string)$this->getCustomFieldValue($entity, 'subscription_interval_unit'); $this->subscriptionRepetitionCount = (int)$this->getCustomFieldValue($entity, 'subscription_repetition'); - } /** @@ -160,7 +159,7 @@ protected function getCustomFieldValue(Entity $entity, string $keyName): string } } - if ($foundValue == '') { + if ($foundValue === '') { $foundValue = parent::getCustomFieldValue($entity, $keyName); }