paid subscription - little paypal IPN language patch (SMF2-RC2)

Started by thomasdev, February 17, 2010, 08:32:34 AM

Previous topic - Next topic

thomasdev

i faced the problem that my paypal account was in german and i needed to add the language information into the data pushed to the paypal IPN. So i thought this could be helpful for others as well:

the patched paypal gateway code:

--- ../backups/Subscriptions-PayPal.php     2009-11-08 23:19:37.000000000 +0000
+++ ./Subscriptions-PayPal.php  2010-02-17 13:25:53.000000000 +0000
@@ -35,6 +35,18 @@

                $setting_data = array(
                        array('text', 'paypal_email', 'subtext' => $txt['paypal_email_desc']),
+                       array('select', 'paypal_language', array(
+                               'default' => '(Default Account Language)',
+                               'user' => '(Try to use member\'s language settings)',
+                               'FR' => 'Force to French',
+                               'ES' => 'Force to Spanish',
+                               'IT' => 'Force to Italian',
+                               'DE' => 'Force to German',
+                               'CN' => 'Force to Chinese',
+                               'JP' => 'Force to Japanese',
+                               'US' => 'Force to English'),
+                               'subtext' => $txt['paypal_language_desc']),
+                               // TODO: extend this list properly ...
                );

                return $setting_data;
@@ -51,7 +63,7 @@
        // What do we want?
        public function fetchGatewayFields($unique_id, $sub_data, $value, $period, $return_url)
        {
-               global $modSettings, $txt, $boardurl;
+               global $modSettings, $txt, $boardurl, $user_info;

                $return_data = array(
                        'form' => 'https://www.' . (!empty($modSettings['paidsubs_test']) ? 'sandbox.' : '') . 'paypal.com/cgi-bin/webscr',
@@ -70,6 +83,20 @@
                $return_data['hidden']['currency_code'] = strtoupper($modSettings['paid_currency_code']);
                $return_data['hidden']['no_shipping'] = 1;
                $return_data['hidden']['no_note'] = 1;
+               if(!empty($modSettings['paypal_language']) && $modSettings['paypal_language'] == 'user')
+               {
+                       if($user_info['language'] == 'english')
+                               $return_data['hidden']['lc'] = 'US';
+                       else if($user_info['language'] == 'german')
+                               $return_data['hidden']['lc'] = 'DE';
+                       else if($user_info['language'] == 'french')
+                               $return_data['hidden']['lc'] = 'FR';
+                       else if($user_info['language'] == 'spanish')
+                               $return_data['hidden']['lc'] = 'ES';
+
+               } else if(!empty($modSettings['paypal_language']) && $modSettings['paypal_language'] != 'default')
+                       $return_data['hidden']['lc'] = $modSettings['paypal_language'];
+
                $return_data['hidden']['amount'] = $value;
                $return_data['hidden']['cmd'] = !$sub_data['repeatable'] ? '_xclick' : '_xclick-subscriptions';
                $return_data['hidden']['return'] = $return_url;


two new texts:

$txt['paypal_language'] = 'Paypal Login page Language';
$txt['paypal_language_desc'] = 'You can use this if you want to use another language for the login page as your profile language.';


someone should add all possible language codes into this ;)

Norv

Thank you for sharing this!
I will add this idea on the bug/feature tracker, since it seems to me something the developers could look into adding to the core code.
To-do lists are for deferral. The more things you write down the later they're done... until you have 100s of lists of things you don't do.

File a security report | Developers' Blog | Bug Tracker


Also known as Norv on D* | Norv N. on G+ | Norv on Github

Fussilet


Fussilet


Advertisement: