Permalink
Browse files

Encode IPN data based on request from PayPal, otherwise

IPN will not work/there will be an encoding error. This
is better than simply encoding as UTF-8 as what the
data needs to be encoded as depends on the account settings.

We also have to set encoding on the request object in order
for Django to pick up that the encoding is whatever it is
as opposed to assuming it's UTF-8.
  • Loading branch information...
1 parent a28544c commit be5d477375566d59599d00bdf7384e3b377e3ec9 @radiosilence radiosilence committed Mar 6, 2013
Showing with 10 additions and 4 deletions.
  1. +10 −4 mamona/backends/paypal/views.py
@@ -7,7 +7,7 @@
from mamona.signals import return_urls_query
import urllib2
-from django.utils.http import urlencode
+from urllib import urlencode
from decimal import Decimal
def return_from_gw(request, payment_id):
@@ -41,9 +41,15 @@ def ipn(request):
backend='paypal')
except (KeyError, ValueError):
return HttpResponseBadRequest()
-
- data = list(request.POST.items())
- data.insert(0, ('cmd', '_notify-validate'))
+ charset = request.POST.get('charset', 'UTF-8')
+ request.encoding = charset
+ data = request.POST.dict()
+ data['cmd'] = '_notify-validate'
+
+ # Encode data as PayPal wants it.
+ for k, v in data.items():
+ data[k] = v.encode(charset)
+
udata = urlencode(data)
url = get_backend_settings('paypal')['url']
r = urllib2.Request(url)

0 comments on commit be5d477

Please sign in to comment.