ogone: fix response parameters encoding (#13728)
This commit is contained in:
parent
0432124e0a
commit
11ba668f42
|
@ -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']
|
||||
|
|
|
@ -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¤cy=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'
|
||||
|
|
Loading…
Reference in New Issue