Skip to content

Commit

Permalink
Merge pull request #1119 from PrestaShopCorp/fix/payment-exception-or…
Browse files Browse the repository at this point in the history
…der-state-mapping-ps6

Avoid fatal error on payment due to OS mapping PS1.6
  • Loading branch information
Matt75 authored Aug 1, 2023
2 parents 2699d5a + f1cbc52 commit dbf4d0e
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/Order/CommandHandler/CreateOrderCommandHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
use PrestaShop\Module\PrestashopCheckout\Order\Exception\OrderException;
use PrestaShop\Module\PrestashopCheckout\Order\Exception\OrderNotFoundException;
use PrestaShop\Module\PrestashopCheckout\Order\Service\CheckOrderAmount;
use PrestaShop\Module\PrestashopCheckout\Order\State\Exception\OrderStateException;
use PrestaShop\Module\PrestashopCheckout\Order\State\OrderStateConfigurationKeys;
use PrestaShop\Module\PrestashopCheckout\Order\State\OrderStateInstaller;
use PrestaShop\Module\PrestashopCheckout\Order\State\Service\OrderStateMapper;
use PrestaShop\Module\PrestashopCheckout\Repository\PsCheckoutCartRepository;
use PrestaShopCollection;
Expand Down Expand Up @@ -143,18 +145,25 @@ public function handle(CreateOrderCommand $command)
$currencyId = Currency::getIdByIsoCode($capture['amount']['currency_code'], (int) $cart->id_shop);
}

if ($paidAmount) {
switch ($this->checkOrderAmount->checkAmount((string) $paidAmount, (string) $cart->getOrderTotal(true, \Cart::BOTH))) {
case CheckOrderAmount::ORDER_NOT_FULL_PAID:
$orderStateId = $this->psOrderStateMapper->getIdByKey(OrderStateConfigurationKeys::PS_CHECKOUT_STATE_PARTIALLY_PAID);
break;
case CheckOrderAmount::ORDER_FULL_PAID:
$orderStateId = $this->psOrderStateMapper->getIdByKey(OrderStateConfigurationKeys::PS_CHECKOUT_STATE_COMPLETED);
break;
case CheckOrderAmount::ORDER_TO_MUCH_PAID:
$orderStateId = $this->psOrderStateMapper->getIdByKey(OrderStateConfigurationKeys::PS_CHECKOUT_STATE_COMPLETED);
try {
if ($paidAmount) {
switch ($this->checkOrderAmount->checkAmount((string) $paidAmount, (string) $cart->getOrderTotal(true, \Cart::BOTH))) {
case CheckOrderAmount::ORDER_NOT_FULL_PAID:
$orderStateId = $this->psOrderStateMapper->getIdByKey(OrderStateConfigurationKeys::PS_CHECKOUT_STATE_PARTIALLY_PAID);
break;
case CheckOrderAmount::ORDER_FULL_PAID:
$orderStateId = $this->psOrderStateMapper->getIdByKey(OrderStateConfigurationKeys::PS_CHECKOUT_STATE_COMPLETED);
break;
case CheckOrderAmount::ORDER_TO_MUCH_PAID:
$orderStateId = $this->psOrderStateMapper->getIdByKey(OrderStateConfigurationKeys::PS_CHECKOUT_STATE_COMPLETED);
}
} else {
$orderStateId = $this->psOrderStateMapper->getIdByKey(OrderStateConfigurationKeys::PS_CHECKOUT_STATE_PENDING);
}
} catch (OrderStateException $exception) {
if ($exception->getCode() === OrderStateException::INVALID_MAPPING) {
(new OrderStateInstaller())->install();
}
} else {
$orderStateId = $this->psOrderStateMapper->getIdByKey(OrderStateConfigurationKeys::PS_CHECKOUT_STATE_PENDING);
}

Expand Down

0 comments on commit dbf4d0e

Please sign in to comment.