Skip to content

Commit

Permalink
NTR: fix problem with retrying POS payments after failures
Browse files Browse the repository at this point in the history
  • Loading branch information
boxblinkracer committed Sep 28, 2023
1 parent 2e3817e commit fd68ea9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Facade/MolliePaymentDoPay.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,6 +34,8 @@

class MolliePaymentDoPay
{
use StringTrait;

/**
* @var OrderDataExtractor
*/
Expand Down Expand Up @@ -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,
Expand All @@ -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' => '-',
Expand Down
22 changes: 22 additions & 0 deletions tests/PHPUnit/Traits/StringTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace MolliePayments\Tests\Traits;

trait StringTrait
{

/**
* @param string $haystack
* @param string $needle
* @return bool
*/
protected function stringStartsWith(string $haystack, string $needle): bool
{
if (strpos($haystack, $needle) === 0) {
return true;
}

return false;
}

}

0 comments on commit fd68ea9

Please sign in to comment.