Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions src/Controller/Action/CheckoutStartAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use BitBag\SyliusAmazonPayPlugin\AmazonPayGatewayFactory;
use Doctrine\ORM\EntityManagerInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\PaymentInterface;
use Sylius\Component\Core\Model\PaymentMethod;
use Sylius\Component\Core\Model\PaymentMethodInterface;
use Sylius\Component\Order\Context\CartContextInterface;
Expand Down Expand Up @@ -53,25 +54,30 @@ public function __invoke(Request $request): Response
/** @var OrderInterface $order */
$order = $this->cartContext->getCart();

/** @var PaymentMethodInterface $paymentMethod */
$paymentMethod = $order->getLastPayment()->getMethod();
/** @var PaymentInterface $order */
$payment = $order->getLastPayment();

if (
null !== $paymentMethod &&
AmazonPayGatewayFactory::FACTORY_NAME === $paymentMethod->getGatewayConfig()->getFactoryName()
) {
/** @var PaymentMethod[] $paymentMethods */
$paymentMethods = $this->paymentMethodsResolver->getSupportedMethods($order->getLastPayment());
if(null !== $payment) {
/** @var PaymentMethodInterface $paymentMethod */
$paymentMethod = $payment->getMethod();

foreach ($paymentMethods as $paymentMethod) {
if (
AmazonPayGatewayFactory::FACTORY_NAME !== $paymentMethod->getGatewayConfig()->getFactoryName()
) {
$order->getLastPayment()->setMethod($paymentMethod);
if (
null !== $paymentMethod &&
AmazonPayGatewayFactory::FACTORY_NAME === $paymentMethod->getGatewayConfig()->getFactoryName()
) {
/** @var PaymentMethod[] $paymentMethods */
$paymentMethods = $this->paymentMethodsResolver->getSupportedMethods($order->getLastPayment());

$this->orderEntityManager->flush();
foreach ($paymentMethods as $paymentMethod) {
if (
AmazonPayGatewayFactory::FACTORY_NAME !== $paymentMethod->getGatewayConfig()->getFactoryName()
) {
$order->getLastPayment()->setMethod($paymentMethod);

return new RedirectResponse($this->router->generate('sylius_shop_checkout_address'));
$this->orderEntityManager->flush();

return new RedirectResponse($this->router->generate('sylius_shop_checkout_address'));
}
}
}
}
Expand Down