paybox: add support for delayed payment (#25737)
This commit is contained in:
parent
d142c1c8f8
commit
1e5aa020a3
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue