diff --git a/src/Controller/Api/Order/RefundControllerBase.php b/src/Controller/Api/Order/RefundControllerBase.php index c8a8c430b..7939da056 100644 --- a/src/Controller/Api/Order/RefundControllerBase.php +++ b/src/Controller/Api/Order/RefundControllerBase.php @@ -196,8 +196,13 @@ public function refundOrderID(RequestDataBag $data, Context $context): JsonRespo try { $this->creditNoteService->addCreditNoteToOrder($orderId, $refundId, $items, $context); } catch (CreditNoteException $exception) { - $this->logger->error($exception->getMessage(), ['code' => $exception->getCode(),]); - return $this->buildErrorResponse($exception->getMessage()); + if ($exception->getCode() === CreditNoteException::CODE_ADDING_CREDIT_NOTE_LINE_ITEMS) { + $this->logger->error($exception->getMessage(), ['code' => $exception->getCode(),]); + return $this->buildErrorResponse($exception->getMessage()); + } + if ($exception->getCode() === CreditNoteException::CODE_WARNING_LEVEL) { + $this->logger->warning($exception->getMessage(), ['code' => $exception->getCode(),]); + } } } diff --git a/src/Service/Refund/Exceptions/CreditNoteException.php b/src/Service/Refund/Exceptions/CreditNoteException.php index a53fe1546..d3d2c5a63 100644 --- a/src/Service/Refund/Exceptions/CreditNoteException.php +++ b/src/Service/Refund/Exceptions/CreditNoteException.php @@ -14,9 +14,9 @@ final private function __construct(string $message, int $code) parent::__construct($message, $code); } - public static function forAddingLineItems(string $message): CreditNoteException + public static function forAddingLineItems(string $message, int $code = self::CODE_ADDING_CREDIT_NOTE_LINE_ITEMS): CreditNoteException { - return new self($message, self::CODE_ADDING_CREDIT_NOTE_LINE_ITEMS); + return new self($message, $code); } public static function forRemovingLineItems(string $message, int $code = self::CODE_REMOVING_CREDIT_NOTE_LINE_ITEMS): CreditNoteException diff --git a/src/Service/Refund/RefundCreditNoteService.php b/src/Service/Refund/RefundCreditNoteService.php index 3d4db1213..b269e11a1 100644 --- a/src/Service/Refund/RefundCreditNoteService.php +++ b/src/Service/Refund/RefundCreditNoteService.php @@ -126,7 +126,7 @@ public function addCreditNoteToOrder(string $orderId, string $refundId, array $l } if (empty($data['lineItems'])) { - throw CreditNoteException::forAddingLineItems(sprintf('No credit note line items found for order. OrderID: %s RefundID: %s', $orderId, $refundId)); + throw CreditNoteException::forAddingLineItems(sprintf('No credit note line items found for order. OrderID: %s RefundID: %s', $orderId, $refundId), CreditNoteException::CODE_WARNING_LEVEL); } $this->logger->debug('Adding credit note to order', ['orderId' => $orderId, 'refundId' => $refundId, 'lineItems' => $data['lineItems']]);