Commits

Mikhail Korobov committed 4810bd0

Postback fix

Comments (0)

Files changed (3)

 
 POSTBACK_URL = 'https://www.payfast.co.za/eng/query/validate'
 
+def _values_to_encode(data):
+    return [
+        (k, unicode(data[k]).encode('utf8'),)
+        for k in data if data[k] and k != 'signature'
+    ]
+
 def _signature_string(data):
-    values = [(k, unicode(data[k]).encode('utf8'),) for k in data if data[k]]
+    values = _values_to_encode(data)
     return urlencode(values)
 
 def siganture(data):
     text = _signature_string(data)
     return md5(text).hexdigest()
 
-def data_is_valid(raw_post_data, postback_url=POSTBACK_URL):
+def data_is_valid(post_data, postback_url=POSTBACK_URL):
     """
     Validates data via the postback. Returns True if data is valid,
     False if data is invalid and None if the request failed.
     """
+    post_str = urlencode(_values_to_encode(post_data))
     try:
-        response = urllib2.urlopen(postback_url, raw_post_data).read()
+        response = urllib2.urlopen(postback_url, post_data).read()
     except urllib2.HTTPError:
         return None
     if response == 'VALID':
             raise forms.ValidationError('untrusted ip: %s' % self.ip)
 
         if conf.USE_POSTBACK:
-            if not data_is_valid(self.request.raw_post_data):
+            if not data_is_valid(self.request.POST):
                 raise forms.ValidationError('Request validation fails')
 
         return self.cleaned_data
 
 setup(
     name='django-payfast',
-    version='0.1.3',
+    version='0.1.4',
     author='Mikhail Korobov',
     author_email='kmike84@gmail.com',