Skip to content

Commit

Permalink
Added RestAPI compatibility with methods such as Apple Pay
Browse files Browse the repository at this point in the history
  • Loading branch information
julian-van-drielen committed Aug 27, 2024
1 parent 247d2cb commit 8b3c701
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions Webapi/StartTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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;
}

/**
Expand All @@ -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
);
}
}

0 comments on commit 8b3c701

Please sign in to comment.