From 8b3c7019cf87449e2db710fe72b06bc016c40645 Mon Sep 17 00:00:00 2001 From: Julian Date: Tue, 27 Aug 2024 09:38:29 +0200 Subject: [PATCH] Added RestAPI compatibility with methods such as Apple Pay --- Webapi/StartTransaction.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Webapi/StartTransaction.php b/Webapi/StartTransaction.php index 7ac877d5392..2db1392b98a 100644 --- a/Webapi/StartTransaction.php +++ b/Webapi/StartTransaction.php @@ -10,6 +10,7 @@ use Magento\Sales\Api\OrderRepositoryInterface; use Mollie\Payment\Api\PaymentTokenRepositoryInterface; use Mollie\Payment\Api\Webapi\StartTransactionRequestInterface; +use Mollie\Payment\Service\Order\Transaction; class StartTransaction implements StartTransactionRequestInterface { @@ -23,12 +24,19 @@ class StartTransaction implements StartTransactionRequestInterface */ private $paymentTokenRepository; + /** + * @var Transaction + */ + private $transaction; + public function __construct( OrderRepositoryInterface $orderRepository, - PaymentTokenRepositoryInterface $paymentTokenRepository + PaymentTokenRepositoryInterface $paymentTokenRepository, + Transaction $transaction ) { $this->orderRepository = $orderRepository; $this->paymentTokenRepository = $paymentTokenRepository; + $this->transaction = $transaction; } /** @@ -45,6 +53,16 @@ public function execute(string $token) /** @var \Mollie\Payment\Model\Mollie $instance */ $instance = $order->getPayment()->getMethodInstance(); - return $instance->startTransaction($order); + $checkoutUrl = $instance->startTransaction($order); + if ($checkoutUrl !== null) { + return $checkoutUrl; + } + + // If the order is paid with a payment method without hosted payment page, + // we need to redirect to the success page. As the order is instantly paid. + return $this->transaction->getRedirectUrl( + $order, + $token + ); } }