Projet

Général

Profil

0007-sips2-use-transaction_date-41320.patch

Benjamin Dauvergne, 04 avril 2020 13:05

Télécharger (4,69 ko)

Voir les différences:

Subject: [PATCH 7/7] sips2: use transaction_date (#41320)

 eopayment/sips2.py  | 21 ++++++++++++++++++++-
 tests/test_sips2.py |  9 ++++++++-
 2 files changed, 28 insertions(+), 2 deletions(-)
eopayment/sips2.py
1 1
# -*- coding: utf-8 -*-
2 2

  
3
import datetime
3 4
from decimal import Decimal
4 5
from gettext import gettext as _
5 6
import collections
......
14 15

  
15 16
import requests
16 17

  
18
import pytz
19

  
17 20
from .common import (PaymentCommon, FORM, Form, PaymentResponse, PAID, ERROR,
18 21
                     CANCELED, ResponseError, force_text)
19 22

  
......
137 140
                'name': 'payment_means',
138 141
                'caption': _('Payment Means'),
139 142
                'required': False
143
            },
144
            {
145
                'name': 'timezone',
146
                'caption': _('SIPS server Timezone'),
147
                'default': 'Europe/Paris',
148
                'required': False,
140 149
            }
141 150
        ],
142 151
    }
......
243 252
        result = self.response_code_to_result.get(response_code, ERROR)
244 253
        merchant_id = data.get('merchantId')
245 254
        test = merchant_id == self.TEST_MERCHANT_ID
255
        transaction_date = None
256
        if 'transactionDateTime' in data:
257
            try:
258
                transaction_date = datetime.datetime.strptime(data['transactionDateTime'], '%Y-%m-%d %H:%M:%S')
259
            except (ValueError, TypeError):
260
                pass
261
            else:
262
                sips_tz = pytz.timezone(self.timezone)
263
                transaction_date = sips_tz.localize(transaction_date)
246 264
        return PaymentResponse(
247 265
            result=result,
248 266
            signed=signed,
......
250 268
            order_id=transaction_id,
251 269
            transaction_id=data.get('authorisationId'),
252 270
            bank_status=self.RESPONSE_CODES.get(response_code, u'unknown code - ' + response_code),
253
            test=test)
271
            test=test,
272
            transaction_date=transaction_date)
254 273

  
255 274
    def get_seal_for_json_ws_data(self, data):
256 275
        data_to_send = []
tests/test_sips2.py
37 37
def test_parse_response():
38 38
    qs = '''Data=captureDay%3D0%7CcaptureMode%3DAUTHOR_CAPTURE%7CcurrencyCode%3D978%7CmerchantId%3D002001000000001%7CorderChannel%3DINTERNET%7CresponseCode%3D00%7CtransactionDateTime%3D2016-02-01T17%3A44%3A20%2B01%3A00%7CtransactionReference%3D668930%7CkeyVersion%3D1%7CacquirerResponseCode%3D00%7Camount%3D1200%7CauthorisationId%3D12345%7CcardCSCResultCode%3D4E%7CpanExpiryDate%3D201605%7CpaymentMeanBrand%3DMASTERCARD%7CpaymentMeanType%3DCARD%7CcustomerIpAddress%3D82.244.203.243%7CmaskedPan%3D5100%23%23%23%23%23%23%23%23%23%23%23%2300%7CorderId%3Dd4903de7027f4d56ac01634fd7ab9526%7CholderAuthentRelegation%3DN%7CholderAuthentStatus%3D3D_ERROR%7CtransactionOrigin%3DINTERNET%7CpaymentPattern%3DONE_SHOT&Seal=6ca3247765a19b45d25ad54ef4076483e7d55583166bd5ac9c64357aac097602&InterfaceVersion=HP_2.0&Encode='''
39 39
    backend = eopayment.Payment('sips2', {})
40
    assert backend.response(qs)
40
    response = backend.response(qs)
41
    assert response.signed
42
    assert response.transaction_date is None
43

  
44
    qs = '''Data=captureDay%3D0%7CcaptureMode%3DAUTHOR_CAPTURE%7CcurrencyCode%3D978%7CmerchantId%3D002001000000001%7CorderChannel%3DINTERNET%7CresponseCode%3D00%7CtransactionDateTime%3D2016-02-01T17%3A44%3A20%2B01%3A00%7CtransactionReference%3D668930%7CkeyVersion%3D1%7CacquirerResponseCode%3D00%7Camount%3D1200%7CauthorisationId%3D12345%7CcardCSCResultCode%3D4E%7CpanExpiryDate%3D201605%7CpaymentMeanBrand%3DMASTERCARD%7CpaymentMeanType%3DCARD%7CcustomerIpAddress%3D82.244.203.243%7CmaskedPan%3D5100%23%23%23%23%23%23%23%23%23%23%23%2300%7CorderId%3Dd4903de7027f4d56ac01634fd7ab9526%7CholderAuthentRelegation%3DN%7CholderAuthentStatus%3D3D_ERROR%7CtransactionOrigin%3DINTERNET%7CpaymentPattern%3DONE_SHOT%7CtransactionDateTime%3D2020-01-01%2001:01:01&Seal=6ca3247765a19b45d25ad54ef4076483e7d55583166bd5ac9c64357aac097602&InterfaceVersion=HP_2.0&Encode='''
45
    response = backend.response(qs)
46
    assert not response.signed
47
    assert response.transaction_date.isoformat() == '2020-01-01T01:01:01+01:00'
41 48

  
42 49
    with pytest.raises(eopayment.ResponseError, match='missing Data, Seal or InterfaceVersion'):
43 50
        backend.response('foo=bar')
44
-