Skip to content

Commit

Permalink
Removed capture status check in payment controller
Browse files Browse the repository at this point in the history
  • Loading branch information
L3RAZ committed Nov 5, 2024
1 parent 66d463f commit c473798
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
16 changes: 7 additions & 9 deletions controllers/front/payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,14 @@ private function createOrder($payPalOrderFromCache, $payPalOrder)
/** @var CommandBusInterface $commandBus */
$commandBus = $this->module->getService('ps_checkout.bus.command');

$capture = $payPalOrderFromCache['purchase_units'][0]['payments']['captures'][0];
if ($capture['status'] === 'COMPLETED') {
$commandBus->handle(new CreateOrderCommand($payPalOrder->getId()->getValue(), $capture));
if ($payPalOrder->getPaymentTokenId() && $payPalOrder->checkCustomerIntent(PayPalOrder::CUSTOMER_INTENT_FAVORITE)) {
/** @var PaymentTokenRepository $paymentTokenRepository */
$paymentTokenRepository = $this->module->getService(PaymentTokenRepository::class);
$paymentTokenRepository->setTokenFavorite($payPalOrder->getPaymentTokenId());
}
$this->redirectToOrderConfirmationPage($payPalOrder->getIdCart(), $capture['id'], $payPalOrderFromCache['status']);
$capture = $payPalOrderFromCache['purchase_units'][0]['payments']['captures'][0] ?? null;
$commandBus->handle(new CreateOrderCommand($payPalOrder->getId()->getValue(), $capture));
if ($payPalOrder->getPaymentTokenId() && $payPalOrder->checkCustomerIntent(PayPalOrder::CUSTOMER_INTENT_FAVORITE)) {
/** @var PaymentTokenRepository $paymentTokenRepository */
$paymentTokenRepository = $this->module->getService(PaymentTokenRepository::class);
$paymentTokenRepository->setTokenFavorite($payPalOrder->getPaymentTokenId());
}
$this->redirectToOrderConfirmationPage($payPalOrder->getIdCart(), $capture['id'], $payPalOrderFromCache['status']);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Checkout/EventSubscriber/CheckoutEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function proceedToPayment(CheckoutCompletedEvent $event)
$this->checkoutChecker->continueWithAuthorization($event->getCartId()->getValue(), $payPalOrder);
} catch (PsCheckoutException $exception) {
if ($exception->getCode() === PsCheckoutException::PAYPAL_ORDER_ALREADY_CAPTURED) {
$capture = $payPalOrder['purchase_units'][0]['payments']['captures'][0] ?? null;
$capture = isset($payPalOrder['purchase_units'][0]['payments']['captures'][0]) ? $payPalOrder['purchase_units'][0]['payments']['captures'][0] : null;
$this->commandBus->handle(new CreateOrderCommand($event->getPayPalOrderId()->getValue(), $capture));

return;
Expand Down Expand Up @@ -172,7 +172,7 @@ public function proceedToPayment(CheckoutCompletedEvent $event)
$event->getPayPalOrderId()->getValue()
));
$payPalOrder = $getPayPalOrderForCheckoutCompletedQueryResult->getPayPalOrder();
$capture = $payPalOrder['purchase_units'][0]['payments']['captures'][0] ?? null;
$capture = isset($payPalOrder['purchase_units'][0]['payments']['captures'][0]) ? $payPalOrder['purchase_units'][0]['payments']['captures'][0] : null;
}
$this->commandBus->handle(new CreateOrderCommand($event->getPayPalOrderId()->getValue(), $capture));

Expand Down

0 comments on commit c473798

Please sign in to comment.