add minimal and maximal amount attribute to backends (#57367)

This commit is contained in:
Benjamin Dauvergne 2021-09-28 21:51:36 +02:00
parent db91463687
commit 6284e0fbb3
6 changed files with 45 additions and 0 deletions

View File

@ -247,3 +247,9 @@ class Payment(object):
@property
def has_payment_status(self):
return hasattr(self.backend, 'payment_status')
def get_minimal_amount(self):
return getattr(self.backend, 'minimal_amount', None)
def get_maximal_amount(self):
return getattr(self.backend, 'maximal_amount', None)

View File

@ -17,6 +17,7 @@
from __future__ import print_function, unicode_literals
import copy
import decimal
import datetime
import functools
import os
@ -201,6 +202,9 @@ class Payment(PaymentCommon):
min_time_between_transactions = 60 * 20 # 20 minutes
minimal_amount = decimal.Decimal('1.0')
maximal_amount = decimal.Decimal('100000.0')
def __init__(self, *args, **kwargs):
super(Payment, self).__init__(*args, **kwargs)
self.payfip = PayFiP()

View File

@ -15,6 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import datetime
import decimal
import re
import random
@ -76,6 +77,9 @@ class Payment(PaymentCommon):
REFDET_RE = re.compile('^[a-zA-Z0-9]{6,30}$')
minimal_amount = decimal.Decimal('1.0')
maximal_amount = decimal.Decimal('100000.0')
def _generate_refdet(self):
return '%s%010d' % (datetime.datetime.now(pytz.timezone('Europe/Paris')).strftime('%Y%m%d%H%M%S'),
random.randint(1, 1000000000))

View File

@ -118,3 +118,13 @@ def test_payment_status(monkeypatch):
def test_get_min_time_between_transaction(monkeypatch):
_, payment = do_mock_backend(monkeypatch)
assert payment.get_min_time_between_transactions() == 0
def test_get_minimal_amount(monkeypatch):
_, payment = do_mock_backend(monkeypatch)
assert payment.get_minimal_amount() is None
def test_get_maximal_amount(monkeypatch):
_, payment = do_mock_backend(monkeypatch)
assert payment.get_maximal_amount() is None

View File

@ -484,3 +484,11 @@ def test_invalid_transaction_id_invalid_orderid(get_idop, backend):
def test_get_min_time_between_transactions(backend):
assert backend.get_min_time_between_transactions() == 20 * 60
def test_get_minimal_amount(backend):
assert backend.get_minimal_amount() is not None
def test_get_maximal_amount(backend):
assert backend.get_maximal_amount() is not None

View File

@ -115,3 +115,16 @@ def test_tipi_orderid_not_refdef_compatible():
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]
@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