Skip to content

Commit

Permalink
Updated PayPal order fetching to check date_upd
Browse files Browse the repository at this point in the history
  • Loading branch information
L3RAZ committed Oct 30, 2024
1 parent 439fc49 commit 741bf5b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions config/query-handlers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ services:
public: true
arguments:
- "@ps_checkout.cache.paypal.order"
- '@PrestaShop\Module\PrestashopCheckout\Repository\PsCheckoutCartRepository'

PrestaShop\Module\PrestashopCheckout\PayPal\Order\QueryHandler\GetPayPalOrderForOrderConfirmationQueryHandler:
class: 'PrestaShop\Module\PrestashopCheckout\PayPal\Order\QueryHandler\GetPayPalOrderForOrderConfirmationQueryHandler'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
use PrestaShop\Module\PrestashopCheckout\PayPal\Order\Query\GetPayPalOrderForCheckoutCompletedQuery;
use PrestaShop\Module\PrestashopCheckout\PayPal\Order\Query\GetPayPalOrderForCheckoutCompletedQueryResult;
use PrestaShop\Module\PrestashopCheckout\PaypalOrder;
use PrestaShop\Module\PrestashopCheckout\Repository\PsCheckoutCartRepository;
use PsCheckoutCart;
use Psr\SimpleCache\CacheInterface;

/**
Expand All @@ -38,18 +40,28 @@ class GetPayPalOrderForCheckoutCompletedQueryHandler
* @var CacheInterface
*/
private $orderPayPalCache;
/**
* @var PsCheckoutCartRepository
*/
private $psCheckoutCartRepository;

public function __construct(CacheInterface $orderPayPalCache)
public function __construct(CacheInterface $orderPayPalCache, PsCheckoutCartRepository $psCheckoutCartRepository)
{
$this->orderPayPalCache = $orderPayPalCache;
$this->psCheckoutCartRepository = $psCheckoutCartRepository;
}

public function handle(GetPayPalOrderForCheckoutCompletedQuery $getPayPalOrderQuery)
{
/** @var array{id: string, status: string} $order */
$order = $this->orderPayPalCache->get($getPayPalOrderQuery->getOrderPayPalId()->getValue());
$psCheckoutCart = $this->psCheckoutCartRepository->findOneByPayPalOrderId($getPayPalOrderQuery->getOrderPayPalId()->getValue());

$psCheckoutCartDateUpdated = new \DateTime($psCheckoutCart->date_upd);
$currentDateTime = new \DateTime();
$interval = $currentDateTime->getTimestamp() - $psCheckoutCartDateUpdated->getTimestamp();

if (!empty($order) && !in_array($order['status'], ['APPROVED', 'COMPLETED'])) {
if (!empty($order) && ($psCheckoutCart->paypal_status === $order['status'] && $interval < 30 || in_array($order['status'], [PsCheckoutCart::STATUS_COMPLETED, PsCheckoutCart::STATUS_CANCELED]))) {
return new GetPayPalOrderForCheckoutCompletedQueryResult($order);
}

Expand Down

0 comments on commit 741bf5b

Please sign in to comment.