Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#GCC currency - saved amount on create adyen order #1385

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions Helper/AdyenOrderPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use Magento\Framework\App\Helper\Context;
use Magento\Framework\Exception\AlreadyExistsException;
use Magento\Sales\Model\Order;
use Adyen\Payment\Helper\Config;

/**
* Helper class for anything related to the adyen_order_payment entity
Expand Down Expand Up @@ -78,6 +79,11 @@ class AdyenOrderPayment extends AbstractHelper
*/
protected $invoiceHelper;

/**
* @var Config
*/
protected $config;

/**
* AdyenOrderPayment constructor.
*
Expand All @@ -97,7 +103,8 @@ public function __construct(
ChargedCurrency $adyenChargedCurrencyHelper,
OrderPaymentResourceModel $orderPaymentResourceModel,
PaymentFactory $adyenOrderPaymentFactory,
Invoice $invoiceHelper
Invoice $invoiceHelper,
Config $config
) {
parent::__construct($context);
$this->adyenLogger = $adyenLogger;
Expand All @@ -107,6 +114,7 @@ public function __construct(
$this->orderPaymentResourceModel = $orderPaymentResourceModel;
$this->adyenOrderPaymentFactory = $adyenOrderPaymentFactory;
$this->invoiceHelper = $invoiceHelper;
$this->config = $config;
}

/**
Expand Down Expand Up @@ -214,7 +222,9 @@ public function createAdyenOrderPayment(Order $order, Notification $notification
{
$adyenOrderPayment = null;
$payment = $order->getPayment();
$amount = $this->adyenDataHelper->originalAmount($notification->getAmountValue(), $order->getBaseCurrencyCode());
$chargedCurrencyCode = $this->config->getChargedCurrency() === "display"
? $order->getOrderCurrencyCode() : $order->getBaseCurrencyCode();
$amount = $this->adyenDataHelper->originalAmount($notification->getAmountValue(), $chargedCurrencyCode);
Comment on lines +225 to +227
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dejankar would you mind doing quick check for this testing your scenario?

Suggested change
$chargedCurrencyCode = $this->config->getChargedCurrency() === "display"
? $order->getOrderCurrencyCode() : $order->getBaseCurrencyCode();
$amount = $this->adyenDataHelper->originalAmount($notification->getAmountValue(), $chargedCurrencyCode);
$amount = $this->adyenDataHelper->originalAmount($notification->getAmountValue(), $notification->getAmountCurrency());

Copy link
Contributor Author

@dejankar dejankar Mar 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dejankar would you mind doing quick check for this testing your scenario?

Hi Angel, I don't mind and I already tested your suggestion even before and can confirm that's working as expected when capturing payments.

However when refunding from the Adyen platform the amount is wrong, and always tries to refund the base amount instead of the correct amount.

I'm checking if this is related with this code or not.

Dejan

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dejankar would you mind doing quick check for this testing your scenario?

Hi Angel, I don't mind and I already tested your suggestion even before and can confirm that's working as expected when capturing payments.

However when refunding from the Adyen platform the amount is wrong, and always tries to refund the base amount instead of the correct amount.

I'm checking if this is related with this code or not.

Dejan

Seems that issue is not related with those changes and it's another issue.

So when order is placed with one of KWD, OMR, BHD as a display currency and then I try to refund from Adyen platform the full amount.

This is the response in M2:

Adyen Refund Successfully completed

IPN "Refunded". Refund issued by merchant. Registered notification about refunded amount of $15.90. Transaction ID: "". Credit Memo has not been created. Please create offline Credit Memo.

Adyen HTTP Notification(s):
eventCode: REFUND
pspReference: JR6PFJ8VBGNG5S82
paymentMethod: visa
success: true

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dejankar interesting, can you spot anything in the logs that could clarify if this is a bug?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @acampos1916 ,
Nothing in the logs that clarifies it.

The notification seems correct and data inside is correct:
[2022-03-16 09:11:43] AdyenLoggerTest.ADYEN_NOTIFICATION: The content of the notification item is: {"amount":{"currency":"KWD","value":15900},"eventCode":"REFUND","eventDate":"2022-03-16T10:10:38+01:00","merchantAccountCode":"Lens_Me","merchantReference":"1000612602","originalReference":"JXVHHCW6PP4WHD82","paymentMethod":"visa","pspReference":"JR6PFJ8VBGNG5S82","reason":"","success":"true"} {"is_exception":false} []
[2022-03-16 09:11:43] AdyenLoggerTest.ADYEN_NOTIFICATION: The result is accepted {"is_exception":false} []

I guess it's the same issue how the amount is being formated when sent back from Adyen webhooks, but will debug later on and get back when I have more info.

It's not a general bug as i tried the same with our base currency and a refund was successfully created.

Best Regards,
Dejan

$captureStatus = $autoCapture ? Payment::CAPTURE_STATUS_AUTO_CAPTURE : Payment::CAPTURE_STATUS_NO_CAPTURE;
$merchantReference = $notification->getMerchantReference();
$pspReference = $notification->getPspreference();
Expand Down