summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSerghei Mihai <smihai@entrouvert.com>2016-02-08 17:40:45 (GMT)
committerSerghei Mihai <smihai@entrouvert.com>2016-02-16 14:56:56 (GMT)
commit8cd625e4651ededa92d888c31d64fafa578f2a9e (patch)
tree7f2a10d67c73a9c4763a4f8868bf2a2e5031b238 /tests
parent33ba732c91f08a3a2cfea7ebe8e277c6cd7881cb (diff)
downloadeopayment-8cd625e4651ededa92d888c31d64fafa578f2a9e.zip
eopayment-8cd625e4651ededa92d888c31d64fafa578f2a9e.tar.gz
eopayment-8cd625e4651ededa92d888c31d64fafa578f2a9e.tar.bz2
pass order id to all backends (#9941)
Diffstat (limited to 'tests')
-rw-r--r--tests/test_ogone.py54
-rw-r--r--tests/test_paybox.py52
2 files changed, 88 insertions, 18 deletions
diff --git a/tests/test_ogone.py b/tests/test_ogone.py
new file mode 100644
index 0000000..ee210dd
--- /dev/null
+++ b/tests/test_ogone.py
@@ -0,0 +1,54 @@
+from unittest import TestCase
+import urllib
+
+import eopayment
+import eopayment.ogone as ogone
+
+PSPID = '2352566'
+
+BACKEND_PARAMS = {
+ 'environment': ogone.ENVIRONMENT_TEST,
+ 'pspid': PSPID,
+ 'sha_in': 'secret',
+ 'sha_out': 'secret'
+}
+
+class OgoneTests(TestCase):
+
+ def test_request(self):
+ ogone_backend = eopayment.Payment('ogone', BACKEND_PARAMS)
+ amount = '42.42'
+ order_id = 'myorder'
+ reference, kind, what = ogone_backend.request(amount=amount,
+ orderid=order_id, email='foo@example.com')
+ self.assertEqual(len(reference), 30)
+ assert reference.startswith(order_id)
+ from xml.etree import ElementTree as ET
+ root = ET.fromstring(str(what))
+ self.assertEqual(root.tag, 'form')
+ self.assertEqual(root.attrib['method'], 'POST')
+ self.assertEqual(root.attrib['action'], ogone.ENVIRONMENT_TEST_URL)
+ values = {
+ 'CURRENCY': 'EUR',
+ 'ORDERID': reference,
+ 'PSPID': PSPID,
+ 'EMAIL': 'foo@example.com',
+ 'AMOUNT': amount.replace('.', ''),
+ 'LANGUAGE': 'fr_FR',
+ }
+ values.update({'SHASIGN': ogone_backend.backend.sha_sign_in(values)})
+ for node in root:
+ self.assertIn(node.attrib['type'], ('hidden', 'submit'))
+ self.assertEqual(set(node.attrib.keys()), set(['type', 'name', 'value']))
+ name = node.attrib['name']
+ if node.attrib['type'] == 'hidden':
+ self.assertIn(name, values)
+ self.assertEqual(node.attrib['value'], values[name])
+
+ def test_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}
+ response = ogone_backend.response(urllib.urlencode(data))
+ self.assertEqual(response.order_id, order_id)
diff --git a/tests/test_paybox.py b/tests/test_paybox.py
index 41b8da2..7e1e99f 100644
--- a/tests/test_paybox.py
+++ b/tests/test_paybox.py
@@ -1,18 +1,28 @@
from unittest import TestCase
from decimal import Decimal
import base64
+import urllib
import eopayment.paybox as paybox
import eopayment
+BACKEND_PARAMS = {
+ 'platform': 'test',
+ 'site': '12345678',
+ 'rang': '001',
+ 'identifiant': '12345678',
+ 'shared_secret': '0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF',
+ 'callback': 'http://example.com/callback',
+}
+
class PayboxTests(TestCase):
def test_sign(self):
key = '0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF'.decode('hex')
d = dict(paybox.sign([
- ['PBX_SITE', '1999888'],
+ ['PBX_SITE', '12345678'],
['PBX_RANG', '32'],
- ['PBX_IDENTIFIANT', '110647233'],
- ['PBX_TOTAL', '999'],
+ ['PBX_IDENTIFIANT', '12345678'],
+ ['PBX_TOTAL', '999'],
['PBX_DEVISE', '978'],
['PBX_CMD', 'TEST Paybox'],
['PBX_PORTEUR', 'test@paybox.com'],
@@ -21,25 +31,20 @@ class PayboxTests(TestCase):
['PBX_TIME', '2015-06-08T16:21:16+02:00'],
],
key))
- result = '7ABB5F7A31DF4C8976A44374D3BA2F9831E7927CFD62F774ED378F4E27471708F4EFE6D0BEFA44EBABCBD978B661C74E22EEB16DEF73A510E86D0A5C0E7B6D88'
+ result = '475FE1C45A0D09D26D2CAC9A1AC39C024773D790F50B6DD15B260F55FCD527FD3AD4AA3998F4162EFE9BDC494B9850A673355A32ACC4F85B67F8566037836F8E'
self.assertIn('PBX_HMAC', d)
self.assertEqual(d['PBX_HMAC'], result)
def test_request(self):
- key = '0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF'
- backend = eopayment.Payment('paybox', {
- 'platform': 'test',
- 'site': '12345678',
- 'rang': '001',
- 'identifiant': '12345678',
- 'shared_secret': key,
- 'callback': 'http://example.com/callback',
- })
+ backend = eopayment.Payment('paybox', BACKEND_PARAMS)
time = '2015-07-15T18:26:32+02:00'
email = 'bdauvergne@entrouvert.com'
+ order_id = '20160216'
+ transaction = '1234'
+ amount = '19.99'
transaction_id, kind, what = backend.request(
- Decimal('19.99'), email=email,
- transaction_id='1234', time=time)
+ Decimal(amount), email=email, orderid=order_id,
+ transaction_id=transaction, time=time)
self.assertEqual(kind, eopayment.FORM)
self.assertEqual(transaction_id, '1234')
from xml.etree import ElementTree as ET
@@ -54,6 +59,7 @@ class PayboxTests(TestCase):
if node.attrib['type'] == 'hidden':
self.assertEqual(set(node.attrib.keys()), set(['type', 'name', 'value']))
name = node.attrib['name']
+ reference = order_id + eopayment.common.ORDERID_TRANSACTION_SEPARATOR + transaction
values = {
'PBX_RANG': '01',
'PBX_SITE': '12345678',
@@ -61,17 +67,27 @@ class PayboxTests(TestCase):
'PBX_RETOUR': 'montant:M;reference:R;code_autorisation:A;erreur:E;signature:K',
'PBX_TIME': time,
'PBX_PORTEUR': email,
- 'PBX_CMD': '1234',
- 'PBX_TOTAL': '1999',
+ 'PBX_CMD': reference,
+ 'PBX_TOTAL': amount.replace('.', ''),
'PBX_DEVISE': '978',
'PBX_HASH': 'SHA512',
- 'PBX_HMAC': 'A0AA37FC3DD46F3233C0AD3BF95242CD71003D98F33DF85124E4423D53759A82A132EC2CC42B7234B22A75F00CF5DA124DF3A34331F3F6B9D7308B2EF09DCA3C',
+ 'PBX_HMAC': '173483CFF84A7ECF21039F99E9A95C5FB53D98A1562184F5B2C4543E4F87BFA227CC2CA10DE989D6C8B4DC03BC2ED44B7D7BDF5B4FABA8274D5D37C2F6445F36',
'PBX_ARCHIVAGE': '1234',
'PBX_REPONDRE_A': 'http://example.com/callback',
}
self.assertIn(name, values)
self.assertEqual(node.attrib['value'], values[name])
+ def test_response(self):
+ backend = eopayment.Payment('paybox', BACKEND_PARAMS)
+ order_id = '20160216'
+ transaction = '1234'
+ reference = order_id + eopayment.common.ORDERID_TRANSACTION_SEPARATOR + transaction
+ data = {'montant': '4242', 'reference': reference,
+ 'code_autorisation': 'A', 'erreur': '00000'}
+ response = backend.response(urllib.urlencode(data))
+ self.assertEqual(response.order_id, order_id)
+
def test_rsa_signature_validation(self):
pkey = '''-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDUgYufHuheMztK1LhQSG6xsOzb