forked from CGM_Public/pretix_original
Allow payment providers to define custom form fields / templates
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
from decimal import Decimal
|
||||
|
||||
from django.forms import Form
|
||||
from django.template import Context
|
||||
from django.template.loader import get_template
|
||||
|
||||
from pretix.base.settings import SettingsSandbox
|
||||
|
||||
|
||||
@@ -50,6 +54,41 @@ class BasePaymentProvider:
|
||||
def settings_form_fields(self) -> dict:
|
||||
"""
|
||||
A dictionary. The keys should be (unprefixed) EventSetting keys,
|
||||
the values should be corresponding django form fields
|
||||
the values should be corresponding django form fields.
|
||||
|
||||
We suggest returning a collections.OrderedDict object instead of a dict.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
@property
|
||||
def checkout_form_fields(self) -> dict:
|
||||
"""
|
||||
A dictionary. The keys should be unprefixed field names,
|
||||
the values should be corresponding django form fields.
|
||||
|
||||
We suggest returning a collections.OrderedDict object instead of a dict.
|
||||
"""
|
||||
# TODO: Proper handling of required=True fields in HTML
|
||||
return {}
|
||||
|
||||
def checkout_form(self, request) -> Form:
|
||||
"""
|
||||
Returns the Form object of the form that should be displayed when the
|
||||
user selects this provider as his payment method.
|
||||
"""
|
||||
form = Form(
|
||||
data=(request.POST if request.method == 'POST' else None),
|
||||
prefix='payment_%s' % self.identifier
|
||||
)
|
||||
form.fields = self.checkout_form_fields
|
||||
return form
|
||||
|
||||
def checkout_form_render(self, request) -> str:
|
||||
"""
|
||||
Returns the HTML of the form that should be displayed when the user
|
||||
selects this provider as his payment method.
|
||||
"""
|
||||
form = self.checkout_form(request)
|
||||
template = get_template('pretixpresale/event/checkout_payment_form_default.html')
|
||||
ctx = Context({'request': request, 'form': form})
|
||||
return template.render(ctx)
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
{% bootstrap_form provider.form layout='horizontal' %}
|
||||
</div>
|
||||
</div>
|
||||
{% empty %}
|
||||
<em>{% trans "There are no payment providers available. Please go to the plugin settings and activate one or more payment plugins." %}</em>
|
||||
{% endfor %}
|
||||
</fieldset>
|
||||
<div class="form-group submit-group">
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
from collections import OrderedDict
|
||||
from django.template import Context
|
||||
from django.template.loader import get_template
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django import forms
|
||||
|
||||
@@ -16,3 +18,8 @@ class BankTransfer(BasePaymentProvider):
|
||||
required=False
|
||||
))
|
||||
])
|
||||
|
||||
def checkout_form_render(self, request) -> str:
|
||||
template = get_template('pretixplugins/banktransfer/checkout_payment_form.html')
|
||||
ctx = Context({'request': request, 'event': self.event, 'settings': self.settings})
|
||||
return template.render(ctx)
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
{% load i18n %}
|
||||
|
||||
<p>{% blocktrans trimmed %}
|
||||
After completing your purchase, we will ask you to transfer the money to the following
|
||||
bank account, using a personal reference code.
|
||||
{% endblocktrans %}</p>
|
||||
|
||||
<address>
|
||||
{{ settings.bank_details|linebreaksbr }}
|
||||
</address>
|
||||
@@ -10,3 +10,10 @@ class Stripe(BasePaymentProvider):
|
||||
verbose_name = _('Credit Card via Stripe')
|
||||
settings_form_fields = OrderedDict([
|
||||
])
|
||||
checkout_form_fields = OrderedDict([
|
||||
('cc_number',
|
||||
forms.CharField(
|
||||
label=_('Credit card number'),
|
||||
required=False
|
||||
))
|
||||
])
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
</div>
|
||||
<div id="payment_{{ p.provider.identifier }}" class="panel-collapse collapse">
|
||||
<div class="panel-body form-horizontal">
|
||||
{{ p.form }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
{% load bootstrap3 %}
|
||||
{% bootstrap_form form layout='horizontal' %}
|
||||
@@ -218,6 +218,7 @@ class PaymentDetails(EventViewMixin, CartDisplayMixin, EventLoginRequiredMixin,
|
||||
providers.append({
|
||||
'provider': provider,
|
||||
'fee': fee,
|
||||
'form': provider.checkout_form_render(self.request),
|
||||
})
|
||||
return providers
|
||||
|
||||
|
||||
Reference in New Issue
Block a user