Projet

Général

Profil

0001-ogone-use-COMPLUS-to-transmit-the-transaction_id-475.patch

Benjamin Dauvergne, 11 octobre 2020 22:40

Télécharger (6,06 ko)

Voir les différences:

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 +++++++++++++++++++++---------------------
 tests/test_ogone.py |  6 +++---
 2 files changed, 24 insertions(+), 24 deletions(-)
eopayment/ogone.py
15 15
# You should have received a copy of the GNU Affero General Public License
16 16
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 17

  
18
from decimal import Decimal, ROUND_HALF_UP
19
from six.moves.urllib import parse as urlparse
18 20
import hashlib
19
import string
20 21
import six
21
from six.moves.urllib import parse as urlparse
22
from decimal import Decimal, ROUND_HALF_UP
22
import uuid
23 23

  
24 24
from .common import (
25 25
    PaymentCommon, PaymentResponse, FORM, CANCELLED, PAID,
......
514 514
        raise NotImplementedError('unknown environment %s' % self.environment)
515 515

  
516 516
    def request(self, amount, orderid=None, name=None, email=None,
517
                language=None, description=None, **kwargs):
518

  
519
        reference = self.transaction_id(20, string.digits + string.ascii_letters)
517
                language=None, description=None, transaction_id=None,
518
                **kwargs):
519
        # use complus for transmitting and receiving the transaction_id see
520
        # https://epayments-support.ingenico.com/fr/integration/all-sales-channels/integrate-with-e-commerce/guide#variable-feedback-parameters
521
        # orderid is now only used for unicity of payments check (it's
522
        # garanteed that no payment for the same ORDERID can happen during a 45
523
        # days window, see
524
        # https://epayments-support.ingenico.com/fr/integration/all-sales-channels/integrate-with-e-commerce/guide#form-parameters)
525
        complus = transaction_id or uuid.uuid4().hex
526
        if not orderid:
527
            orderid = complus
520 528

  
521
        # prepend order id in payment reference
522
        if orderid:
523
            if len(orderid) > 24:
524
                raise ValueError('orderid length exceeds 25 characters')
525
            reference = (
526
                orderid
527
                + ORDERID_TRANSACTION_SEPARATOR
528
                + self.transaction_id(29 - len(orderid),
529
                                      string.digits + string.ascii_letters))
530 529
        language = language or self.language
531 530
        # convertir en centimes
532 531
        amount = Decimal(amount) * 100
......
534 533
        amount = amount.quantize(Decimal('1.'), rounding=ROUND_HALF_UP)
535 534
        params = {
536 535
            'AMOUNT': force_text(amount),
537
            'ORDERID': reference,
536
            'ORDERID': orderid,
538 537
            'PSPID': self.pspid,
539 538
            'LANGUAGE': language,
540 539
            'CURRENCY': self.currency,
540
            'COMPLUS': complus,
541 541
        }
542 542
        if self.normal_return_url:
543 543
            params['ACCEPTURL'] = self.normal_return_url
......
564 564
            fields=[{'type': 'hidden',
565 565
                     'name': key,
566 566
                     'value': params[key]} for key in params])
567
        return reference, FORM, form
567
        return complus, FORM, form
568 568

  
569 569
    def response(self, query_string, **kwargs):
570 570
        if six.PY3:
......
578 578
        # uniformize iso-8859-1 encoded values
579 579
        for key in params:
580 580
            params[key] = force_text(params[key], 'iso-8859-1')
581
        reference = params['ORDERID']
581
        orderid = params['ORDERID']
582
        complus = params.get('COMPLUS')
582 583
        transaction_id = params['PAYID']
583 584
        status = params['STATUS']
584 585
        error = params['NCERROR']
......
606 607
                              status, error, params.get('NCERRORPLUS', ''))
607 608
            result = ERROR
608 609
        # extract reference from received order id
609
        if ORDERID_TRANSACTION_SEPARATOR in reference:
610
            reference, transaction_id = reference.split(ORDERID_TRANSACTION_SEPARATOR, 1)
610

  
611 611
        return PaymentResponse(
612 612
            result=result,
613 613
            signed=signed,
614 614
            bank_data=params,
615
            order_id=reference,
615
            order_id=complus or orderid,
616 616
            transaction_id=transaction_id)
tests/test_ogone.py
49 49
            amount=amount,
50 50
            orderid=order_id,
51 51
            email='foo@example.com')
52
        self.assertEqual(len(reference), 30)
53
        assert reference.startswith(order_id)
52
        self.assertEqual(len(reference), 32)
54 53
        root = ET.fromstring(str(what))
55 54
        self.assertEqual(root.tag, 'form')
56 55
        self.assertEqual(root.attrib['method'], 'POST')
57 56
        self.assertEqual(root.attrib['action'], ogone.ENVIRONMENT_TEST_URL)
58 57
        values = {
59 58
            'CURRENCY': u'EUR',
60
            'ORDERID': reference,
59
            'ORDERID': order_id,
61 60
            'PSPID': PSPID,
62 61
            'EMAIL': 'foo@example.com',
63 62
            'AMOUNT': amount.replace('.', ''),
64 63
            'LANGUAGE': 'fr_FR',
64
            'COMPLUS': reference,
65 65
        }
66 66
        values.update({'SHASIGN': ogone_backend.backend.sha_sign_in(values)})
67 67
        for node in root:
68
-