forked from CGM_Public/pretix_original
Re-work API for payment settings fields
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
from collections import OrderedDict
|
||||
from decimal import Decimal
|
||||
from django import forms
|
||||
|
||||
from django.forms import Form
|
||||
from django.template import Context
|
||||
from django.template.loader import get_template
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from pretix.base.forms import SettingsForm
|
||||
|
||||
from pretix.base.settings import SettingsSandbox
|
||||
|
||||
@@ -20,45 +24,74 @@ class BasePaymentProvider:
|
||||
return self.identifier
|
||||
|
||||
@property
|
||||
def is_enabled(self):
|
||||
def is_enabled(self) -> bool:
|
||||
"""
|
||||
Returns, whether or whether not this payment provider is enabled.
|
||||
By default, this is determined by the value of a setting.
|
||||
By default, this is determined by the value of the ``_enabled`` setting.
|
||||
"""
|
||||
return self.settings.get('_enabled', as_type=bool)
|
||||
|
||||
def calculate_fee(self, price):
|
||||
def calculate_fee(self, price: Decimal) -> Decimal:
|
||||
"""
|
||||
Calculate the fee for this payment provider which will be added to
|
||||
the final price if the price before fees (but after taxes) is 'price'.
|
||||
final price before fees (but after taxes). It should include any taxes.
|
||||
The default implementation makes use of the setting ``_fee_abs`` for an
|
||||
absolute fee and ``_fee_percent`` for a percentage.
|
||||
|
||||
:param price: The total value without the payment method fee, after taxes.
|
||||
"""
|
||||
fee_abs = self.settings.get('_fee_abs', as_type=Decimal, default=0)
|
||||
fee_percent = self.settings.get('_fee_percent', as_type=Decimal, default=0)
|
||||
return price * fee_percent / 100 + fee_abs
|
||||
return Decimal(price * fee_percent / 100 + fee_abs)
|
||||
|
||||
@property
|
||||
def verbose_name(self) -> str:
|
||||
"""
|
||||
A human-readable name for this payment provider
|
||||
A human-readable name for this payment provider. This should
|
||||
be short but self-explaining. Good examples include 'Bank transfer'
|
||||
and 'Credit card via Stripe'.
|
||||
"""
|
||||
raise NotImplementedError() # NOQA
|
||||
|
||||
@property
|
||||
def identifier(self) -> str:
|
||||
"""
|
||||
A unique identifier for this payment provider
|
||||
A short and unique identifier for this payment provider.
|
||||
This should only contain lowercase letters and in most
|
||||
cases will be the same as your packagename.
|
||||
"""
|
||||
raise NotImplementedError() # NOQA
|
||||
|
||||
@property
|
||||
def settings_form_fields(self) -> dict:
|
||||
"""
|
||||
When the event's administrator administrator visits the event configuration
|
||||
page,
|
||||
A dictionary. The keys should be (unprefixed) EventSetting keys,
|
||||
the values should be corresponding django form fields.
|
||||
|
||||
We suggest returning a collections.OrderedDict object instead of a dict.
|
||||
"""
|
||||
raise NotImplementedError() # NOQA
|
||||
return OrderedDict([
|
||||
('_enabled',
|
||||
forms.ChoiceField(
|
||||
label=_('Enable payment method'),
|
||||
required=False,
|
||||
choices=SettingsForm.BOOL_CHOICES,
|
||||
)),
|
||||
('_fee_abs',
|
||||
forms.DecimalField(
|
||||
label=_('Additional fee'),
|
||||
help_text=_('Absolute value'),
|
||||
required=False
|
||||
)),
|
||||
('_fee_percent',
|
||||
forms.DecimalField(
|
||||
label=_('Additional fee'),
|
||||
help_text=_('Percentage'),
|
||||
required=False
|
||||
)),
|
||||
])
|
||||
|
||||
@property
|
||||
def checkout_form_fields(self) -> dict:
|
||||
|
||||
Reference in New Issue
Block a user