This issue is different than https://drupal.org/node/1787172 and might be similar to https://drupal.org/node/2013883.
now the issue
site's default currency is set to INR (indian rupees)
paypal's Primary currency is set to USD , as INR is not supported yet.
https://drupal.org/project/commerce_multicurrency is used to convert INR to USD.
I am testing a flow with live paypal account, when trying to navigating to paypal using express checkout button error is displaying
The totals of the cart item amounts do not match order amounts
PayPal API request to https://api-3t.paypal.com/nvp:
Array
(
[METHOD] => SetExpressCheckout
[SOLUTIONTYPE] => Sole
[LANDINGPAGE] => Billing
[ALLOWNOTE] => 0
[PAYMENTREQUEST_0_PAYMENTACTION] => Sale
[PAYMENTREQUEST_0_AMT] => 900.00
[PAYMENTREQUEST_0_CURRENCYCODE] => USD
[PAYMENTREQUEST_0_INVNUM] => 25-1383049878
[RETURNURL] => http://xxxtest.org/checkout/25/payment/return/X2a6r1fwFlVQe-2E7TKHUVzuNuHrxHYsA8M9b9v51eA
[CANCELURL] => http://xxxtest.org/checkout/25/payment/back/X2a6r1fwFlVQe-2E7TKHUVzuNuHrxHYsA8M9b9v51eA
[L_PAYMENTREQUEST_0_NAME0] => Basic testing for INR
[L_PAYMENTREQUEST_0_AMT0] => 14.63
[L_PAYMENTREQUEST_0_QTY0] => 1
[L_PAYMENTREQUEST_0_NUMBER0] => basic_test_inr
[PAYMENTREQUEST_0_ITEMAMT] => 14.63
[PAYMENTREQUEST_0_TAXAMT] => 0.00
[NOSHIPPING] => 1
[USER] => xxxxxxxxxx_api1.gmail.com
[PWD] => XXXXXXXXXXXXXXXX
[SIGNATURE] => XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[VERSION] => 76.0
)
PayPal server response:
Array
(
[TIMESTAMP] => 2013-10-29T12:21:40Z
[CORRELATIONID] => 5a8aaa42eb654
[ACK] => Failure
[VERSION] => 76.0
[BUILD] => 8275157
[L_ERRORCODE0] => 10413
[L_SHORTMESSAGE0] => Transaction refused because of an invalid argument. See additional error messages for details.
[L_LONGMESSAGE0] => The totals of the cart item amounts do not match order amounts.
[L_SEVERITYCODE0] => Error
)
I don't get whether this is rounding problem or something else is causing.Attached is the Commerce Multicurrency settings screenshot.
Comment | File | Size | Author |
---|---|---|---|
#16 | 2123005-multicurrency.patch | 3.72 KB | tko |
#13 | 2123005-13.patch | 3.97 KB | mglaman |
#7 | fix_conversion_multicurrency_not_supported_currencies-2123005-7.patch | 4.8 KB | Marko B |
#5 | fix_conversion_multicurrency_not_supported_currencies-2123005-5.patch | 6.67 KB | Marko B |
#4 | Screen Shot 2016-05-13 at 12.18.00.png | 400.03 KB | Marko B |
Comments
Comment #1
linitrex CreditAttribution: linitrex commentedIn functions:
function commerce_paypal_ec_set_express_checkout($payment_method, $order, $flow)
function commerce_paypal_ec_do_payment($payment_method, $order, $charge)
Replace:
'PAYMENTREQUEST_0_AMT' => commerce_paypal_price_amount($amount, $currency_code)
with
'PAYMENTREQUEST_0_AMT' => commerce_paypal_price_amount(commerce_currency_convert($order_total['amount'], $order_total['currency_code'], $currency_code), $currency_code)
to convert the Order total amount from local to the payment currency used by PayPal
Comment #2
andyg5000It's not fixed unless it's committed to the project. Marking back as active. Thanks for your suggestion. If you could put your update in a patch that would help speed things along.
Comment #3
torgosPizzaIt does appear that the currency is converted already in commerce_paypal_ec_do_payment() as there is a call to alter the $amount before it is added to the $nvp array like so:
So really this only needs to change in commerce_paypal_ec_set_express_checkout(). Patch attached.
Comment #4
Marko B CreditAttribution: Marko B commentedThere is also another problem when using currencies that are not supported and need to convert to dollars (or default currency).
I will demonstrate it with picture. So when buying more products, like 2x of one and 2x of another. There is a high chance the conversion will be wrong by one decimal at least. For example, you can see my picture, and see that PAYMENTREQUEST_0_AMT equals PAYMENTREQUEST_0_ITEMAMT but if you count the total of line items in
L_PAYMENTREQUEST_0_NUMBER_$i it will be 387,7. Which will break the payment as PP checks the sum of totals of line items and you will get the
"REDIRECT TO PAYPAL EXPRESS CHECKOUT FAILED. PLEASE TRY AGAIN OR CONTACT AN ADMINISTRATOR TO RESOLVE THE ISSUE."
With
Comment #5
Marko B CreditAttribution: Marko B commentedI made a patch that will fix above issue, which normalizes total amount according to line items total if totals miss-match.
Comment #6
tko CreditAttribution: tko commentedMarko, patch seems to be working however if there is a shipping line item its not being converted. It just gets a changed currency symbol.
Comment #7
Marko B CreditAttribution: Marko B commentedOk I made new patch, this one solves Shipping also, but also there were few problems with old one.
Please needs review. this is also a critical thing for, well most of the world :)
Comment #8
adrien.felipe CreditAttribution: adrien.felipe commentedPatch #7 have solved the issue for me. Thanks.
Comment #9
tonysbag CreditAttribution: tonysbag commented#7 works! thank u Marko!
Comment #10
bnadem CreditAttribution: bnadem commentedHi everybody,
patch#7 works! thank you Marko!
Comment #11
torgosPizzaSounds like it's RTBC?
Comment #12
mglamanThis is a breaking change. NVP needs to default to an empty array
$amt is no longer used
Comment #13
mglamanHere is a new version of the patch, which has only has the logic in
commerce_paypal_ec_itemize_order
updated for better math and currency conversion handled. Along with the ensured currency conversion inPAYMENTREQUEST_0_AMT
.Comment #14
mglamanThis needs manual testing in order to commit. INR is now supported by PayPal, so a different currency will have to be tested.
Comment #15
rafiqasad CreditAttribution: rafiqasad commentedHello,
This patch is not working with commerce_paypal 7.x-2.6 and 7..x-2.7. This patch is also not inclued/fixed in the updated version.
Best Regards,
Comment #16
tko CreditAttribution: tko commentedUpdated mglaman's patch from #13 to work on latest dev