22 |
22 |
import warnings
|
23 |
23 |
|
24 |
24 |
from .common import (PaymentCommon, PaymentResponse, FORM, PAID, ERROR, Form,
|
25 |
|
ORDERID_TRANSACTION_SEPARATOR, ResponseError, force_text, force_byte)
|
|
25 |
ORDERID_TRANSACTION_SEPARATOR, ResponseError, force_text,
|
|
26 |
force_byte)
|
26 |
27 |
|
27 |
28 |
__all__ = ['sign', 'Payment']
|
28 |
29 |
|
... | ... | |
39 |
40 |
'PBX_IDENTIFIANT': 'Identifiant interne (fourni par Paybox)',
|
40 |
41 |
'PBX_TOTAL': 'Montant total de la transaction',
|
41 |
42 |
'PBX_DEVISE': 'Devise de la transaction',
|
42 |
|
'PBX_CMD': 'Référence commande côté commerçant',
|
|
43 |
'PBX_CMD': 'Référence commande côté commerçant',
|
43 |
44 |
'PBX_PORTEUR': 'Adresse E - mail de l’acheteur',
|
44 |
45 |
'PBX_RETOUR': 'Liste des variables à retourner par Paybox',
|
45 |
46 |
'PBX_HASH': 'Type d’algorit hme de hachage pour le calcul de l’empreinte',
|
... | ... | |
52 |
53 |
'00001': 'La connexion au centre d’autorisation a échoué ou une '
|
53 |
54 |
'erreur interne est survenue. Dans ce cas, il est souhaitable de faire '
|
54 |
55 |
'une tentative sur le site secondaire : tpeweb1.paybox.com.',
|
55 |
|
'001xx': 'Paiement refusé par le centre d’autorisation [voir '
|
|
56 |
'001xx': 'Paiement refusé par le centre d’autorisation [voir '
|
56 |
57 |
'§12.112.1 Codes réponses du centre d’autorisationCodes réponses du '
|
57 |
58 |
'centre d’autorisation]. En cas d’autorisation de la transaction par '
|
58 |
59 |
'le centre d’autorisation de la banque ou de l’établissement financier '
|
... | ... | |
182 |
183 |
'name': 'platform',
|
183 |
184 |
'caption': _('Plateforme cible'),
|
184 |
185 |
'default': 'test',
|
185 |
|
'validation': lambda x: isinstance(x, basestring) and
|
186 |
|
x.lower() in ('test', 'prod'),
|
|
186 |
'validation': lambda x: isinstance(x, six.string_types)
|
|
187 |
and x.lower() in ('test', 'prod'),
|
187 |
188 |
},
|
188 |
189 |
{
|
189 |
190 |
'name': 'site',
|
190 |
191 |
'caption': _('Numéro de site'),
|
191 |
192 |
'required': True,
|
192 |
|
'validation': lambda x: isinstance(x, basestring) and
|
193 |
|
x.isdigit() and len(x) == 7,
|
|
193 |
'validation': lambda x: isinstance(x, six.string_types)
|
|
194 |
and x.isdigit() and len(x) == 7,
|
194 |
195 |
},
|
195 |
196 |
{
|
196 |
197 |
'name': 'cle',
|
197 |
198 |
'caption': _('Site key'),
|
198 |
199 |
'required': False,
|
199 |
|
'validation': lambda x: isinstance(x, basestring),
|
|
200 |
'validation': lambda x: isinstance(x, six.string_types),
|
200 |
201 |
},
|
201 |
202 |
{
|
202 |
203 |
'name': 'rang',
|
203 |
204 |
'caption': _('Numéro de rang'),
|
204 |
205 |
'required': True,
|
205 |
|
'validation': lambda x: isinstance(x, basestring) and
|
206 |
|
x.isdigit() and len(x) == 2,
|
|
206 |
'validation': lambda x: isinstance(x, six.string_types)
|
|
207 |
and x.isdigit() and len(x) == 2,
|
207 |
208 |
},
|
208 |
209 |
{
|
209 |
210 |
'name': 'identifiant',
|
210 |
211 |
'caption': _('Identifiant'),
|
211 |
212 |
'required': True,
|
212 |
|
'validation': lambda x: isinstance(x, basestring) and
|
213 |
|
x.isdigit() and (0 < len(x) < 10),
|
|
213 |
'validation': lambda x: isinstance(x, six.string_types)
|
|
214 |
and x.isdigit() and (0 < len(x) < 10),
|
214 |
215 |
},
|
215 |
216 |
{
|
216 |
217 |
'name': 'shared_secret',
|
217 |
218 |
'caption': _('Secret partagé'),
|
218 |
|
'validation': lambda x: isinstance(x, str) and
|
219 |
|
all(a.lower() in '0123456789ABCDEF' for a in x),
|
|
219 |
'validation': lambda x: isinstance(x, str)
|
|
220 |
and all(a.lower() in '0123456789ABCDEF' for a in x),
|
220 |
221 |
'required': True,
|
221 |
222 |
},
|
222 |
223 |
{
|
... | ... | |
237 |
238 |
'caption': _('Nombre de jours pour un paiement différé'),
|
238 |
239 |
'default': '',
|
239 |
240 |
'required': False,
|
240 |
|
'validation': lambda x: isinstance(x, basestring) and
|
241 |
|
x.isdigit() and (1 <= len(x) <= 2)
|
|
241 |
'validation': lambda x: isinstance(x, six.string_types)
|
|
242 |
and x.isdigit() and (1 <= len(x) <= 2)
|
242 |
243 |
},
|
243 |
244 |
{
|
244 |
245 |
'name': 'capture_mode',
|
... | ... | |
339 |
340 |
result = ERROR
|
340 |
341 |
for l in (5, 3):
|
341 |
342 |
prefix = d['erreur'][0][:l]
|
342 |
|
suffix = 'x' * (5-l)
|
|
343 |
suffix = 'x' * (5 - l)
|
343 |
344 |
bank_status = PAYBOX_ERROR_CODES.get(prefix + suffix)
|
344 |
345 |
if bank_status is not None:
|
345 |
346 |
break
|
... | ... | |
357 |
358 |
def perform(self, amount, bank_data, operation):
|
358 |
359 |
logger = logging.getLogger(__name__)
|
359 |
360 |
url = PAYBOX_DIRECT_URLS[self.platform]
|
360 |
|
params = {'VERSION': PAYBOX_DIRECT_VERSION_NUMBER,
|
361 |
|
'TYPE': operation,
|
362 |
|
'SITE': force_text(self.site),
|
363 |
|
'RANG': self.rang.strip(),
|
364 |
|
'CLE': force_text(self.cle),
|
365 |
|
'NUMQUESTION': bank_data['numero_transaction'][0].zfill(10),
|
366 |
|
'MONTANT': (amount * Decimal(100)).to_integral_value(ROUND_DOWN),
|
367 |
|
'DEVISE': force_text(self.devise),
|
368 |
|
'NUMTRANS': bank_data['numero_transaction'][0], # paybox transaction number
|
369 |
|
'NUMAPPEL': bank_data['numero_appel'][0],
|
370 |
|
'REFERENCE': bank_data['reference'][0],
|
371 |
|
'DATEQ': datetime.datetime.now().strftime('%d%m%Y%H%M%S'),
|
|
361 |
params = {
|
|
362 |
'VERSION': PAYBOX_DIRECT_VERSION_NUMBER,
|
|
363 |
'TYPE': operation,
|
|
364 |
'SITE': force_text(self.site),
|
|
365 |
'RANG': self.rang.strip(),
|
|
366 |
'CLE': force_text(self.cle),
|
|
367 |
'NUMQUESTION': bank_data['numero_transaction'][0].zfill(10),
|
|
368 |
'MONTANT': (amount * Decimal(100)).to_integral_value(ROUND_DOWN),
|
|
369 |
'DEVISE': force_text(self.devise),
|
|
370 |
'NUMTRANS': bank_data['numero_transaction'][0], # paybox transaction number
|
|
371 |
'NUMAPPEL': bank_data['numero_appel'][0],
|
|
372 |
'REFERENCE': bank_data['reference'][0],
|
|
373 |
'DATEQ': datetime.datetime.now().strftime('%d%m%Y%H%M%S'),
|
372 |
374 |
}
|
373 |
375 |
response = requests.post(url, params)
|
374 |
376 |
response.raise_for_status()
|
375 |
|
-
|