Skip to content

Commit

Permalink
Add mechanism for failing order update task when order is in invalid …
Browse files Browse the repository at this point in the history
…state

ISSUE: CS-4704
  • Loading branch information
AleksandarBoljanovic committed Nov 14, 2023
1 parent 59b1758 commit 6ba3bbf
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/classes/Services/Integration/OrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Adyen\Core\BusinessLogic\Domain\Multistore\StoreContext;
use Adyen\Core\BusinessLogic\Domain\TransactionHistory\Repositories\TransactionHistoryRepository;
use Adyen\Core\BusinessLogic\Domain\Webhook\Models\Webhook;
use Adyen\Core\Infrastructure\ORM\Exceptions\QueryFilterInvalidParamException;
use Adyen\Core\Infrastructure\ORM\Exceptions\RepositoryClassException;
use Adyen\Webhook\EventCodes;
use AdyenPayment\Classes\Services\RefundHandler;
Expand All @@ -16,6 +15,7 @@
use Db;
use Order;
use OrderHistory;
use Exception;
use PrestaShop\PrestaShop\Adapter\Entity\Currency;
use PrestaShopDatabaseException;
use PrestaShopException;
Expand Down Expand Up @@ -54,19 +54,28 @@ public function __construct(TransactionHistoryRepository $transactionLogReposito
*
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
* @throws Exception
*/
public function orderExists(string $merchantReference): bool
{
$cart = new Cart((int)$merchantReference);
$idOrder = (int)$this->getIdByCartId((int)$merchantReference);
$order = new Order($idOrder);

return $cart->orderExists() &&
$order->module === 'adyenofficial' &&
isset($order->current_state) &&
(int)$order->current_state !== 0 &&
(int)$cart->id_shop === (int)StoreContext::getInstance()->getStoreId() &&
$this->transactionHistoryRepository->getTransactionHistory($merchantReference);
if (!$cart->orderExists() ||
(int)$cart->id_shop !== (int)StoreContext::getInstance()->getStoreId() ||
$order->module !== 'adyenofficial' ||
!$this->transactionHistoryRepository->getTransactionHistory($merchantReference)) {
return false;
}

if (!isset($order->current_state) || (int)$order->current_state === 0) {
throw new Exception(
'Order with cart ID:' . $merchantReference . ' can not be updated, because order is still not completed. Order is not in initial state.'
);
}

return true;
}

/**
Expand Down

0 comments on commit 6ba3bbf

Please sign in to comment.