From a7485fc9b17e56cd09332a7f2d10468745dee3be Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 22 Sep 2023 09:23:42 +0200 Subject: [PATCH] NTR: fix broken refund composition after metadata change (#623) --- .../RefundManager/Builder/RefundDataBuilder.php | 8 +++++++- src/Hydrator/RefundHydrator.php | 6 +++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Components/RefundManager/Builder/RefundDataBuilder.php b/src/Components/RefundManager/Builder/RefundDataBuilder.php index 44107df98..253d6695f 100644 --- a/src/Components/RefundManager/Builder/RefundDataBuilder.php +++ b/src/Components/RefundManager/Builder/RefundDataBuilder.php @@ -275,7 +275,13 @@ private function getRefundedQuantity(string $mollieLineItemId, \Mollie\Api\Resou continue; } - $metadata = RefundMetadata::fromArray($refund['metadata']); + $meta = $refund['metadata']; + + if (is_string($meta)) { + $meta = json_decode($meta, true); + } + + $metadata = RefundMetadata::fromArray($meta); # if we do have a FULL item refund then # we must NOT substract our item again. diff --git a/src/Hydrator/RefundHydrator.php b/src/Hydrator/RefundHydrator.php index a16ff4b6d..1c1088887 100644 --- a/src/Hydrator/RefundHydrator.php +++ b/src/Hydrator/RefundHydrator.php @@ -33,10 +33,10 @@ public function hydrate(Refund $refund, OrderEntity $order): array ]; } - $metaData = ''; + $metaData = []; if (property_exists($refund, 'metadata')) { - $metaData = (string)json_encode($refund->metadata); + $metaData = $refund->metadata; } $internalDescription = null; @@ -70,7 +70,7 @@ public function hydrate(Refund $refund, OrderEntity $order): array 'isProcessing' => $refund->isProcessing(), 'isQueued' => $refund->isQueued(), 'isTransferred' => $refund->isTransferred(), - 'metadata' => json_decode($metaData, true), + 'metadata' => $metaData, ]; } }