paybox: PEP8, style, python3 (#41320)
This commit is contained in:
parent
8a9f36e522
commit
27bea9fce9
|
@ -22,7 +22,8 @@ import string
|
|||
import warnings
|
||||
|
||||
from .common import (PaymentCommon, PaymentResponse, FORM, PAID, ERROR, Form,
|
||||
ORDERID_TRANSACTION_SEPARATOR, ResponseError, force_text, force_byte)
|
||||
ORDERID_TRANSACTION_SEPARATOR, ResponseError, force_text,
|
||||
force_byte)
|
||||
|
||||
__all__ = ['sign', 'Payment']
|
||||
|
||||
|
@ -39,7 +40,7 @@ VARS = {
|
|||
'PBX_IDENTIFIANT': 'Identifiant interne (fourni par Paybox)',
|
||||
'PBX_TOTAL': 'Montant total de la transaction',
|
||||
'PBX_DEVISE': 'Devise de la transaction',
|
||||
'PBX_CMD': 'Référence commande côté commerçant',
|
||||
'PBX_CMD': 'Référence commande côté commerçant',
|
||||
'PBX_PORTEUR': 'Adresse E - mail de l’acheteur',
|
||||
'PBX_RETOUR': 'Liste des variables à retourner par Paybox',
|
||||
'PBX_HASH': 'Type d’algorit hme de hachage pour le calcul de l’empreinte',
|
||||
|
@ -52,7 +53,7 @@ PAYBOX_ERROR_CODES = {
|
|||
'00001': 'La connexion au centre d’autorisation a échoué ou une '
|
||||
'erreur interne est survenue. Dans ce cas, il est souhaitable de faire '
|
||||
'une tentative sur le site secondaire : tpeweb1.paybox.com.',
|
||||
'001xx': 'Paiement refusé par le centre d’autorisation [voir '
|
||||
'001xx': 'Paiement refusé par le centre d’autorisation [voir '
|
||||
'§12.112.1 Codes réponses du centre d’autorisationCodes réponses du '
|
||||
'centre d’autorisation]. En cas d’autorisation de la transaction par '
|
||||
'le centre d’autorisation de la banque ou de l’établissement financier '
|
||||
|
@ -182,41 +183,41 @@ class Payment(PaymentCommon):
|
|||
'name': 'platform',
|
||||
'caption': _('Plateforme cible'),
|
||||
'default': 'test',
|
||||
'validation': lambda x: isinstance(x, basestring) and
|
||||
x.lower() in ('test', 'prod'),
|
||||
'validation': lambda x: isinstance(x, six.string_types)
|
||||
and x.lower() in ('test', 'prod'),
|
||||
},
|
||||
{
|
||||
'name': 'site',
|
||||
'caption': _('Numéro de site'),
|
||||
'required': True,
|
||||
'validation': lambda x: isinstance(x, basestring) and
|
||||
x.isdigit() and len(x) == 7,
|
||||
'validation': lambda x: isinstance(x, six.string_types)
|
||||
and x.isdigit() and len(x) == 7,
|
||||
},
|
||||
{
|
||||
'name': 'cle',
|
||||
'caption': _('Site key'),
|
||||
'required': False,
|
||||
'validation': lambda x: isinstance(x, basestring),
|
||||
'validation': lambda x: isinstance(x, six.string_types),
|
||||
},
|
||||
{
|
||||
'name': 'rang',
|
||||
'caption': _('Numéro de rang'),
|
||||
'required': True,
|
||||
'validation': lambda x: isinstance(x, basestring) and
|
||||
x.isdigit() and len(x) == 2,
|
||||
'validation': lambda x: isinstance(x, six.string_types)
|
||||
and x.isdigit() and len(x) == 2,
|
||||
},
|
||||
{
|
||||
'name': 'identifiant',
|
||||
'caption': _('Identifiant'),
|
||||
'required': True,
|
||||
'validation': lambda x: isinstance(x, basestring) and
|
||||
x.isdigit() and (0 < len(x) < 10),
|
||||
'validation': lambda x: isinstance(x, six.string_types)
|
||||
and x.isdigit() and (0 < len(x) < 10),
|
||||
},
|
||||
{
|
||||
'name': 'shared_secret',
|
||||
'caption': _('Secret partagé'),
|
||||
'validation': lambda x: isinstance(x, str) and
|
||||
all(a.lower() in '0123456789ABCDEF' for a in x),
|
||||
'validation': lambda x: isinstance(x, str)
|
||||
and all(a.lower() in '0123456789ABCDEF' for a in x),
|
||||
'required': True,
|
||||
},
|
||||
{
|
||||
|
@ -237,8 +238,8 @@ class Payment(PaymentCommon):
|
|||
'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)
|
||||
'validation': lambda x: isinstance(x, six.string_types)
|
||||
and x.isdigit() and (1 <= len(x) <= 2)
|
||||
},
|
||||
{
|
||||
'name': 'capture_mode',
|
||||
|
@ -339,7 +340,7 @@ class Payment(PaymentCommon):
|
|||
result = ERROR
|
||||
for l in (5, 3):
|
||||
prefix = d['erreur'][0][:l]
|
||||
suffix = 'x' * (5-l)
|
||||
suffix = 'x' * (5 - l)
|
||||
bank_status = PAYBOX_ERROR_CODES.get(prefix + suffix)
|
||||
if bank_status is not None:
|
||||
break
|
||||
|
@ -357,18 +358,19 @@ class Payment(PaymentCommon):
|
|||
def perform(self, amount, bank_data, operation):
|
||||
logger = logging.getLogger(__name__)
|
||||
url = PAYBOX_DIRECT_URLS[self.platform]
|
||||
params = {'VERSION': PAYBOX_DIRECT_VERSION_NUMBER,
|
||||
'TYPE': operation,
|
||||
'SITE': force_text(self.site),
|
||||
'RANG': self.rang.strip(),
|
||||
'CLE': force_text(self.cle),
|
||||
'NUMQUESTION': bank_data['numero_transaction'][0].zfill(10),
|
||||
'MONTANT': (amount * Decimal(100)).to_integral_value(ROUND_DOWN),
|
||||
'DEVISE': force_text(self.devise),
|
||||
'NUMTRANS': bank_data['numero_transaction'][0], # paybox transaction number
|
||||
'NUMAPPEL': bank_data['numero_appel'][0],
|
||||
'REFERENCE': bank_data['reference'][0],
|
||||
'DATEQ': datetime.datetime.now().strftime('%d%m%Y%H%M%S'),
|
||||
params = {
|
||||
'VERSION': PAYBOX_DIRECT_VERSION_NUMBER,
|
||||
'TYPE': operation,
|
||||
'SITE': force_text(self.site),
|
||||
'RANG': self.rang.strip(),
|
||||
'CLE': force_text(self.cle),
|
||||
'NUMQUESTION': bank_data['numero_transaction'][0].zfill(10),
|
||||
'MONTANT': (amount * Decimal(100)).to_integral_value(ROUND_DOWN),
|
||||
'DEVISE': force_text(self.devise),
|
||||
'NUMTRANS': bank_data['numero_transaction'][0], # paybox transaction number
|
||||
'NUMAPPEL': bank_data['numero_appel'][0],
|
||||
'REFERENCE': bank_data['reference'][0],
|
||||
'DATEQ': datetime.datetime.now().strftime('%d%m%Y%H%M%S'),
|
||||
}
|
||||
response = requests.post(url, params)
|
||||
response.raise_for_status()
|
||||
|
|
Loading…
Reference in New Issue