summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerghei Mihai <smihai@entrouvert.com>2016-10-25 08:27:07 (GMT)
committerSerghei Mihai <smihai@entrouvert.com>2016-10-25 10:03:38 (GMT)
commit11ba668f42333cc3f595be6a54910992d8f42111 (patch)
treedc21f2a710f8f4c4e6835762723a668467cc4475
parent0432124e0a93c25a6217c265fabd436c5e4ba9cb (diff)
downloadeopayment-11ba668f42333cc3f595be6a54910992d8f42111.zip
eopayment-11ba668f42333cc3f595be6a54910992d8f42111.tar.gz
eopayment-11ba668f42333cc3f595be6a54910992d8f42111.tar.bz2
ogone: fix response parameters encoding (#13728)v1.16
-rw-r--r--eopayment/ogone.py10
-rw-r--r--tests/test_ogone.py22
2 files changed, 26 insertions, 6 deletions
diff --git a/eopayment/ogone.py b/eopayment/ogone.py
index e7c4569..1c43e25 100644
--- a/eopayment/ogone.py
+++ b/eopayment/ogone.py
@@ -6,7 +6,7 @@ from decimal import Decimal, ROUND_HALF_UP
from common import (PaymentCommon, PaymentResponse, FORM, CANCELLED, PAID,
ERROR, Form, DENIED, ACCEPTED, ORDERID_TRANSACTION_SEPARATOR,
- ResponseError, force_byte)
+ ResponseError, force_byte, force_text)
def N_(message): return message
ENVIRONMENT_TEST = 'TEST'
@@ -494,7 +494,7 @@ class Payment(PaymentCommon):
# arrondi comptable francais
amount = amount.quantize(Decimal('1.'), rounding=ROUND_HALF_UP)
params = {
- 'AMOUNT': amount,
+ 'AMOUNT': unicode(amount),
'ORDERID': reference,
'PSPID': self.pspid,
'LANGUAGE': language,
@@ -517,7 +517,7 @@ class Payment(PaymentCommon):
params['SHASIGN'] = self.sha_sign_in(params)
# uniformize all values to UTF-8 string
for key in params:
- params[key] = unicode(params[key]).encode('utf-8')
+ params[key] = force_text(params[key])
url = self.get_request_url()
form = Form(
url=url,
@@ -532,6 +532,10 @@ class Payment(PaymentCommon):
params = dict((key.upper(), params[key][0]) for key in params)
if not set(params) >= set(['ORDERID', 'PAYID', 'STATUS', 'NCERROR']):
raise ResponseError()
+
+ # uniformize iso-8859-1 encoded values
+ for key in params:
+ params[key] = force_text(params[key], 'iso-8859-1')
reference = params['ORDERID']
transaction_id = params['PAYID']
status = params['STATUS']
diff --git a/tests/test_ogone.py b/tests/test_ogone.py
index ba7e8d7..f13aa6e 100644
--- a/tests/test_ogone.py
+++ b/tests/test_ogone.py
@@ -49,14 +49,30 @@ class OgoneTests(TestCase):
self.assertIn(name, values)
self.assertEqual(node.attrib['value'], values[name])
- def test_response(self):
+ def test_unicode_response(self):
ogone_backend = eopayment.Payment('ogone', BACKEND_PARAMS)
order_id = 'myorder'
- data = {'orderid': order_id + eopayment.common.ORDERID_TRANSACTION_SEPARATOR + 'RtEpMXZn4dX8k1rYbwLlby',
- 'payid': '32100123', 'status': 9, 'ncerror': 0}
+ data = {'orderid': u'myorder', 'status': u'9', 'payid': u'3011229363',
+ 'cn': u'Usér', 'ncerror': u'0',
+ 'trxdate': u'10/24/16', 'acceptance': u'test123',
+ 'currency': u'eur', 'amount': u'7.5',
+ 'shasign': u'3EE0CF69B5A8514962C9CF8A545861F0CA1C6891'}
+ # uniformize to utf-8 first
+ for k in data:
+ data[k] = eopayment.common.force_byte(data[k])
response = ogone_backend.response(urllib.urlencode(data))
+ assert response.signed
self.assertEqual(response.order_id, order_id)
+ def test_iso_8859_1_response(self):
+ ogone_backend = eopayment.Payment('ogone', BACKEND_PARAMS)
+ order_id = 'lRXK4Rl1N2yIR3R5z7Kc'
+ backend_response = 'orderID=lRXK4Rl1N2yIR3R5z7Kc&currency=EUR&amount=7%2E5&PM=CreditCard&ACCEPTANCE=test123&STATUS=9&CARDNO=XXXXXXXXXXXX9999&ED=0118&CN=Miha%EF+Serghe%EF&TRXDATE=10%2F24%2F16&PAYID=3011228911&NCERROR=0&BRAND=MasterCard&IP=80%2E12%2E92%2E47&SHASIGN=435D5E36E1F4B17739C1054FFD204218E65C15AB'
+ response = ogone_backend.response(backend_response)
+ assert response.signed
+ self.assertEqual(response.order_id, order_id)
+
+
def test_bad_response(self):
ogone_backend = eopayment.Payment('ogone', BACKEND_PARAMS)
order_id = 'myorder'