Magento2: With certain currencies invalid amount is sent to Paypal

Created on 18 Sep 2017  Â·  16Comments  Â·  Source: magento/magento2


Preconditions


  1. Magento 2.1.6
  2. php 5.6

Steps to reproduce

  1. [ADMIN] Select HUF (Hungarian forint) as base & display currency
  2. [ADMIN] Turn on Paypal Express checkout
  3. [FRONTEND] Start checkout flow
  4. [FRONTEND] Try paying with Paypal

Expected result


User can successfully pay

Actual result


Paypal error is thrown, user is unable to pay via Paypal

Error message:
PayPal gateway has rejected request. Item total is invalid (#10426: Transaction refused because of an invalid argument. See additional error messages for details). Tax total is invalid (#10429: Transaction refused because of an invalid argument. See additional error messages for details).

Logs:
Here's the relevant part of the array:
main.DEBUG: array ( 'url' => 'https://api-3t.paypal.com/nvp', 'SetExpressCheckout' => array ( 'PAYMENTACTION' => 'Sale', 'AMT' =>'2990.00', 'CURRENCYCODE' => 'HUF', 'SHIPPINGAMT' =>'0.00', 'ITEMAMT' =>'2354.33', 'TAXAMT' => '635.67',

Compare this with Paypal's official Currency Code advice for developers:

Hungarian Forint | HUF Note: Decimal amounts are not supported for this currency. Passing a decimal amount will throw an error.

Clear Description Confirmed Format is valid Ready for Work P3 ready for dev Reproduced on 2.1.x Reproduced on 2.2.x Reproduced on 2.3.x Reproduced on 2.4.x S3

Most helpful comment

Why would this be a feature request and not a bug?

@zzvara @simonattilahun this is how I've been working around this for now:
(Depending on which Paypal payment method you use the actual file and methods to modify might be different. I've had to set up express checkout, so that's what you find covered below.)

In vendor/magento/module-paypal/Model/Api/Nvp.php update the public fun callSetExpressCheckout():

// Paypal does not accept decimals for HUF, JPY, TWD
        $request['AMT'] = round($request['AMT'], 0);
        $request['SHIPPINGAMT'] = round($request['SHIPPINGAMT'], 0);
        $request['ITEMAMT'] = round($request['ITEMAMT'], 0);
        $request['TAXAMT'] = round($request['TAXAMT'], 0);

Then you have to add rounding to a different function as well -- callDoExpressCheckoutPayment()

// Paypal does not accept decimals for HUF, JPY, TWD
        $request['AMT'] = round($request['AMT'], 0);
        $request['SHIPPINGAMT'] = round($request['SHIPPINGAMT'], 0);
        $request['ITEMAMT'] = round($request['ITEMAMT'], 0);
        $request['TAXAMT'] = round($request['TAXAMT'], 0);

I added both just above the function calling the response.

All 16 comments

Interesting case!

'AMT' =>'2990.00', 'ITEMAMT' =>'2354.33', 'TAXAMT' => '635.67',
So what would be the valid values in such case?

Full list of such currencies seem to be: HUF, JPY, TWD.

@orlangur My opinion is we should do simple rounding, taking the total amount as basis. In this case:

'AMT' => '2990', 'ITEMAMT' => '2354', 'TAXAMT' => '636',

Thanks for your input! Ideally it would be nice to have some legal information for reference how rounding is supposed to occur in your country.

Did you try to play with configuration a bit, like suggested in https://stackoverflow.com/a/28909775 by the way?

I'll take a look but I don't know from the top of my head where such official, sanctioned information may be found. (Not to mention other countries with this issue.) I hope that wouldn't halt any - potential - progress on this.

Yes, I did try it but it doesn't matter. I tried this and a bunch of other things before opening this ticket. M2 is going to be still sending amounts with decimals in place regardless of any of these changes so it will be denied by Paypal.

Ok, thanks. Well, as a quick'n'dirty workaround you can still create an around plugin for \Magento\Directory\Model\PriceCurrency::round which does round($price, 0) but not sure how it will work with all other price-modifying features.

I was thinking about that but for now I just really needed something to work so I hacked the Paypal Nvp request at \Magento\Paypal\Model\Api\Nvp::callSetExpressCheckout.

That seems to work well for now, but I will re-visit this and try to come up with a proper solution later.

Hi, @pvj, this is known issue, Magento doesn't resolve zero-decimal currencies like HUF, JPY, TWD, etc. We already have the internal ticket (MAGETWO-56451) but I can't provide any estimation.

So, are there any solution for the HUF rounding problem? We try to implement a store on Community Edition 2.2.1 This seems to be a blocking issue preventing us to go live with PayPal payments as PayPal is sending an error message assumably because of the tax calculation rounding issue. (Zero digit rounding is needed)

This is a blocker for us as well.

I'm not at home currently but I can show you my hack that I've employed
until this is fixed.

On 11 Dec 2017 13:51, "Zoltán Zvara" notifications@github.com wrote:

This is a blocker for us as well.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/magento/magento2/issues/10954#issuecomment-350715631,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AChPf4AqZyGkaaqFyE17NmZG15IxiBrZks5s_SVhgaJpZM4Pa-xY
.

That would be great, thanks! :-)
On 2017-12-11 14:14:24, pvj notifications@github.com wrote:
I'm not at home currently but I can show you my hack that I've employed
until this is fixed.

On 11 Dec 2017 13:51, "Zoltán Zvara" notifications@github.com wrote:

This is a blocker for us as well.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/magento/magento2/issues/10954#issuecomment-350715631,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AChPf4AqZyGkaaqFyE17NmZG15IxiBrZks5s_SVhgaJpZM4Pa-xY
.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub [https://github.com/magento/magento2/issues/10954#issuecomment-350720680], or mute the thread [https://github.com/notifications/unsubscribe-auth/AH--TXgA16PI-InQ6so-yEGzk1erX63Kks5s_SqvgaJpZM4Pa-xY].

Hi @pvj. Thank you for the report. We are moving your feature request to the special project. You can track this issue here: https://github.com/magento-engcom/community-features/issues/22

@magento-engcom-team Is this a feature request not a bug?

Why would this be a feature request and not a bug?

@zzvara @simonattilahun this is how I've been working around this for now:
(Depending on which Paypal payment method you use the actual file and methods to modify might be different. I've had to set up express checkout, so that's what you find covered below.)

In vendor/magento/module-paypal/Model/Api/Nvp.php update the public fun callSetExpressCheckout():

// Paypal does not accept decimals for HUF, JPY, TWD
        $request['AMT'] = round($request['AMT'], 0);
        $request['SHIPPINGAMT'] = round($request['SHIPPINGAMT'], 0);
        $request['ITEMAMT'] = round($request['ITEMAMT'], 0);
        $request['TAXAMT'] = round($request['TAXAMT'], 0);

Then you have to add rounding to a different function as well -- callDoExpressCheckoutPayment()

// Paypal does not accept decimals for HUF, JPY, TWD
        $request['AMT'] = round($request['AMT'], 0);
        $request['SHIPPINGAMT'] = round($request['SHIPPINGAMT'], 0);
        $request['ITEMAMT'] = round($request['ITEMAMT'], 0);
        $request['TAXAMT'] = round($request['TAXAMT'], 0);

I added both just above the function calling the response.

Framework Level Support for Non-Decimal Currencies https://jira.corp.magento.com/browse/MC-23213

I believe the functionality failure for the specific currencies that are available in Magento is a bug rather than a feature. Closed the feature request and reopened the original issue

Was this page helpful?
0 / 5 - 0 ratings