From 7db0ac541582161090451ec648d21ee38f870f17 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Sat, 10 Oct 2020 13:33:08 +0200 Subject: [PATCH] ogone: use COMPLUS to transmit the transaction_id (#47535) Now ORDERID will contain the orderid if it is given or the transaction_id if there is no orderid. response() is adapted to work with old and new reponse: * old, there is no COMPLUS in the response, ORDERID is used as the transaction_id * new, COMPLUS is present, its value is returned as response.order_id (which is in fact the transaction_id :/ ) Ref: https://epayments-support.ingenico.com/fr/integration/all-sales-channels/integrate-with-e-commerce/guide#variable-feedback-parameters https://epayments-support.ingenico.com/fr/integration/all-sales-channels/integrate-with-e-commerce/guide#form-parameters --- eopayment/ogone.py | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/eopayment/ogone.py b/eopayment/ogone.py index 9d759ef..4d9b46f 100644 --- a/eopayment/ogone.py +++ b/eopayment/ogone.py @@ -15,11 +15,11 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +from decimal import Decimal, ROUND_HALF_UP +from six.moves.urllib import parse as urlparse import hashlib -import string import six -from six.moves.urllib import parse as urlparse -from decimal import Decimal, ROUND_HALF_UP +import uuid from .common import ( PaymentCommon, PaymentResponse, FORM, CANCELLED, PAID, @@ -514,19 +514,18 @@ class Payment(PaymentCommon): raise NotImplementedError('unknown environment %s' % self.environment) def request(self, amount, orderid=None, name=None, email=None, - language=None, description=None, **kwargs): - - reference = self.transaction_id(20, string.digits + string.ascii_letters) + language=None, description=None, transaction_id=None, + **kwargs): + # use complus for transmitting and receiving the transaction_id see + # https://epayments-support.ingenico.com/fr/integration/all-sales-channels/integrate-with-e-commerce/guide#variable-feedback-parameters + # orderid is now only used for unicity of payments check (it's + # garanteed that no payment for the same ORDERID can happen during a 45 + # days window, see + # https://epayments-support.ingenico.com/fr/integration/all-sales-channels/integrate-with-e-commerce/guide#form-parameters) + complus = transaction_id or uuid.uuid4().hex + if not orderid: + orderid = complus - # prepend order id in payment reference - if orderid: - if len(orderid) > 24: - raise ValueError('orderid length exceeds 25 characters') - reference = ( - orderid - + ORDERID_TRANSACTION_SEPARATOR - + self.transaction_id(29 - len(orderid), - string.digits + string.ascii_letters)) language = language or self.language # convertir en centimes amount = Decimal(amount) * 100 @@ -534,10 +533,11 @@ class Payment(PaymentCommon): amount = amount.quantize(Decimal('1.'), rounding=ROUND_HALF_UP) params = { 'AMOUNT': force_text(amount), - 'ORDERID': reference, + 'ORDERID': orderid, 'PSPID': self.pspid, 'LANGUAGE': language, 'CURRENCY': self.currency, + 'COMPLUS': complus, } if self.normal_return_url: params['ACCEPTURL'] = self.normal_return_url @@ -564,7 +564,7 @@ class Payment(PaymentCommon): fields=[{'type': 'hidden', 'name': key, 'value': params[key]} for key in params]) - return reference, FORM, form + return complus, FORM, form def response(self, query_string, **kwargs): if six.PY3: @@ -578,7 +578,8 @@ class Payment(PaymentCommon): # uniformize iso-8859-1 encoded values for key in params: params[key] = force_text(params[key], 'iso-8859-1') - reference = params['ORDERID'] + orderid = params['ORDERID'] + complus = params.get('COMPLUS') transaction_id = params['PAYID'] status = params['STATUS'] error = params['NCERROR'] @@ -606,11 +607,10 @@ class Payment(PaymentCommon): status, error, params.get('NCERRORPLUS', '')) result = ERROR # extract reference from received order id - if ORDERID_TRANSACTION_SEPARATOR in reference: - reference, transaction_id = reference.split(ORDERID_TRANSACTION_SEPARATOR, 1) + return PaymentResponse( result=result, signed=signed, bank_data=params, - order_id=reference, + order_id=complus or orderid, transaction_id=transaction_id) -- 2.28.0