CMS MADE SIMPLE FORGE

PaypalGateway

 

[#4300] Decimal item amount if $config['locale'] = 'de_DE.UTF8';

avatar
Created By: Sofia Hauschildt (sonya)
Date Submitted: Thu Nov 12 12:30:29 -0500 2009

Assigned To:
Version: 2.1.3
CMSMS Version: None
Severity: Critical
Resolution: None
State: Open
Summary:
Decimal item amount if $config['locale'] = 'de_DE.UTF8';
Detailed Description:
PayPal returns the error on trying to checkout:
---------------------------------------------
"The link you have used to enter the PayPal system contains an incorrectly
formatted item amount."
-------------------------------------------

In the config.php on the installation with the issue there is a German locale:
$config['locale'] = 'de_DE.UTF8';

It's weird, but sprinf functions does change the decimal point to comma if
$config['locale'] is not English.

Try this test.php
--------------------------------------------------
<?php
  setlocale (LC_ALL, 'de_DE.UTF8');
  $key = "field";  
  $value = 2.4;
  $fmt = 'input type="hidden" name="%s" value="%s"/>'."\n";     
  echo sprintf($fmt,$key,$value);
?>

You will see that sprintf() changes the number format to:
<input type="hidden" name="field" value="2,4"/> 

If you comment the setlocale() in the first line the output will be correct:
input type="hidden" name="field" value="2.4"/> 


History

Comments
avatar
Date: 2009-11-12 13:20
Posted By: Robert Campbell (calguy1000)

try using:
echo sprintf($fmt,$key,(string)$value);

to force the value to be interpreted as a string.
      
avatar
Date: 2009-11-12 13:43
Posted By: Sofia Hauschildt (sonya)

Thank you for the quick answer. I have pasted the code suggested to my test.php:
----------------------------------
echo sprintf($fmt,$key,(string)$value); // does not work

I have also tried
--------------------------------
echo sprintf($fmt,$key,strval($value)); // does not work
echo sprintf($fmt,$key,var_export($value)); // does not work  


For me, I have made an ugly and dirty correction in the module:
$str .= sprintf($fmt,$key,str_replace(',','.',$value));  

But this surely cannot be a general solution.
      
avatar
Date: 2009-11-13 08:16
Posted By: Sofia Hauschildt (sonya)

I have found the solution that works with 
$config['locale'] = 'de_DE.UTF8';
and
$config['locale'] = '';

Replace any sprintf() in PaypalGateway.module.php with

number_format([VALUE], 2, '.', ',')

Thanks to Peciura! 
http://forum.cmsmadesimple.org/index.php/topic,39024.msg184795.html#msg184795
      
Updates

Updated: 2009-11-12 13:20
resolution_id: => 5