Add "is_implicit" attribute to payment providers

This commit is contained in:
Raphael Michel
2018-02-04 23:14:18 +01:00
parent 4ccf33af03
commit da32621c55
2 changed files with 21 additions and 3 deletions

View File

@@ -50,6 +50,16 @@ class BasePaymentProvider:
def __str__(self):
return self.identifier
@property
def is_implicit(self) -> bool:
"""
Returns whether or whether not this payment provider is an "implicit" payment provider that will
*always* and unconditionally be used if is_allowed() returns True and does not require any input.
This is intended to be used by the FreePaymentProvider, which skips the payment choice page.
By default, this returns ``False``. Please do not set this if you don't know exactly what you are doing.
"""
return False
@property
def is_meta(self) -> bool:
"""
@@ -552,6 +562,10 @@ class PaymentException(Exception):
class FreeOrderProvider(BasePaymentProvider):
@property
def is_implicit(self) -> bool:
return True
@property
def is_enabled(self) -> bool:
return True

View File

@@ -487,9 +487,13 @@ class PaymentStep(QuestionsViewMixin, CartMixin, TemplateFlowStep):
def is_applicable(self, request):
self.request = request
if self._total_order_value == 0:
self.cart_session['payment'] = 'free'
return False
for p in self.request.event.get_payment_providers().values():
if p.is_implicit:
if p.is_allowed(request):
self.cart_session['payment'] = p.identifier
return False
return True