From bcbc48afa4d54feee992219957f4d6c2f8dac327 Mon Sep 17 00:00:00 2001 From: Nils Maier Date: Wed, 15 Sep 2010 23:10:54 +0200 Subject: [PATCH] Bug 526967 - Contributions: Allow the user to set the PayPal form language Port from remora fix --- apps/addons/tests/test_views.py | 16 ++++++++++++++++ apps/addons/views.py | 15 ++++++++++++--- settings.py | 12 ++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/apps/addons/tests/test_views.py b/apps/addons/tests/test_views.py index 0fff743034d..a8f14c9e869 100644 --- a/apps/addons/tests/test_views.py +++ b/apps/addons/tests/test_views.py @@ -4,6 +4,7 @@ from django import test from django.conf import settings from django.core.cache import cache +from django.utils import translation from mock import Mock from nose.tools import eq_ @@ -14,6 +15,7 @@ import amo.test_utils from amo.helpers import urlparams from amo.urlresolvers import reverse +from addons import views from addons.models import Addon, AddonUser from users.models import UserProfile from tags.models import Tag, AddonTag @@ -618,3 +620,17 @@ def test_redirect_no_eula(self): r = self.client.get(reverse('addons.privacy', args=[11730]), follow=True) self.assertRedirects(r, reverse('addons.detail', args=[11730])) + + +def test_paypal_language_code(): + def check(lc): + d = views.contribute_url_params('bz', 32, 'name', 'url') + eq_(d['lc'], lc) + + check('US') + + translation.activate('it') + check('IT') + + translation.activate('ru-DE') + check('RU') diff --git a/apps/addons/views.py b/apps/addons/views.py index b3956022585..9342abb37f3 100644 --- a/apps/addons/views.py +++ b/apps/addons/views.py @@ -408,6 +408,14 @@ def contribute(request, addon_id): def contribute_url_params(business, addon_id, item_name, return_url, amount='', item_number='', monthly=False, comment=''): + + lang = translation.get_language() + try: + paypal_lang = settings.PAYPAL_COUNTRYMAP[lang] + except KeyError: + lang = lang.split('-')[0] + paypal_lang = settings.PAYPAL_COUNTRYMAP.get(lang, 'US') + # Get all the data elements that will be URL params # on the Paypal redirect URL. data = {'business': business, @@ -417,12 +425,13 @@ def contribute_url_params(business, addon_id, item_name, return_url, 'no_shipping': '1', 'return': return_url, 'charset': 'utf-8', + 'lc': paypal_lang, 'notify_url': "%s%s" % (settings.SERVICES_URL, reverse('amo.paypal'))} - if (not monthly): + if not monthly: data['cmd'] = '_donations' - if (amount): + if amount: data['amount'] = amount else: data.update({ @@ -432,7 +441,7 @@ def contribute_url_params(business, addon_id, item_name, return_url, 'a3': amount, # recurring contribution amount 'no_note': '1'}) # required: no "note" text field for user - if (comment): + if comment: data['custom'] = comment return data diff --git a/settings.py b/settings.py index 1aea380b06f..0ff716da545 100644 --- a/settings.py +++ b/settings.py @@ -88,6 +88,18 @@ # to load the internationalization machinery. USE_I18N = True +# Paypal is an awful place that doesn't understand locales. Instead they have +# country codes. This maps our locales to their codes. +PAYPAL_COUNTRYMAP = { + 'af': 'ZA', 'ar': 'EG', 'ca': 'ES', 'cs': 'CZ', 'cy': 'GB', 'da': 'DK', + 'de': 'DE', 'de-AT': 'AT', 'de-CH': 'CH', 'el': 'GR', 'en-GB': 'GB', + 'eu': 'BS', 'fa': 'IR', 'fi': 'FI', 'fr': 'FR', 'he': 'IL', 'hu': 'HU', + 'id': 'ID', 'it': 'IT', 'ja': 'JP', 'ko': 'KR', 'mn': 'MN', 'nl': 'NL', + 'pl': 'PL', 'ro': 'RO', 'ru': 'RU', 'sk': 'SK', 'sq': 'AL', 'sr': 'CS', + 'tr': 'TR', 'uk': 'UA', 'vi': 'VI', +} + + # The host currently running the site. Only use this in code for good reason; # the site is designed to run on a cluster and should continue to support that HOSTNAME = socket.gethostname()