From fd68ea9b1b32ccfe75aa7d834b9a169c8f6cfbfc Mon Sep 17 00:00:00 2001 From: Christian Dangl Date: Thu, 28 Sep 2023 16:22:56 +0200 Subject: [PATCH] NTR: fix problem with retrying POS payments after failures --- src/Facade/MolliePaymentDoPay.php | 8 +++++--- tests/PHPUnit/Traits/StringTrait.php | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 tests/PHPUnit/Traits/StringTrait.php diff --git a/src/Facade/MolliePaymentDoPay.php b/src/Facade/MolliePaymentDoPay.php index b58606af9..63258f766 100644 --- a/src/Facade/MolliePaymentDoPay.php +++ b/src/Facade/MolliePaymentDoPay.php @@ -23,8 +23,8 @@ use Kiener\MolliePayments\Struct\MolliePaymentPrepareData; use Kiener\MolliePayments\Struct\Order\OrderAttributes; use Mollie\Api\Exceptions\ApiException; -use Mollie\Api\Resources\Order as MollieOrder; use Mollie\Api\Resources\OrderLine; +use MolliePayments\Tests\Traits\StringTrait; use Psr\Log\LoggerInterface; use Shopware\Core\Checkout\Order\OrderEntity; use Shopware\Core\Checkout\Payment\Cart\AsyncPaymentTransactionStruct; @@ -34,6 +34,8 @@ class MolliePaymentDoPay { + use StringTrait; + /** * @var OrderDataExtractor */ @@ -172,7 +174,7 @@ public function startMolliePayment(string $paymentMethod, AsyncPaymentTransactio # this is the case, if we already have a Mollie Order ID in our custom fields. # in this case, we just add a new payment (transaction) to the existing order in Mollie. # DO NEVER reuse a POS payment, because that only works with payments and not with orders!!! - if (!$paymentHandler instanceof PosPayment && !empty($mollieOrderId)) { + if (!$paymentHandler instanceof PosPayment && $this->stringStartsWith($mollieOrderId, 'ord_')) { try { return $this->handleNextPaymentAttempt( $order, @@ -194,7 +196,7 @@ public function startMolliePayment(string $paymentMethod, AsyncPaymentTransactio } $this->logger->debug( - 'Start first payment attempt for order: ' . $order->getOrderNumber(), + 'Start payment attempt for order: ' . $order->getOrderNumber(), [ 'salesChannel' => $salesChannelContext->getSalesChannel()->getName(), 'mollieID' => '-', diff --git a/tests/PHPUnit/Traits/StringTrait.php b/tests/PHPUnit/Traits/StringTrait.php new file mode 100644 index 000000000..d822b3b75 --- /dev/null +++ b/tests/PHPUnit/Traits/StringTrait.php @@ -0,0 +1,22 @@ +