Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 526967 - Contributions: Allow the user to set the PayPal form lan…
…guage

Port from remora fix
  • Loading branch information
nmaier authored and Jeff Balogh committed Sep 22, 2010
1 parent e07502c commit bcbc48a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
16 changes: 16 additions & 0 deletions apps/addons/tests/test_views.py
Expand Up @@ -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_
Expand All @@ -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
Expand Down Expand Up @@ -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')
15 changes: 12 additions & 3 deletions apps/addons/views.py
Expand Up @@ -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,
Expand All @@ -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({
Expand All @@ -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
12 changes: 12 additions & 0 deletions settings.py
Expand Up @@ -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()
Expand Down

0 comments on commit bcbc48a

Please sign in to comment.