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 2 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
2 changes: 1 addition & 1 deletion Helper/AdyenOrderPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public function createAdyenOrderPayment(Order $order, Notification $notification
{
$adyenOrderPayment = null;
$payment = $order->getPayment();
$amount = $this->adyenDataHelper->originalAmount($notification->getAmountValue(), $order->getBaseCurrencyCode());
$amount = $this->adyenDataHelper->originalAmount($notification->getAmountValue(), $order->getOrderCurrencyCode());
Copy link
Member

Choose a reason for hiding this comment

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

Would it be better to use $notification->getAmountCurrency()? Maybe that way the entity is created in adyen_order_payment with the matching currency everytime.

I see that @Morerice introduced this, do you know if we can make that change?

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 ,

thanks for replying back.

Not sure if the question is directed to me but I took the liberty to respond:
Looking at the plugin code, I believe both options will work as expected.

However, I would stick to the Magento default $order->getOrderCurrencyCode() as that's following the formatting that Magento needs always.

If you use $notification->getAmountCurrency() and in the future, you decide to change the code how webhooks pass the currency code or decide not to pass it at all, it will break the function again.

In the end, it's a matter of preference :).

I applied my solution on our live website and so far we didn't experience any bugs or problems after applying the patch.

Best
Dejena

Copy link
Member

Choose a reason for hiding this comment

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

Thanks @dejankar. If I get it right there are multiple scenarios to cover:

Base currency A, Display currency B (getOrderCurrencyCode != getAmountCurrency)
Base currency B, Display currency A (getOrderCurrencyCode != getAmountCurrency)
Base currency A, Display currency A (getOrderCurrencyCode == getAmountCurrency)
Base currency B, Display currency B (getOrderCurrencyCode == getAmountCurrency)

If the charged currency config included in the plugin is set to Display the payment will be processed with the Display currency, but the getOrderCurrencyCode would return the Base currency. I think it is safer to use $notification->getAmountCurrency() because of that, what do you think?

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 Angel,

Extended solution committed that checks how the Adyen plugin is set.
If it's set to use display currency then we have only one scenario actually.

  1. OrderCurrencyCode will always return the display currency code and will be matching Magento values.

  2. If plugin is set to use base currency code , we can always return the base currency code with :
    $order->getBaseCurrencyCode();

So the check I add will solve the concerns you have from the Magento side.

However, what you mentioned is not wrong and $notification->getAmountCurrency() can be used too if as mentioned you are not a plugin to change the data on your end and how data is passed from the webhooks back to Magento.

Great conversation btw 👍

Best Regards,
Dejan

Copy link
Member

Choose a reason for hiding this comment

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

Hey @dejankar, of course! Thanks for helping us figure this out.

I'll test your patience a bit more 😄 since the notification is being processed after the payment has been completed there's a small chance that the plugin's config for charged currency has been modified between the order placement and the webhook being received, that would set the wrong currency with your updated approach.

I would indeed suggest to use the $notification->getAmountCurrency(), to my knowledge there are no plans at all to change the format from the Adyen side and hasn't been changed for a while. It is safe to use.

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 ,

Sure it's my pleasure.

Yeah, I agree there is a small chance for the mentioned use case but in such config, the whole process might be wrong.
There might be a problem if let's say the order was placed in base currency and then someone changes the charged currency setting and then webhooks returns the values with a different currency.

That might interfere with Magento's internal logic for let's say if someone invoice later and want to capture the amount in charged currency. Than anyway the order needs to be fixed from the M2 side.

But all in all, I'm really fine with the proposal from your side: $notification->getAmountCurrency(), especially as you mentioned that format won't be changed in the future, and the field will always be called like this.

I will leave the decision for you and your team!

It's been a pleasure chatting with all of you guys :)

Looking forward to the solution and all the great stuff that this plugin offer.

Copy link
Member

Choose a reason for hiding this comment

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

@dejankar good point! We do have a mechanism in place so that orders are captured and refunded in the currency with which it was placed, see the docblock for this helper function.

I'm doing a suggestion with the use of the notification currency. Thank you!

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