Skip to content

Commit

Permalink
PISHPS-306: cypress fix
Browse files Browse the repository at this point in the history
  • Loading branch information
m-muxfeld-diw committed Oct 1, 2024
1 parent 0d01ac0 commit 96626b9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/Controller/Api/Order/RefundControllerBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),]);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Service/Refund/Exceptions/CreditNoteException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Service/Refund/RefundCreditNoteService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']]);
Expand Down

0 comments on commit 96626b9

Please sign in to comment.