Skip to content

Commit

Permalink
Merge branch 'bugfix/prevent-double-credit-restore' into release-week-15
Browse files Browse the repository at this point in the history
  • Loading branch information
michielgerritsen committed Apr 18, 2024
2 parents 1f200cf + f5993fc commit d29e239
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Plugin/CustomerBalance/Observer/PreventDoubleCreditRevert.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace Mollie\Payment\Plugin\CustomerBalance\Observer;

use Magento\Framework\Event\Observer;
use Magento\Sales\Api\Data\OrderInterface;

class PreventDoubleCreditRevert
{
public function aroundExecute($subject, callable $proceed, Observer $observer)
{
$order = $observer->getData('order');
if (!$order ||
!$order instanceof OrderInterface ||
!$order->getPayment()
) {
return $proceed($observer);
}

if ($observer->getEvent()->getName() == 'restore_quote' &&
$this->isMollieOrder($order)
) {
return $subject;
}

return $proceed($observer);
}

private function isMollieOrder(OrderInterface $order): bool
{
$payment = $order->getPayment();

return strstr($payment->getMethod(), 'mollie_methods_') !== false;
}
}
4 changes: 4 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@
</arguments>
</type>

<type name="Magento\CustomerBalance\Observer\RevertStoreCreditObserver">
<plugin name="mollie_prevent_double_credit_revert" type="Mollie\Payment\Plugin\CustomerBalance\Observer\PreventDoubleCreditRevert" />
</type>

<!-- Payment methods configuration start -->
<!-- ApplePay -->
<type name="Mollie\Payment\Model\Methods\ApplePay">
Expand Down

0 comments on commit d29e239

Please sign in to comment.