white-nl / commerce-mollie-plus

Mollie Klarna integration for Craft Commerce
Other
3 stars 4 forks source link

Currency support #22

Closed Romanavr closed 2 weeks ago

Romanavr commented 7 months ago

Description

See following PR -> https://github.com/white-nl/commerce-mollie-plus/pull/21 We recently switched to this plugin from the original Mollie plugin and after a few days we noticed something strange in the logs. It turned out that this plugin does not support other payment currencies at all.

Our client really like the support of the "Klarna Pay Later", so we decided to help you guys a bit and add crutch currency support by our own. Please look at my PR, I wrote there what I did. You can reject it or just use it as a source of inspiration, but PLEASE add currency support. If you know how to do this better, I, and others, will be very grateful to you. We have tested this code for a 2 weeks on our store and everything worked well.

Steps to reproduce

  1. Try placing an order for Molly using this plugin and a payment currency with a rate other than 1.

Additional info

WHITE-developer commented 6 months ago

Thanks for the PR, I'll try to look at it early next week!

WHITE-developer commented 6 months ago

Hi @Romanavr , Just tagged 2.4.0 which added the multi currency support.

Romanavr commented 6 months ago

Hi @Romanavr , Just tagged 2.4.0 which added the multi currency support.

Thanks! Will check and let you know if something is wrong.

Romanavr commented 5 months ago

Hey @WHITE-developer I get the error Amount precision is too high for currency. when I try to pay in a currency whose exchange rate is not 1. How to reproduce:

  1. My primary currency is EUR, I have a product variant for 100 EUR.
  2. I set the payment currency to be the American USD with the exchange rate, for example, 1.078
  3. I add an item to the cart, try to pay through Mollie Plus and see error above

It's also worth adding that I have 21% TAX included on this product and 5 EUR shipping, see example: image

WHITE-developer commented 5 months ago

Hey @Romanavr Could you test the fix I just pushed to the develop-v2 branch if this fixes it?

Romanavr commented 5 months ago

Hey @Romanavr Could you test the fix I just pushed to the develop-v2 branch if this fixes it?

Thanks for the quick this fix. This works, however another problem is that in some cases I get the following error from the Mollie API (initial problem): "The amount of the order does not match the total amount from the order lines."

How to reproduce:

  1. My primary currency is EUR, I have a product variant for 100 EUR.
  2. I set the payment currency to be the Norwegian Krone(NOK) with the exchange rate, for example, 11.7531
  3. I'm trying to pay on the final checkout step and getting the error above. image

https://github.com/white-nl/commerce-mollie-plus/pull/21#issue-2171438197 I mentioned earlier in my PR that I ran into the same problem when I tried to fix it. We're currently using a fork with the fix suggested in the PR, and it works, so maybe you can still use something from it. I guess the main problem is that commerce under the hood converts(or rounds) the total value again and thus we get the difference between the total amount(in decimals) sent and the calculated amount of each item in the Mollie. Mollie Order API always compares the total amount sent and the total amount of each item (the API itself sums the quantity * price of each item). And if we have a difference, then an error message will be thrown above.

WHITE-developer commented 4 months ago

Hi, I tested with the same order you have but the error I got is a wrong tax amount on the lineItem, as the converted tax amount is (17.36*11.7531) = 204.03. But when calculating the included tax on the converted lineItem price (1175.31) (1175.31-1175.31/1.21) = 203.98

And this is the calculation that Mollie does, this means that we can't use the calculated tax values that Craft provides but that we'll have to do the calculations ourself

Romanavr commented 4 months ago

Hi, I tested with the same order you have but the error I got is a wrong tax amount on the lineItem, as the converted tax amount is (17.36*11.7531) = 204.03. But when calculating the included tax on the converted lineItem price (1175.31) (1175.31-1175.31/1.21) = 203.98

And this is the calculation that Mollie does, this means that we can't use the calculated tax values that Craft provides but that we'll have to do the calculations ourself

Yes, that's exactly what I meant. For this particular reason, we need to do the calculations manually rather than taking calculations from commerce. If you can fix this I will be grateful for it.

white-lukas commented 1 month ago

This is fixed in 2.5.0

Romanavr commented 1 month ago

@white-lukas Unfortunately, it doesn't work if I have an order with exchange order != 1 and have VAT and any discount (coupon code):

Client error: `POST https://api.mollie.com/v2/orders` resulted in a `422 unknown` response:
{"status":422,"title":"Unprocessable Entity","detail":"Order line 5 is invalid. VAT amount is off. Expected VAT amount t (truncated...)
white-lukas commented 3 weeks ago

Hi @Romanavr Could you provide the used VAT rate/method and discount, as I did test with different methods but was not able to replicate it

white-lukas commented 2 weeks ago

I've now removed the vat and discount amounts If they where applied on line item level, and just calculated them inside the line item price to further prevent the vat calculation