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 + ); } }