From 0599d68adb849ecef64959d669b9e019cb7c4d66 Mon Sep 17 00:00:00 2001 From: inpsyde-maticluznar Date: Fri, 25 Aug 2023 09:27:44 +0200 Subject: [PATCH 1/3] Implement basic refund functionality. Still needs refactoring. --- src/Payment/MollieOrderService.php | 120 ++++++++++++++++++++++------- 1 file changed, 93 insertions(+), 27 deletions(-) diff --git a/src/Payment/MollieOrderService.php b/src/Payment/MollieOrderService.php index 898c0686..cb8b5532 100644 --- a/src/Payment/MollieOrderService.php +++ b/src/Payment/MollieOrderService.php @@ -4,6 +4,7 @@ namespace Mollie\WooCommerce\Payment; +use Exception; use Mollie\Api\Exceptions\ApiException; use Mollie\Api\Resources\Order; use Mollie\Api\Resources\Payment; @@ -14,6 +15,7 @@ use Mollie\WooCommerce\Shared\SharedDataDictionary; use Psr\Log\LoggerInterface as Logger; use Psr\Log\LogLevel; +use WC_Abstract_Order; use WC_Order; class MollieOrderService @@ -171,9 +173,9 @@ public function onWebhookAction() $payment->id . ($payment->mode === 'test' ? (' - ' . __('test mode', 'mollie-payments-for-woocommerce')) : '') )); } - // Status 200 } + /** * @param WC_Order $order * @@ -234,8 +236,9 @@ protected function isOrderPaidByOtherGateway(WC_Order $order) } /** - * @param WC_Order $order + * @param WC_Order $order * @param Payment|Order $payment + * @throws Exception */ protected function processRefunds(WC_Order $order, $payment) { @@ -258,7 +261,11 @@ protected function processRefunds(WC_Order $order, $payment) return; } - $refundIds = $this->findRefundIds($payment); + $refunds = $this->findRefunds($payment); + $refundIds = array_reduce($refunds, static function ($ids, $refund) { + $ids[] = $refund->id; + return $ids; + }, []); // Check for new refund $this->logger->debug( __METHOD__ . " All refund IDs for {$logId}: " . json_encode( @@ -281,15 +288,20 @@ protected function processRefunds(WC_Order $order, $payment) return; } // There are new refunds. - $refundsToProcess = array_diff($refundIds, $processedRefundIds); + $refundIdsToProcess = array_diff($refundIds, $processedRefundIds); + $refundsToProcess = array_filter($refunds, static function ($refund) use ($refundIdsToProcess) { + return in_array($refund->id, $refundIdsToProcess); + }); + $this->logger->debug( __METHOD__ . " Refunds that need to be processed for {$logId}: " - . json_encode($refundsToProcess) + . json_encode($refundIdsToProcess) ); $order = wc_get_order($orderId); - $this->notifyProcessedRefunds($refundsToProcess, $logId, $order, $processedRefundIds); + $woocommerceProcessedRefunds = $this->generateWoocommerceRefunds($refundsToProcess, $order); + $this->notifyProcessedRefunds($refundIdsToProcess, $woocommerceProcessedRefunds, $logId, $order, $processedRefundIds); $order->save(); $this->processUpdateStateRefund($order, $payment); @@ -305,7 +317,7 @@ protected function processRefunds(WC_Order $order, $payment) } /** - * @param WC_Order $order + * @param WC_Order $order * @param Payment|Order $payment */ protected function processChargebacks(WC_Order $order, $payment) @@ -419,7 +431,10 @@ protected function processChargebacks(WC_Order $order, $payment) $newOrderStatus = apply_filters($this->pluginId . '_order_status_on_hold', $newOrderStatus); // Overwrite gateway-wide - $newOrderStatus = apply_filters($this->pluginId . "_order_status_on_hold_{$this->gateway->id}", $newOrderStatus); + $newOrderStatus = apply_filters( + $this->pluginId . "_order_status_on_hold_{$this->gateway->id}", + $newOrderStatus + ); $paymentMethodTitle = $this->getPaymentMethodTitle($payment); @@ -539,12 +554,12 @@ protected function hasLineRefund($payment): bool * @param $payment * @return array */ - protected function findRefundIds($payment): array + protected function findRefunds($payment): array { if (empty($payment->_links->refunds)) { - return $this->findRefundIdsByLine($payment); + return $this->findRefundsByLine($payment); } - return $this->findRefundIdsByLinks($payment); + return $this->findRefundsByLinks($payment); } /** @@ -553,11 +568,11 @@ protected function findRefundIds($payment): array * @param $payment * @return array */ - protected function findRefundIdsByLine($payment): array + protected function findRefundsByLine($payment): array { - return array_map(static function ($refund) { - return $refund->id; - }, $payment->_embedded->refunds); + return array_filter($payment->_embedded->refunds, function($refund){ + return $refund->status === "refunded"; + }); } /** @@ -571,7 +586,7 @@ protected function calculateRefundByLine($payment): float $refundAmount = 0.0; $refunds = $payment->_embedded->refunds; foreach ($refunds as $refund) { - $refundAmount += (float) $refund->amount->value; + $refundAmount += (float)$refund->amount->value; } return $refundAmount; } @@ -582,14 +597,15 @@ protected function calculateRefundByLine($payment): float * @param $payment * @return array */ - protected function findRefundIdsByLinks($payment): array + protected function findRefundsByLinks($payment): array { - $refundIds = []; + $refundsList = []; try { // Get all refunds for this payment $refunds = $payment->refunds(); foreach ($refunds as $refund) { - $refundIds[] = $refund->id; + if($refund->status !== "refunded") continue; + $refundsList[] = $refund; } } catch (\Mollie\Api\Exceptions\ApiException $e) { $this->logger->debug( @@ -598,7 +614,7 @@ protected function findRefundIdsByLinks($payment): array . ' (' . get_class($e) . ')' ); } - return $refundIds; + return $refundsList; } /** @@ -637,7 +653,7 @@ protected function isPartialRefund($payment) } /** - * @param WC_Order $order + * @param WC_Order $order * @param Payment|Order $payment */ protected function processUpdateStateRefund(WC_Order $order, $payment) @@ -653,7 +669,7 @@ protected function processUpdateStateRefund(WC_Order $order, $payment) } /** - * @param WC_Order $order + * @param WC_Order $order * @param Payment|Order $payment * @param $newOrderStatus * @param $refundType @@ -734,6 +750,7 @@ protected function getPaymentMethodTitle($payment) } return $payment_method_title; } + /** * @param \WC_Order $order * @param string $new_status @@ -747,7 +764,7 @@ public function updateOrderStatus(\WC_Order $order, $new_status, $note = '', $re switch ($new_status) { case SharedDataDictionary::STATUS_ON_HOLD: if ($restore_stock === true) { - if (! $order->get_meta('_order_stock_reduced', true)) { + if (!$order->get_meta('_order_stock_reduced', true)) { // Reduce order stock wc_reduce_stock_levels($order->get_id()); @@ -772,17 +789,18 @@ public function updateOrderStatus(\WC_Order $order, $new_status, $note = '', $re } /** - * @param WC_Order $order + * @param WC_Abstract_Order $order * @param string $logId - * @return array|mixed|string|void + * @return array */ - protected function getProcessedRefundIds(WC_Order $order, string $logId) + protected function getProcessedRefundIds(WC_Abstract_Order $order, string $logId): array { if ($order->meta_exists('_mollie_processed_refund_ids')) { $processedRefundIds = $order->get_meta( '_mollie_processed_refund_ids', true ); + $processedRefundIds = is_array($processedRefundIds) ? $processedRefundIds : []; } else { $processedRefundIds = []; } @@ -796,12 +814,60 @@ protected function getProcessedRefundIds(WC_Order $order, string $logId) /** * @param array $refundsToProcess + * @param mixed $order + */ + protected function generateWoocommerceRefunds(array $refundsToProcess, $order) + { + if (count($refundsToProcess) === 0) { + return []; + } + + $woocommerceRefunds = []; + + foreach ($refundsToProcess as $refund) { + $refundItems = $refund->lines; + $wcRefund = [ + 'order_id' => $order->get_id(), + 'amount' => $refund->amount->value, + ]; + + + if (is_array($refundItems) && count($refundItems) > 0) { + $wcRefundItems = []; + foreach ($refundItems as $refundItem) { + $wcRefundItems[$refundItem->metadata->order_item_id] = [ + 'qty' => $refundItem->quantity, + 'refund_total' => $refundItem->totalAmount->value, + 'refund_tax' => $refundItem->vatAmount->value, + ]; + } + $wcRefund['restock_items'] = true; + $wcRefund['line_items'] = $wcRefundItems; + } + + + + try { + $woocommerceRefunds[] = wc_create_refund($wcRefund); + } catch (Exception $error) { + $this->logger->debug( + __METHOD__ . " Can't create a refund for order " . $order->get_id() . " for refund ID: " . $refund->id . "." + ); + } + } + + return $woocommerceRefunds; + } + + /** + * @param array $refundsToProcess + * @param array $woocommerceRefunds * @param string $logId * @param $order * @param $processedRefundIds * @return mixed */ - protected function notifyProcessedRefunds(array $refundsToProcess, string $logId, $order, $processedRefundIds) + protected function notifyProcessedRefunds(array $refundsToProcess, array $woocommerceRefunds,string $logId, $order, $processedRefundIds) { foreach ($refundsToProcess as $refundToProcess) { $this->logger->debug( From 86dc4e1ce60235317ce188dc1c0be06a8ca41aca Mon Sep 17 00:00:00 2001 From: inpsyde-maticluznar Date: Mon, 28 Aug 2023 12:37:16 +0200 Subject: [PATCH 2/3] Implement refund functionality, including partial refunds. --- src/Payment/MollieOrderService.php | 253 ++++++++++++++++++++--------- 1 file changed, 178 insertions(+), 75 deletions(-) diff --git a/src/Payment/MollieOrderService.php b/src/Payment/MollieOrderService.php index cb8b5532..a424eec1 100644 --- a/src/Payment/MollieOrderService.php +++ b/src/Payment/MollieOrderService.php @@ -20,6 +20,10 @@ class MollieOrderService { + const REFUND_STATUS_REFUNDED = 'refunded'; + const META_KEY_PROCESSED_ORDERS = '_mollie_processed_refund_ids'; + const META_KEY_PROCESSED_AND_REFUNDED_ORDERS = '_mollie_processed_and_refunded_refund_ids'; + protected $gateway; /** * @var HttpResponse @@ -131,15 +135,20 @@ public function onWebhookAction() if ($order_id != $payment->metadata->order_id) { $this->httpResponse->setHttpResponseCode(400); - $this->logger->debug(__METHOD__ . ": Order ID does not match order_id in payment metadata. Payment ID {$payment->id}, order ID $order_id"); + $this->logger->debug( + __METHOD__ . ": Order ID does not match order_id in payment metadata. Payment ID {$payment->id}, order ID $order_id" + ); return; } // Log a message that webhook was called, doesn't mean the payment is actually processed - $this->logger->debug($this->gateway->id . ": Mollie payment object {$payment->id} (" . $payment->mode . ") webhook call for order {$order->get_id()}.", [true]); + $this->logger->debug( + $this->gateway->id . ": Mollie payment object {$payment->id} (" . $payment->mode . ") webhook call for order {$order->get_id()}.", + [true] + ); // Order does not need a payment - if (! $this->orderNeedsPayment($order)) { + if (!$this->orderNeedsPayment($order)) { // TODO David: move to payment object? // Add a debug message that order was already paid for $this->gateway->handlePaidOrderWebhook($order, $payment); @@ -165,13 +174,18 @@ public function onWebhookAction() if (method_exists($payment_object, $method_name)) { $payment_object->{$method_name}($order, $payment, $payment_method_title); } else { - $order->add_order_note(sprintf( - /* translators: Placeholder 1: payment method title, placeholder 2: payment status, placeholder 3: payment ID */ - __('%1$s payment %2$s (%3$s), not processed.', 'mollie-payments-for-woocommerce'), - $this->gateway->method_title, - $payment->status, - $payment->id . ($payment->mode === 'test' ? (' - ' . __('test mode', 'mollie-payments-for-woocommerce')) : '') - )); + $order->add_order_note( + sprintf( + /* translators: Placeholder 1: payment method title, placeholder 2: payment status, placeholder 3: payment ID */ + __('%1$s payment %2$s (%3$s), not processed.', 'mollie-payments-for-woocommerce'), + $this->gateway->method_title, + $payment->status, + $payment->id . ($payment->mode === 'test' ? (' - ' . __( + 'test mode', + 'mollie-payments-for-woocommerce' + )) : '') + ) + ); } // Status 200 } @@ -187,20 +201,29 @@ public function orderNeedsPayment(WC_Order $order) // Check whether the order is processed and paid via another gateway if ($this->isOrderPaidByOtherGateway($order)) { - $this->logger->debug(__METHOD__ . ' ' . $this->gateway->id . ': Order ' . $order_id . ' orderNeedsPayment check: no, previously processed by other (non-Mollie) gateway.', [true]); + $this->logger->debug( + __METHOD__ . ' ' . $this->gateway->id . ': Order ' . $order_id . ' orderNeedsPayment check: no, previously processed by other (non-Mollie) gateway.', + [true] + ); return false; } // Check whether the order is processed and paid via Mollie - if (! $this->isOrderPaidAndProcessed($order)) { - $this->logger->debug(__METHOD__ . ' ' . $this->gateway->id . ': Order ' . $order_id . ' orderNeedsPayment check: yes, order not previously processed by Mollie gateway.', [true]); + if (!$this->isOrderPaidAndProcessed($order)) { + $this->logger->debug( + __METHOD__ . ' ' . $this->gateway->id . ': Order ' . $order_id . ' orderNeedsPayment check: yes, order not previously processed by Mollie gateway.', + [true] + ); return true; } if ($order->needs_payment()) { - $this->logger->debug(__METHOD__ . ' ' . $this->gateway->id . ': Order ' . $order_id . ' orderNeedsPayment check: yes, WooCommerce thinks order needs payment.', [true]); + $this->logger->debug( + __METHOD__ . ' ' . $this->gateway->id . ': Order ' . $order_id . ' orderNeedsPayment check: yes, WooCommerce thinks order needs payment.', + [true] + ); return true; } @@ -243,65 +266,77 @@ protected function isOrderPaidByOtherGateway(WC_Order $order) protected function processRefunds(WC_Order $order, $payment) { $orderId = $order->get_id(); - - // Debug log ID (order id/payment id) + $notifyNewRefundsIds = []; + $notifyRefundedRefundsIds = []; $logId = "order {$orderId} / payment{$payment->id}"; - - // Add message to log $this->logger->debug(__METHOD__ . " called for {$logId}"); - $hasLineRefund = $this->hasLineRefund($payment); // Make sure there are refunds to process at all - if (empty($payment->_links->refunds) && !$hasLineRefund) { + if (!$this->hasRefund($payment)) { $this->logger->debug( __METHOD__ . ": No refunds to process for {$logId}", [true] ); - return; } - $refunds = $this->findRefunds($payment); - $refundIds = array_reduce($refunds, static function ($ids, $refund) { + $mollieRefunds = $this->findMollieRefunds($payment); + $mollieRefundIds = array_reduce($mollieRefunds, static function ($ids, $refund) { $ids[] = $refund->id; return $ids; }, []); - // Check for new refund + $this->logger->debug( __METHOD__ . " All refund IDs for {$logId}: " . json_encode( - $refundIds + $mollieRefundIds ) ); - // Get possibly already processed refunds - $processedRefundIds = $this->getProcessedRefundIds($order, $logId); + $notedRefundIds = $this->getProcessedRefundIds($order, $logId); + $notedAndWCProcessedRefunds = $this->getWCRefundIds($order, $logId); - // Order the refund arrays by value (refund ID) - asort($refundIds); - asort($processedRefundIds); + foreach ($mollieRefunds as $mollieRefund) { + if (!in_array($mollieRefund->id, $notedRefundIds)) { + $notifyNewRefundsIds[] = $mollieRefund->id; + } - // Check if no new refunds need processing return - if ($refundIds === $processedRefundIds) { + if ($mollieRefund->status === self::REFUND_STATUS_REFUNDED && !in_array($mollieRefund->id, $notedAndWCProcessedRefunds)) { + $notifyRefundedRefundsIds[] = $mollieRefund->id; + } + } + + /** Notification - refund exists in Mollie, but it is not processed in Woocommerce yet */ + if (count($notifyNewRefundsIds) > 0) { $this->logger->debug( - __METHOD__ . " No new refunds, stop processing for {$logId}" + __METHOD__ + . " Refunds that need to be processed for {$logId}: " + . json_encode($notifyNewRefundsIds) + ); + $this->notifyNewRefunds($notifyNewRefundsIds, $logId, $order, $notedRefundIds); + } else { + $this->logger->debug( + __METHOD__ . " No new refunds." ); - return; } - // There are new refunds. - $refundIdsToProcess = array_diff($refundIds, $processedRefundIds); - $refundsToProcess = array_filter($refunds, static function ($refund) use ($refundIdsToProcess) { - return in_array($refund->id, $refundIdsToProcess); - }); - $this->logger->debug( - __METHOD__ - . " Refunds that need to be processed for {$logId}: " - . json_encode($refundIdsToProcess) - ); - $order = wc_get_order($orderId); + /** Notification & Woocommerce refund - refund exists, and it is processed in Mollie, so we can create a refund in the Woocommerce */ + if (count($notifyRefundedRefundsIds)) { + $this->logger->debug( + __METHOD__ + . " Refunds that need to be processed and refunded for {$logId}: " + . json_encode($notifyRefundedRefundsIds) + ); + + $notifyRefundedRefunds = array_filter($mollieRefunds, static function ($mollieRefund) use ($notifyRefundedRefundsIds) { + return in_array($mollieRefund->id, $notifyRefundedRefundsIds); + }); - $woocommerceProcessedRefunds = $this->generateWoocommerceRefunds($refundsToProcess, $order); - $this->notifyProcessedRefunds($refundIdsToProcess, $woocommerceProcessedRefunds, $logId, $order, $processedRefundIds); + $this->notifyRefundedRefundsAndCreateWCRefund($notifyRefundedRefunds, $logId, $order, $notedAndWCProcessedRefunds); + } else { + $this->logger->debug( + __METHOD__ . " No new processed refunds." + ); + } $order->save(); $this->processUpdateStateRefund($order, $payment); @@ -529,7 +564,7 @@ class_exists('WC_Subscriptions') ); return; - } catch (\Mollie\Api\Exceptions\ApiException $e) { + } catch (ApiException $e) { $this->logger->debug( __FUNCTION__ . ": Could not load chargebacks for $payment->id: " . $e->getMessage() . ' (' . get_class($e) . ')' @@ -540,21 +575,24 @@ class_exists('WC_Subscriptions') /** * Check if there is a refund inside an order line * - * @param $payment + * @param Order | Payment $payment * @return bool */ - protected function hasLineRefund($payment): bool + protected function hasRefund($payment): bool { - return !empty($payment->_embedded->refunds); + $hasEmbeddedRefund = !empty($payment->_embedded->refunds); + $hasLinkRefunds = !empty($payment->_links->refunds); + + return $hasEmbeddedRefund || $hasLinkRefunds; } /** * Find the Ids of the refunds * - * @param $payment + * @param Order | Payment $payment * @return array */ - protected function findRefunds($payment): array + protected function findMollieRefunds($payment): array { if (empty($payment->_links->refunds)) { return $this->findRefundsByLine($payment); @@ -570,8 +608,8 @@ protected function findRefunds($payment): array */ protected function findRefundsByLine($payment): array { - return array_filter($payment->_embedded->refunds, function($refund){ - return $refund->status === "refunded"; + return array_filter($payment->_embedded->refunds, static function ($refund) { + return $refund; }); } @@ -594,27 +632,24 @@ protected function calculateRefundByLine($payment): float /** * Check if there is a refund inside an order line * - * @param $payment + * @param Order | Payment $payment * @return array */ protected function findRefundsByLinks($payment): array { - $refundsList = []; + $activeRefunds = []; try { - // Get all refunds for this payment - $refunds = $payment->refunds(); - foreach ($refunds as $refund) { - if($refund->status !== "refunded") continue; - $refundsList[] = $refund; + foreach ($payment->refunds() as $refund) { + $activeRefunds[] = $refund; } - } catch (\Mollie\Api\Exceptions\ApiException $e) { + } catch (ApiException $e) { $this->logger->debug( __FUNCTION__ . " : Could not load refunds for {$payment->id}: {$e->getMessage()}" . ' (' . get_class($e) . ')' ); } - return $refundsList; + return $activeRefunds; } /** @@ -795,9 +830,9 @@ public function updateOrderStatus(\WC_Order $order, $new_status, $note = '', $re */ protected function getProcessedRefundIds(WC_Abstract_Order $order, string $logId): array { - if ($order->meta_exists('_mollie_processed_refund_ids')) { + if ($order->meta_exists(self::META_KEY_PROCESSED_ORDERS)) { $processedRefundIds = $order->get_meta( - '_mollie_processed_refund_ids', + self::META_KEY_PROCESSED_ORDERS, true ); $processedRefundIds = is_array($processedRefundIds) ? $processedRefundIds : []; @@ -812,9 +847,29 @@ protected function getProcessedRefundIds(WC_Abstract_Order $order, string $logId return $processedRefundIds; } + protected function getWCRefundIds(WC_Abstract_Order $order, string $logId): array + { + if ($order->meta_exists(self::META_KEY_PROCESSED_AND_REFUNDED_ORDERS)) { + $wcRefundIds = $order->get_meta( + self::META_KEY_PROCESSED_AND_REFUNDED_ORDERS, + true + ); + $wcRefundIds = is_array($wcRefundIds) ? $wcRefundIds : []; + } else { + $wcRefundIds = []; + } + + $this->logger->debug( + __METHOD__ . " Already created WC refunds for {$logId}: " + . json_encode($wcRefundIds) + ); + return $wcRefundIds; + } + /** * @param array $refundsToProcess * @param mixed $order + * @return array */ protected function generateWoocommerceRefunds(array $refundsToProcess, $order) { @@ -831,7 +886,6 @@ protected function generateWoocommerceRefunds(array $refundsToProcess, $order) 'amount' => $refund->amount->value, ]; - if (is_array($refundItems) && count($refundItems) > 0) { $wcRefundItems = []; foreach ($refundItems as $refundItem) { @@ -845,13 +899,12 @@ protected function generateWoocommerceRefunds(array $refundsToProcess, $order) $wcRefund['line_items'] = $wcRefundItems; } - - try { $woocommerceRefunds[] = wc_create_refund($wcRefund); } catch (Exception $error) { $this->logger->debug( - __METHOD__ . " Can't create a refund for order " . $order->get_id() . " for refund ID: " . $refund->id . "." + __METHOD__ . " Can't create a refund for order " . $order->get_id( + ) . " for refund ID: " . $refund->id . "." ); } } @@ -861,14 +914,18 @@ protected function generateWoocommerceRefunds(array $refundsToProcess, $order) /** * @param array $refundsToProcess - * @param array $woocommerceRefunds * @param string $logId * @param $order - * @param $processedRefundIds + * @param array $processedRefundIds * @return mixed */ - protected function notifyProcessedRefunds(array $refundsToProcess, array $woocommerceRefunds,string $logId, $order, $processedRefundIds) - { + protected function notifyNewRefunds( + array $refundsToProcess, + string $logId, + $order, + array $processedRefundIds + ) { + foreach ($refundsToProcess as $refundToProcess) { $this->logger->debug( __METHOD__ @@ -889,7 +946,7 @@ protected function notifyProcessedRefunds(array $refundsToProcess, array $woocom } $order->update_meta_data( - '_mollie_processed_refund_ids', + self::META_KEY_PROCESSED_ORDERS, $processedRefundIds ); $this->logger->debug( @@ -899,6 +956,52 @@ protected function notifyProcessedRefunds(array $refundsToProcess, array $woocom return $processedRefundIds; } + /** + * @param array $refundsToProcess + * @param string $logId + * @param $order + * @param array $processedRefundIds + * @return mixed + */ + protected function notifyRefundedRefundsAndCreateWCRefund( + array $refundsToProcess, + string $logId, + $order, + array $processedRefundIds + ) { + + foreach ($refundsToProcess as $refundToProcess) { + $this->logger->debug( + __METHOD__ + . " New refund {$refundToProcess->id} processed in Mollie Dashboard for {$logId} Order note added, but order not updated." + ); + /* translators: Placeholder 1: Refund to process id. */ + $order->add_order_note( + sprintf( + __( + 'Refund %s applied to Woocommerce order.', + 'mollie-payments-for-woocommerce' + ), + $refundToProcess->id + ) + ); + + $processedRefundIds[] = $refundToProcess->id; + } + + $this->generateWoocommerceRefunds($refundsToProcess, $order); + + $order->update_meta_data( + self::META_KEY_PROCESSED_AND_REFUNDED_ORDERS, + $processedRefundIds + ); + $this->logger->debug( + __METHOD__ . " Updated all processed and applied refunds for {$logId}: " + . json_encode($processedRefundIds) + ); + return $processedRefundIds; + } + protected function isOrderButtonPayment(WC_Order $order): bool { return $order->get_meta('_mollie_payment_method_button') === 'PayPalButton'; From bf965f6ab4b067292625be16a86bace446e6f5d6 Mon Sep 17 00:00:00 2001 From: inpsyde-maticluznar Date: Tue, 29 Aug 2023 06:08:21 +0200 Subject: [PATCH 3/3] Removed filter from findRefundsByLine method --- src/Payment/MollieOrderService.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Payment/MollieOrderService.php b/src/Payment/MollieOrderService.php index a424eec1..819cbdb4 100644 --- a/src/Payment/MollieOrderService.php +++ b/src/Payment/MollieOrderService.php @@ -608,9 +608,7 @@ protected function findMollieRefunds($payment): array */ protected function findRefundsByLine($payment): array { - return array_filter($payment->_embedded->refunds, static function ($refund) { - return $refund; - }); + return $payment->_embedded->refunds; } /**