summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerghei Mihai <smihai@entrouvert.com>2018-08-21 08:56:49 (GMT)
committerSerghei Mihai <smihai@entrouvert.com>2018-08-29 10:17:26 (GMT)
commit1e5aa020a3e53b62bed2212a2fa1ea9513abb838 (patch)
tree1fd0d12d555987d1602d2d8508083b52a1798d41
parentd142c1c8f82c995fd05cc6cbeff56ac4a94c0b74 (diff)
downloadeopayment-1e5aa020a3e53b62bed2212a2fa1ea9513abb838.zip
eopayment-1e5aa020a3e53b62bed2212a2fa1ea9513abb838.tar.gz
eopayment-1e5aa020a3e53b62bed2212a2fa1ea9513abb838.tar.bz2
paybox: add support for delayed payment (#25737)v1.28
-rw-r--r--eopayment/paybox.py10
-rw-r--r--tests/test_paybox.py59
2 files changed, 50 insertions, 19 deletions
diff --git a/eopayment/paybox.py b/eopayment/paybox.py
index 6e70143..3298672 100644
--- a/eopayment/paybox.py
+++ b/eopayment/paybox.py
@@ -208,6 +208,14 @@ class Payment(PaymentCommon):
'caption': _('Callback URL'),
'deprecated': True,
},
+ {
+ 'name': 'capture_day',
+ 'caption': _('Nombre de jours pour un paiement différé'),
+ 'default': '',
+ 'required': False,
+ 'validation': lambda x: isinstance(x, basestring) and
+ x.isdigit() and (1 <= len(x) <= 2)
+ },
]
}
@@ -240,6 +248,8 @@ class Payment(PaymentCommon):
warnings.warn("callback option is deprecated, "
"use automatic_return_url", DeprecationWarning)
automatic_return_url = self.callback
+ if self.capture_day:
+ d['PBX_DIFF'] = self.capture_day.zfill(2)
if automatic_return_url:
d['PBX_REPONDRE_A'] = force_text(automatic_return_url)
d = d.items()
diff --git a/tests/test_paybox.py b/tests/test_paybox.py
index abea656..8d7952a 100644
--- a/tests/test_paybox.py
+++ b/tests/test_paybox.py
@@ -5,6 +5,7 @@ from unittest import TestCase
from decimal import Decimal
import base64
from six.moves.urllib import parse as urllib
+from xml.etree import ElementTree as ET
import eopayment.paybox as paybox
import eopayment
@@ -51,11 +52,27 @@ class PayboxTests(TestCase):
transaction_id=transaction, time=time)
self.assertEqual(kind, eopayment.FORM)
self.assertEqual(transaction_id, '1234')
- 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'], paybox.URLS['test'])
+ expected_form_values = {
+ 'PBX_RANG': '01',
+ 'PBX_SITE': '12345678',
+ 'PBX_IDENTIFIANT': '12345678',
+ 'PBX_RETOUR': 'montant:M;reference:R;code_autorisation:A;erreur:E;signature:K',
+ 'PBX_TIME': time,
+ 'PBX_PORTEUR': email,
+ 'PBX_CMD': order_id + eopayment.common.ORDERID_TRANSACTION_SEPARATOR + transaction,
+ 'PBX_TOTAL': amount.replace('.', ''),
+ 'PBX_DEVISE': '978',
+ 'PBX_HASH': 'SHA512',
+ 'PBX_HMAC': '173483CFF84A7ECF21039F99E9A95C5FB53D98A1562184F5B2C4543E4F87BFA227CC2CA10DE989D6C8B4DC03BC2ED44B7D7BDF5B4FABA8274D5D37C2F6445F36',
+ 'PBX_ARCHIVAGE': '1234',
+ 'PBX_REPONDRE_A': 'http://example.com/callback',
+ }
+
+ form_params = {}
for node in root:
self.assertIn(node.attrib['type'], ('hidden', 'submit'))
if node.attrib['type'] == 'submit':
@@ -63,24 +80,28 @@ 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',
- 'PBX_IDENTIFIANT': '12345678',
- 'PBX_RETOUR': 'montant:M;reference:R;code_autorisation:A;erreur:E;signature:K',
- 'PBX_TIME': time,
- 'PBX_PORTEUR': email,
- 'PBX_CMD': reference,
- 'PBX_TOTAL': amount.replace('.', ''),
- 'PBX_DEVISE': '978',
- 'PBX_HASH': 'SHA512',
- 'PBX_HMAC': '173483CFF84A7ECF21039F99E9A95C5FB53D98A1562184F5B2C4543E4F87BFA227CC2CA10DE989D6C8B4DC03BC2ED44B7D7BDF5B4FABA8274D5D37C2F6445F36',
- 'PBX_ARCHIVAGE': '1234',
- 'PBX_REPONDRE_A': 'http://example.com/callback',
- }
- self.assertIn(name, values)
- self.assertEqual(node.attrib['value'], values[name])
+ form_params[name] = node.attrib['value']
+ self.assertEqual(form_params, expected_form_values)
+
+ def test_request_with_capture_day(self):
+ params = BACKEND_PARAMS.copy()
+ time = '2018-08-21T10:26:32+02:00'
+ email = 'user@entrouvert.com'
+ order_id = '20180821'
+ transaction = '1234'
+ amount = '42.99'
+
+ for capture_day in ('7', '07'):
+ params['capture_day'] = capture_day
+ backend = eopayment.Payment('paybox', params)
+ transaction_id, kind, what = backend.request(
+ Decimal(amount), email=email, orderid=order_id,
+ transaction_id=transaction, time=time)
+ root = ET.fromstring(str(what))
+
+ form_params = dict(((node.attrib['name'], node.attrib['value']) for node in root if node.attrib['type'] == 'hidden'))
+ self.assertIn('PBX_DIFF', form_params)
+ self.assertEqual(form_params['PBX_DIFF'], '07')
def test_response(self):
backend = eopayment.Payment('paybox', BACKEND_PARAMS)