Skip to content

Commit

Permalink
Fixed incorrect order status issues
Browse files Browse the repository at this point in the history
  • Loading branch information
L3RAZ committed Nov 4, 2024
1 parent 065bee5 commit 66d463f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
19 changes: 16 additions & 3 deletions src/Checkout/EventSubscriber/CheckoutEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,14 @@ public function proceedToPayment(CheckoutCompletedEvent $event)
$event->getPayPalOrderId()->getValue()
));

$payPalOrder = $getPayPalOrderForCheckoutCompletedQueryResult->getPayPalOrder();

try {
$this->checkoutChecker->continueWithAuthorization($event->getCartId()->getValue(), $getPayPalOrderForCheckoutCompletedQueryResult->getPayPalOrder());
$this->checkoutChecker->continueWithAuthorization($event->getCartId()->getValue(), $payPalOrder);
} catch (PsCheckoutException $exception) {
if ($exception->getCode() === PsCheckoutException::PAYPAL_ORDER_ALREADY_CAPTURED) {
$this->commandBus->handle(new CreateOrderCommand($event->getPayPalOrderId()->getValue()));
$capture = $payPalOrder['purchase_units'][0]['payments']['captures'][0] ?? null;
$this->commandBus->handle(new CreateOrderCommand($event->getPayPalOrderId()->getValue(), $capture));

return;
} else {
Expand Down Expand Up @@ -161,7 +164,17 @@ public function proceedToPayment(CheckoutCompletedEvent $event)

throw $exception;
} elseif ($exception->getCode() === PayPalException::ORDER_ALREADY_CAPTURED) {
$this->commandBus->handle(new CreateOrderCommand($event->getPayPalOrderId()->getValue()));
if (isset($payPalOrder['purchase_units'][0]['payments']['captures'][0])) {
$capture = $payPalOrder['purchase_units'][0]['payments']['captures'][0];
} else {
/** @var GetPayPalOrderForCheckoutCompletedQueryResult $getPayPalOrderForCheckoutCompletedQueryResult */
$getPayPalOrderForCheckoutCompletedQueryResult = $this->commandBus->handle(new GetPayPalOrderForCheckoutCompletedQuery(
$event->getPayPalOrderId()->getValue()
));
$payPalOrder = $getPayPalOrderForCheckoutCompletedQueryResult->getPayPalOrder();
$capture = $payPalOrder['purchase_units'][0]['payments']['captures'][0] ?? null;
}
$this->commandBus->handle(new CreateOrderCommand($event->getPayPalOrderId()->getValue(), $capture));

return;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public function handle(GetPayPalOrderForCheckoutCompletedQuery $getPayPalOrderQu

try {
$orderPayPal = new PaypalOrder($getPayPalOrderQuery->getOrderPayPalId()->getValue());
$this->orderPayPalCache->set($getPayPalOrderQuery->getOrderPayPalId()->getValue(), $orderPayPal->getOrder());
$orderToStoreInCache = !empty($order) ? array_replace_recursive($order, $orderPayPal->getOrder()) : $orderPayPal->getOrder();
$this->orderPayPalCache->set($getPayPalOrderQuery->getOrderPayPalId()->getValue(), $orderToStoreInCache);
} catch (HttpTimeoutException $exception) {
throw $exception;
} catch (Exception $exception) {
Expand Down

0 comments on commit 66d463f

Please sign in to comment.