Skip to content

Commit a576a53

Browse files
Bugfix: Prevent new transactions when the previous one is already paid #791 and #786
1 parent ca64e77 commit a576a53

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

Exceptions/PaymentAborted.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/*
3+
* Copyright Magmodules.eu. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Mollie\Payment\Exceptions;
10+
11+
use Magento\Framework\Exception\LocalizedException;
12+
13+
class PaymentAborted extends LocalizedException
14+
{
15+
16+
}

Model/Client/Orders.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Mollie\Api\Resources\Payment;
2727
use Mollie\Api\Types\OrderStatus;
2828
use Mollie\Payment\Config;
29+
use Mollie\Payment\Exceptions\PaymentAborted;
2930
use Mollie\Payment\Helper\General as MollieHelper;
3031
use Mollie\Payment\Model\Adminhtml\Source\InvoiceMoment;
3132
use Mollie\Payment\Model\Client\Orders\ProcessTransaction;
@@ -916,6 +917,15 @@ private function getCheckoutUrl(MollieApiClient $mollieApi, OrderInterface $orde
916917
return $checkoutUrl;
917918
}
918919

920+
if ($mollieOrder->status == 'paid') {
921+
$this->config->addToLog('error', [
922+
'message' => 'This order already has been paid.',
923+
'order' => $order->getEntityId(),
924+
]);
925+
926+
throw new PaymentAborted(__('This order already has been paid.'));
927+
}
928+
919929
// There is no checkout URL, the transaction is either canceled or expired. Create a new transaction.
920930
$order->setMollieTransactionId(null);
921931
return $this->startTransaction($order, $mollieApi);

Model/Client/Payments.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -545,14 +545,12 @@ public function checkCheckoutSession(Order $order, $paymentToken, $paymentData,
545545
}
546546
}
547547

548-
/**
549-
* @param MollieApiClient $mollieApi
550-
* @param $transactionId
551-
* @return string|null
552-
* @throws \Mollie\Api\Exceptions\ApiException
553-
*/
554-
public function getCheckoutUrl(MollieApiClient $mollieApi, $transactionId): ?string
548+
private function getCheckoutUrl(MollieApiClient $mollieApi, ?string $transactionId): ?string
555549
{
550+
if ($transactionId === null) {
551+
return null;
552+
}
553+
556554
$payment = $mollieApi->payments->get($transactionId);
557555
return $payment->getCheckoutUrl();
558556
}

Model/Mollie.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use Mollie\Payment\Api\Data\TransactionToOrderInterface;
3030
use Mollie\Payment\Api\TransactionToOrderRepositoryInterface;
3131
use Mollie\Payment\Config;
32+
use Mollie\Payment\Exceptions\PaymentAborted;
3233
use Mollie\Payment\Helper\General as MollieHelper;
3334
use Mollie\Payment\Model\Client\Orders as OrdersApi;
3435
use Mollie\Payment\Model\Client\Orders\ProcessTransaction;
@@ -293,7 +294,7 @@ private function startTransactionUsingTheOrdersApi(OrderInterface $order, Mollie
293294

294295
$methodCode = $this->mollieHelper->getMethodCode($order);
295296
$methods = ['billie', 'klarna', 'klarnapaylater', 'klarnapaynow', 'klarnasliceit', 'voucher', 'in3'];
296-
if (in_array($methodCode, $methods)) {
297+
if (in_array($methodCode, $methods) || $exception instanceof PaymentAborted) {
297298
throw new LocalizedException(__($exception->getMessage()));
298299
}
299300

0 commit comments

Comments
 (0)