ogone: handle properly unicode params (#13592)
This commit is contained in:
parent
14f3ad8389
commit
d6b80acd02
|
@ -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)
|
||||
ResponseError, force_byte)
|
||||
def N_(message): return message
|
||||
|
||||
ENVIRONMENT_TEST = 'TEST'
|
||||
|
@ -458,9 +458,10 @@ class Payment(PaymentCommon):
|
|||
values = params.items()
|
||||
values = [(a.upper(), b) for a, b in values]
|
||||
values = sorted(values)
|
||||
values = ['%s=%s' % (a, b) for a, b in values if a in keep]
|
||||
values = [u'%s=%s' % (a, b) for a, b in values if a in keep]
|
||||
tosign = key.join(values)
|
||||
tosign += key
|
||||
tosign = force_byte(tosign)
|
||||
hashing = getattr(hashlib, algo)
|
||||
return hashing(tosign).hexdigest().upper()
|
||||
|
||||
|
@ -513,10 +514,10 @@ class Payment(PaymentCommon):
|
|||
params['COM'] = description
|
||||
for key, value in kwargs.iteritems():
|
||||
params[key.upper()] = value
|
||||
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['SHASIGN'] = self.sha_sign_in(params)
|
||||
url = self.get_request_url()
|
||||
form = Form(
|
||||
url=url,
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from unittest import TestCase
|
||||
import urllib
|
||||
|
||||
|
@ -5,13 +7,14 @@ import eopayment
|
|||
import eopayment.ogone as ogone
|
||||
from eopayment import ResponseError
|
||||
|
||||
PSPID = '2352566'
|
||||
PSPID = u'2352566ö'
|
||||
|
||||
BACKEND_PARAMS = {
|
||||
'environment': ogone.ENVIRONMENT_TEST,
|
||||
'pspid': PSPID,
|
||||
'sha_in': 'secret',
|
||||
'sha_out': 'secret'
|
||||
'sha_in': u'sécret',
|
||||
'sha_out': u'sécret',
|
||||
'automatic_return_url': u'http://example.com/autömatic_réturn_url'
|
||||
}
|
||||
|
||||
class OgoneTests(TestCase):
|
||||
|
@ -19,7 +22,7 @@ class OgoneTests(TestCase):
|
|||
def test_request(self):
|
||||
ogone_backend = eopayment.Payment('ogone', BACKEND_PARAMS)
|
||||
amount = '42.42'
|
||||
order_id = 'myorder'
|
||||
order_id = u'my ordér'
|
||||
reference, kind, what = ogone_backend.request(amount=amount,
|
||||
orderid=order_id, email='foo@example.com')
|
||||
self.assertEqual(len(reference), 30)
|
||||
|
@ -30,7 +33,7 @@ class OgoneTests(TestCase):
|
|||
self.assertEqual(root.attrib['method'], 'POST')
|
||||
self.assertEqual(root.attrib['action'], ogone.ENVIRONMENT_TEST_URL)
|
||||
values = {
|
||||
'CURRENCY': 'EUR',
|
||||
'CURRENCY': u'EUR',
|
||||
'ORDERID': reference,
|
||||
'PSPID': PSPID,
|
||||
'EMAIL': 'foo@example.com',
|
||||
|
|
Loading…
Reference in New Issue