Jump to content

[Solved] How to switch the code of "ps_round" (in Cart.php) depends on the customer's currency?


Recommended Posts

Hi!

I'm testing the web-site to sell the product from Swiss to Japanese customer.

 

There is a problem when I set the default currency to Swiss Franc (CHF),
and in the setting of payment "Currency restrictions" I choose " customer's currency" to paypal module.

I want to make our site possible to purchase in currency of JPY in paypal,
but there is a problem of decimal, (JPY is no decimal currency) and paypal doesn't work.

 

I found a solution by changing Cart.php.

 

(via : http://www.prestashop.com/forums/topic/169541-help-paypal-rejection-error-due-to-rounding-non-decimal-currency/ )

 

before

$total_price = Tools::ps_round($total_price + $total_ecotax, 2);

to

$total_price = Tools::ps_round($total_price + $total_ecotax, 0);

After that, paypal works in the currency of JPY, it's good, but on the other hand, when the customer want to purchase in CHF, the price will be incorrect (  the product of "20,5 CHF" will be "20 CHF" in the shopping cart... )

 

 

So now I'm looking for a way to switch some codes of "Cart.php" depends on the customer's currency.

I'm not a programer, not familiar with PHP...

Please your help!

Thank you in advance.

 

Edited by tatamimi (see edit history)
Link to comment
Share on other sites

Thank you El Patron for your quick reply.

I did the setting as you do but after click the button "pay with paypal", always the error occurs like this.
 

 
Error occurred:

Please try to contact the merchant:

  1. <b>PayPal response:</b>
  2. TIMESTAMP -> 2014-08-01T12:44:49Z
  3. L_ERRORCODE0 -> 10401
  4. L_ERRORCODE1 -> 10427
  5. L_ERRORCODE2 -> 10413
  6. L_SHORTMESSAGE0 -> Transaction refused because of an invalid argument. See additional error messages for details.
  7. L_SHORTMESSAGE1 -> Transaction refused because of an invalid argument. See additional error messages for details.
  8. L_SHORTMESSAGE2 -> Transaction refused because of an invalid argument. See additional error messages for details.
  9. L_LONGMESSAGE0 -> Order total is invalid.
  10. L_LONGMESSAGE1 -> Shipping total is invalid.
  11. L_LONGMESSAGE2 -> The totals of the cart item amounts do not match order amounts.
  12. L_SEVERITYCODE0 -> Error
  13. L_SEVERITYCODE1 -> Error
  14. L_SEVERITYCODE2 -> Error

 

I found some topic which says this is because on the screen, the amount is no-decimal (under decimal is not shown) but at the backend, the real amount exist which contain numbers under decimal also.

Please tell me your shop's default currency,  and your paypal customers restriction is also "customers currency" ?

 

note: my prestashop's version is 1.6.0.6. and I use module of "Paypal  v3.7.1"

Link to comment
Share on other sites

Hi sorry you having this issue, on the shop from screen capture default is EU, we like you selected customers currency.  Note: we do not have shipping or taxes and maybe this is why it works for us.  Also that is from 1.4.6.2 shop.

 

I am looking at all the old and 'unresolved' posts for this.  what a mess...if I can find anything I will report back here. 

 

the code above should be checking the currency decimal setting before taking action.

 

what is you exact paypal module version?  and US/Mexico/Canada or EU module.

 

(note it may be worth the effort to use 'other' paypal module, i.e.  if US then use EU and vice versa.

 

I have looked all over the forum and forge, loads of reports without fix.

 

Please open a new forge report here:

 

http://forge.prestashop.com

 

please paste that url back here so others can follow/comment/vote up.

  • Like 1
Link to comment
Share on other sites

Thank you for your advice El Patron (and your effort, it's so kind!).

I'm using Paypal (EU) and tested Paypal US/Mexico/Canada also.
With the 
US/Mexico/Canada version, the error is like this.

 

The link you have used to enter the PayPal system contains an incorrectly formatted item amount.

 

I made this topic in the forge.prestashop.com

http://forge.prestashop.com/browse/PSCSX-2923

 

(I want to re-edit title and some phrase... but I can't find the button for modification...)

 

I hope we can find the solution...

Anyway thank you a lot!

Link to comment
Share on other sites

I don't think that code would make any difference (cart,php), I have it in 1.4.6.2.

 

it's just weird your issue, I last sold in Yen in June without issue (no tax/no shipping/tax excluded groups).

 

I searched only saw couple posts with same yen issue, without resolution...stuff like this can drive one bonkers.

 

can you post the screen when you arrive at PayPal?

Link to comment
Share on other sites

I was more curious about the screen shot of when you first land on the PayPal screen, I am assuming it makes it that far.

 

this will help us understand if product price is  without decimals but say shipping or taxes is adding the decimals.

Link to comment
Share on other sites

Test this (I did not test) in Cart.php

	if ((int)($this->id_currency) == 'id of yen currency')
		$total_price = Tools::ps_round($total_price + $total_ecotax, 0);
	else
		$total_price = Tools::ps_round($total_price + $total_ecotax, 2);

where 'id of yen currency' = back office-->localization-->currencies-->on left id of yen

  • Like 1
Link to comment
Share on other sites

Finally!!! It works!
Thank you so much El Patron!!!

I changed Cart.php as you said.
At first it didn't work but after I changed all codes where contains "ps_round", it works!

Your advice is so much worthy and it helps me a lot!
(and it helps others also who have same problem)

Thank you very much, I appreciate you!
If you need some help of Japanese, feel free to contact me :lol: !
 

  • Like 1
Link to comment
Share on other sites

Finally!!! It works!

Thank you so much El Patron!!!

 

I changed Cart.php as you said.

At first it didn't work but after I changed all codes where contains "ps_round", it works!

 

Your advice is so much worthy and it helps me a lot!

(and it helps others also who have same problem)

 

Thank you very much, I appreciate you!

If you need some help of Japanese, feel free to contact me :lol: !

 

 

very good, so there were other ps_round logic that needed the same code yes?

 

could you attach a zipped file of your cart.php file for others reference in the future?

 

and you are very welcome, glad I could help, please visit the forum often and help others with your experience.

  • Like 1
Link to comment
Share on other sites

Thank you for your very kind message.

I changed the original Cart.php.

In my case, "1" is currency id of JPY.

 

Here are the lines to change in original Cart.php.

 

- line 592
- line 636

- line 1435

- line 1479

- line 1492   <-  I don't use gift wrapping, if you need it  you have to put the code of conditional branch here as others.

- line 1528

- line 1546

- line 1548

- line 2803

 

and put new Cart.php file in the "/override/classes/" folder.

(and delate cash file ( /cash/class_index.php))

 

I attach my new Cart.php. (How attach my file here...? I couldn't so I note link addres)

 

override.zip

 

Attention, I could'nt finish enough test, so please verify well before using.

Chao!
 

Edited by tatamimi (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 3 months later...

I've the same problem with yen because yen is a currency without decimal, and my solution is to override the method ps_round of class Tools by reset the precision:

 

public static function ps_round($value, $precision = 0)
    {
        static $method = null;

         // Added code to get the currency in use

         $context = Context::getContext();
         if($context->currency->iso_code_num == 392) $precision = 0;
         // Added code to get the currency in use

        if ($method == null)
            $method = (int)Configuration::get('PS_PRICE_ROUND_MODE');

        if ($method == PS_ROUND_UP)
            return Tools::ceilf($value, $precision);
        elseif ($method == PS_ROUND_DOWN)
            return Tools::floorf($value, $precision);
        return round($value, $precision);
    }

 

This work for me.

  • Like 2
Link to comment
Share on other sites

  • 1 year later...

Hi, I have 1.0.6.9 of prestashop and this form has always worked but today I received these emails whit this text:


Error reporting from your PayPalAPI module

A client has encountered a problem with the module PayPalAPI, see the report:

PayPal response: 
TIMESTAMP -> 2015-11-30T08:24:23Z 
L_ERRORCODE0 -> 10401 
L_ERRORCODE1 -> 10427 
L_ERRORCODE2 -> 10413 
L_SHORTMESSAGE0 -> Transaction refused because of an invalid argument. See additional error messages for details. 
L_SHORTMESSAGE1 -> Transaction refused because of an invalid argument. See additional error for details. 

L_SHORTMESSAGE2 -> Transaction refused because of an invalid argument. See additional error messages for details. 
L_LONGMESSAGE0 -> Order total is invalid. 
L_LONGMESSAGE1 -> Shipping total is invalid. 
L_LONGMESSAGE2 -> The totals of the cart item amounts do not match order amounts. 
L_SEVERITYCODE0 -> Error 
L_SEVERITYCODE1 -> Error 
L_SEVERITYCODE2 -> Error

post-1119372-0-96920100-1448874506_thumb.png

anyone can help me?

Link to comment
Share on other sites

  • 1 month later...

Hi, i should enable decimals for yen currency beacuse i have module that generate coupons and if i don't have decimals the amount is no correct. 

but if I enable decimals I have problems with paypal payment..anyone can help me?

Thanks in advance :)

Link to comment
Share on other sites

  • 6 months later...

I've the same problem with yen because yen is a currency without decimal, and my solution is to override the method ps_round of class Tools by reset the precision:

 

public static function ps_round($value, $precision = 0)

    {

        static $method = null;

 

         // Added code to get the currency in use

         $context = Context::getContext();

         if($context->currency->iso_code_num == 392) $precision = 0;

         // Added code to get the currency in use

 

        if ($method == null)

            $method = (int)Configuration::get('PS_PRICE_ROUND_MODE');

 

        if ($method == PS_ROUND_UP)

            return Tools::ceilf($value, $precision);

        elseif ($method == PS_ROUND_DOWN)

            return Tools::floorf($value, $precision);

        return round($value, $precision);

    }

 

This work for me.

thanks, this works for me too! saved me a lot of time!

Link to comment
Share on other sites

×
×
  • Create New...