2020-04-10 11:10:15 +02:00
|
|
|
# eopayment - online payment library
|
|
|
|
# Copyright (C) 2011-2020 Entr'ouvert
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify it
|
|
|
|
# under the terms of the GNU Affero General Public License as published
|
|
|
|
# by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2019-01-31 16:57:02 +01:00
|
|
|
import datetime
|
2018-07-25 11:04:54 +02:00
|
|
|
from decimal import Decimal
|
2022-10-28 08:26:03 +02:00
|
|
|
from urllib.parse import parse_qs, urlparse
|
2019-01-31 16:18:27 +01:00
|
|
|
|
2018-08-22 23:14:53 +02:00
|
|
|
import pytest
|
2020-10-11 09:35:50 +02:00
|
|
|
import pytz
|
|
|
|
|
2018-07-25 11:04:54 +02:00
|
|
|
import eopayment
|
2019-01-31 16:57:02 +01:00
|
|
|
import eopayment.tipi
|
2018-07-25 11:04:54 +02:00
|
|
|
|
2019-01-31 16:18:27 +01:00
|
|
|
|
2018-07-25 11:04:54 +02:00
|
|
|
def test_tipi():
|
|
|
|
p = eopayment.Payment('tipi', {'numcli': '12345'})
|
2019-01-31 16:18:27 +01:00
|
|
|
payment_id, kind, url = p.request(
|
|
|
|
amount=Decimal('123.12'),
|
2020-09-10 11:28:43 +02:00
|
|
|
exer='9999',
|
|
|
|
refdet='999900000000999999',
|
2019-01-31 16:18:27 +01:00
|
|
|
objet='tout a fait',
|
|
|
|
email='info@entrouvert.com',
|
|
|
|
urlcl='http://example.com/tipi/test',
|
|
|
|
saisie='T',
|
|
|
|
)
|
2019-02-08 12:58:35 +01:00
|
|
|
assert eopayment.tipi.Payment.REFDET_RE.match(payment_id) is not None
|
2018-07-25 11:04:54 +02:00
|
|
|
parsed_qs = parse_qs(urlparse(url).query)
|
2019-01-31 16:18:27 +01:00
|
|
|
assert parsed_qs['objet'][0].startswith('tout a fait')
|
2018-07-25 11:04:54 +02:00
|
|
|
assert parsed_qs['montant'] == ['12312']
|
|
|
|
assert parsed_qs['saisie'] == ['T']
|
|
|
|
assert parsed_qs['mel'] == ['info@entrouvert.com']
|
|
|
|
assert parsed_qs['numcli'] == ['12345']
|
|
|
|
assert parsed_qs['exer'] == ['9999']
|
|
|
|
assert parsed_qs['refdet'] == ['999900000000999999']
|
|
|
|
|
2019-01-31 16:18:27 +01:00
|
|
|
response = p.response(
|
|
|
|
'objet=tout+a+fait&montant=12312&saisie=T&mel=info%40entrouvert.com'
|
|
|
|
'&numcli=12345&exer=9999&refdet=999900000000999999&resultrans=P'
|
|
|
|
)
|
2018-07-25 11:04:54 +02:00
|
|
|
assert response.signed # ...
|
2019-09-21 17:10:01 +02:00
|
|
|
assert response.order_id == '999900000000999999'
|
|
|
|
assert response.transaction_id == '999900000000999999'
|
2018-07-25 11:04:54 +02:00
|
|
|
assert response.result == eopayment.PAID
|
2018-08-22 23:14:53 +02:00
|
|
|
|
|
|
|
with pytest.raises(eopayment.ResponseError, match='missing refdet or resultrans'):
|
|
|
|
p.response('foo=bar')
|
2019-01-31 16:57:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_tipi_no_orderid_no_refdet():
|
|
|
|
p = eopayment.Payment('tipi', {'numcli': '12345'})
|
|
|
|
payment_id, kind, url = p.request(
|
|
|
|
amount=Decimal('123.12'), exer=9999, email='info@entrouvert.com', saisie='T'
|
|
|
|
)
|
2019-02-08 12:58:35 +01:00
|
|
|
assert eopayment.tipi.Payment.REFDET_RE.match(payment_id) is not None
|
2019-01-31 16:57:02 +01:00
|
|
|
parsed_qs = parse_qs(urlparse(url).query)
|
|
|
|
assert 'objet' not in parsed_qs
|
|
|
|
assert parsed_qs['montant'] == ['12312']
|
|
|
|
assert parsed_qs['saisie'] == ['T']
|
|
|
|
assert parsed_qs['mel'] == ['info@entrouvert.com']
|
|
|
|
assert parsed_qs['numcli'] == ['12345']
|
|
|
|
assert parsed_qs['exer'] == ['9999']
|
2020-10-11 09:35:50 +02:00
|
|
|
assert parsed_qs['refdet'][0].startswith(
|
|
|
|
datetime.datetime.now(pytz.timezone('Europe/Paris')).strftime('%Y%m%d')
|
2021-11-26 10:43:17 +01:00
|
|
|
)
|
2019-01-31 16:57:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_tipi_orderid_refdef_compatible():
|
|
|
|
p = eopayment.Payment('tipi', {'numcli': '12345', 'saisie': 'A'})
|
|
|
|
payment_id, kind, url = p.request(
|
|
|
|
amount=Decimal('123.12'), email='info@entrouvert.com', orderid='F121212'
|
|
|
|
)
|
2019-02-08 12:58:35 +01:00
|
|
|
assert eopayment.tipi.Payment.REFDET_RE.match(payment_id)
|
2019-01-31 16:57:02 +01:00
|
|
|
expected_url = urlparse(eopayment.tipi.TIPI_URL)
|
|
|
|
parsed_url = urlparse(url)
|
|
|
|
assert parsed_url[:3] == expected_url[:3]
|
|
|
|
parsed_qs = parse_qs(parsed_url.query)
|
|
|
|
assert 'objet' not in parsed_qs
|
|
|
|
assert 'exer' not in parsed_qs
|
|
|
|
assert parsed_qs['montant'] == ['12312']
|
|
|
|
assert parsed_qs['saisie'] == ['A']
|
|
|
|
assert parsed_qs['mel'] == ['info@entrouvert.com']
|
|
|
|
assert parsed_qs['numcli'] == ['12345']
|
|
|
|
assert parsed_qs['refdet'] == ['F121212']
|
|
|
|
|
|
|
|
|
|
|
|
def test_tipi_orderid_not_refdef_compatible():
|
|
|
|
p = eopayment.Payment('tipi', {'numcli': '12345', 'saisie': 'A'})
|
|
|
|
payment_id, kind, url = p.request(
|
|
|
|
amount=Decimal('123.12'), email='info@entrouvert.com', objet='coucou', orderid='F12-12-12'
|
|
|
|
)
|
2019-02-08 12:58:35 +01:00
|
|
|
assert eopayment.tipi.Payment.REFDET_RE.match(payment_id) is not None
|
2019-01-31 16:57:02 +01:00
|
|
|
expected_url = urlparse(eopayment.tipi.TIPI_URL)
|
|
|
|
parsed_url = urlparse(url)
|
|
|
|
assert parsed_url[:3] == expected_url[:3]
|
|
|
|
parsed_qs = parse_qs(parsed_url.query)
|
|
|
|
assert 'exer' not in parsed_qs
|
|
|
|
assert parsed_qs['montant'] == ['12312']
|
|
|
|
assert parsed_qs['saisie'] == ['A']
|
|
|
|
assert parsed_qs['mel'] == ['info@entrouvert.com']
|
|
|
|
assert parsed_qs['numcli'] == ['12345']
|
|
|
|
assert parsed_qs['refdet'][0].startswith(datetime.datetime.now().strftime('%Y%m%d'))
|
|
|
|
assert 'coucou' in parsed_qs['objet'][0]
|
|
|
|
assert 'F12-12-12' in parsed_qs['objet'][0]
|
2021-09-28 21:51:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def payment():
|
|
|
|
return eopayment.Payment('tipi', {'numcli': '12345'})
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_minimal_amount(payment):
|
|
|
|
assert payment.get_minimal_amount() is not None
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_maximal_amount(payment):
|
|
|
|
assert payment.get_maximal_amount() is not None
|