Skip to content

Commit

Permalink
Restored logic from PS8 branch
Browse files Browse the repository at this point in the history
  • Loading branch information
L3RAZ committed Jan 10, 2025
1 parent 0ea929f commit 42be99e
Showing 1 changed file with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,27 @@ public function __construct(CacheInterface $orderPayPalCache)

public function __invoke(GetPayPalOrderForCheckoutCompletedQuery $getPayPalOrderQuery)
{
$payPalOrderId = $getPayPalOrderQuery->getOrderPayPalId()->getValue();

/** @var array{id: string, status: string} $order */
$order = $this->orderPayPalCache->get(
$getPayPalOrderQuery->getOrderPayPalId()->getValue(),
function(ItemInterface $cacheItem) use ($getPayPalOrderQuery) {
$payPalOrder = new PaypalOrder($getPayPalOrderQuery->getOrderPayPalId()->getValue());
return $payPalOrder->getOrder();
}
);
$order = $this->orderPayPalCache->getItem($payPalOrderId)->get();

if (!empty($order) && $order['status'] === 'APPROVED') {
if (!empty($order) && in_array($order['status'], ['COMPLETED', 'CANCELED'])) {
return new GetPayPalOrderForCheckoutCompletedQueryResult($order);
}

try {
$orderPayPal = new PaypalOrder($getPayPalOrderQuery->getOrderPayPalId()->getValue());
$this->orderPayPalCache->set($getPayPalOrderQuery->getOrderPayPalId()->getValue(), $orderPayPal->getOrder());
$orderPayPal = new PaypalOrder($payPalOrderId);
$orderToStoreInCache = !empty($order) ? array_replace_recursive($order, $orderPayPal->getOrder()) : $orderPayPal->getOrder();
$this->orderPayPalCache->set($payPalOrderId, $orderToStoreInCache);
} catch (HttpTimeoutException $exception) {
throw $exception;
} catch (Exception $exception) {
throw new PayPalOrderException(sprintf('Unable to retrieve PayPal Order %s', $getPayPalOrderQuery->getOrderPayPalId()->getValue()), PayPalOrderException::CANNOT_RETRIEVE_ORDER, $exception);
throw new PayPalOrderException(sprintf('Unable to retrieve PayPal Order %s', $payPalOrderId), PayPalOrderException::CANNOT_RETRIEVE_ORDER, $exception);
}

if (!$orderPayPal->isLoaded()) {
throw new PayPalOrderException(sprintf('No data for PayPal Order %s', $getPayPalOrderQuery->getOrderPayPalId()->getValue()), PayPalOrderException::EMPTY_ORDER_DATA);
throw new PayPalOrderException(sprintf('No data for PayPal Order %s', $payPalOrderId), PayPalOrderException::EMPTY_ORDER_DATA);
}

return new GetPayPalOrderForCheckoutCompletedQueryResult($orderPayPal->getOrder());
Expand Down

0 comments on commit 42be99e

Please sign in to comment.