Skip to content

Commit

Permalink
add check for -capture suffix (#1760)
Browse files Browse the repository at this point in the history
  • Loading branch information
RokPopov authored Oct 7, 2022
1 parent c133886 commit 55960b7
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions Helper/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -571,27 +571,29 @@ public function refundOrder(MagentoOrder $order, Notification $notification): Ma
$lastTransactionId = $order->getPayment()->getLastTransId();
$matches = $this->dataHelper->parseTransactionId($lastTransactionId);
if (($matches['pspReference'] ?? '') == $notification->getOriginalReference() && empty($matches['suffix'])) {
// refund is done through adyen backoffice so create a credit memo
if ($order->canCreditmemo()) {
$amount = $this->dataHelper->originalAmount($notification->getAmountValue(), $notification->getAmountCurrency());
$order->getPayment()->registerRefundNotification($amount);

$this->adyenLogger->addAdyenNotification(sprintf(
'Created credit memo for order %s', $order->getIncrementId()),
[
'pspReference' => $notification->getPspreference(),
'merchantReference' => $notification->getMerchantReference()
]
);
} else {
$this->adyenLogger->addAdyenNotification(sprintf(
'Could not create a credit memo for order %s while processing notification %s',
$order->getIncrementId(),
$notification->getId()
), [
'pspReference' => $order->getPayment()->getData('adyen_psp_reference'),
'merchantReference' => $order->getPayment()->getData('entity_id')
]);
if (empty($matches['suffix']) || $matches['suffix'] === '-capture') {
// refund is done through adyen backoffice so create a credit memo
if ($order->canCreditmemo()) {
$amount = $this->dataHelper->originalAmount($notification->getAmountValue(), $notification->getAmountCurrency());
$order->getPayment()->registerRefundNotification($amount);

$this->adyenLogger->addAdyenNotification(sprintf(
'Created credit memo for order %s', $order->getIncrementId()),
[
'pspReference' => $notification->getPspreference(),
'merchantReference' => $notification->getMerchantReference()
]
);
} else {
$this->adyenLogger->addAdyenNotification(sprintf(
'Could not create a credit memo for order %s while processing notification %s',
$order->getIncrementId(),
$notification->getId()
), [
'pspReference' => $order->getPayment()->getData('adyen_psp_reference'),
'merchantReference' => $order->getPayment()->getData('entity_id')
]);
}
}
} else {
$this->adyenLogger->addAdyenNotification(sprintf(
Expand Down

0 comments on commit 55960b7

Please sign in to comment.