Skip to content

Commit

Permalink
[ECP-9171] Add the merchant reference check in the paymentResponseHan…
Browse files Browse the repository at this point in the history
…dler (#2745)

* add a check to validate merchant reference from details response against order id

* adjust parameter passed to validate merchant ref method
  • Loading branch information
RokPopov authored Sep 18, 2024
1 parent 055ab67 commit b8bdcc9
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Helper/PaymentResponseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,18 @@ public function handlePaymentResponse($paymentsResponse, $payment, $order = null
return false;
}

if(!$this->isValidMerchantReference($paymentsResponse, $order)) {
$order->setState(\Magento\Sales\Model\Order::STATE_NEW);
$order->save();
$order->setActionFlag(\Magento\Sales\Model\Order::ACTION_FLAG_CANCEL, true);
$this->dataHelper->cancelOrder($order);
$order->addStatusHistoryComment(
__('Invalid /payment/details response. Order has been cancelled due to potential fraud'),
$order->getStatus()
)->save();
return false;
}

if (!empty($paymentsResponse['resultCode'])) {
$payment->setAdditionalInformation('resultCode', $paymentsResponse['resultCode']);
}
Expand Down Expand Up @@ -304,4 +316,20 @@ public function handlePaymentResponse($paymentsResponse, $payment, $order = null
}
return true;
}

private function isValidMerchantReference($paymentsResponse, $order)
{
$merchantReference = $paymentsResponse['merchantReference'] ?? null;
if(!$merchantReference) {
$this->adyenLogger->error("No merchantReference in the response");
return false;
}

if ($order->getIncrementId() !== $merchantReference) {
$this->adyenLogger->error("Incorrect merchantReference");
return false;
}

return true;
}
}

0 comments on commit b8bdcc9

Please sign in to comment.