Skip to content

Commit

Permalink
Bugfix: Prevent the store credit to be restored twice after cancelation
Browse files Browse the repository at this point in the history
  • Loading branch information
michielgerritsen committed Mar 25, 2024
1 parent 76719d8 commit f5993fc
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 @@ -365,6 +365,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 f5993fc

Please sign in to comment.