mirror of
https://github.com/pretix/pretix.git
synced 2026-05-05 15:14:04 +00:00
Make stripe refund call optional, add request parameter to order_control_refund_render
This commit is contained in:
@@ -19,6 +19,18 @@ from pretix.plugins.paypal.models import ReferencedPayPalObject
|
||||
logger = logging.getLogger('pretix.plugins.paypal')
|
||||
|
||||
|
||||
class RefundForm(forms.Form):
|
||||
auto_refund = forms.ChoiceField(
|
||||
initial='auto',
|
||||
label=_('Refund automatically?'),
|
||||
choices=(
|
||||
('auto', _('Automatically refund charge with PayPal')),
|
||||
('manual', _('Do not send refund instruction to PayPal, only mark as refunded in pretix'))
|
||||
),
|
||||
widget=forms.RadioSelect,
|
||||
)
|
||||
|
||||
|
||||
class Paypal(BasePaymentProvider):
|
||||
identifier = 'paypal'
|
||||
verbose_name = _('PayPal')
|
||||
@@ -248,10 +260,28 @@ class Paypal(BasePaymentProvider):
|
||||
'payment_info': payment_info, 'order': order}
|
||||
return template.render(ctx)
|
||||
|
||||
def order_control_refund_render(self, order) -> str:
|
||||
return '<div class="alert alert-info">%s</div>' % _('The money will be automatically refunded.')
|
||||
def _refund_form(self, request):
|
||||
return RefundForm(data=request.POST if request.method == "POST" else None)
|
||||
|
||||
def order_control_refund_render(self, order, request) -> str:
|
||||
template = get_template('pretixplugins/paypal/control_refund.html')
|
||||
ctx = {
|
||||
'request': request,
|
||||
'form': self._refund_form(request),
|
||||
}
|
||||
return template.render(ctx)
|
||||
|
||||
def order_control_refund_perform(self, request, order) -> "bool|str":
|
||||
f = self._refund_form(request)
|
||||
if not f.is_valid():
|
||||
messages.error(request, _('Your input was invalid, please try again.'))
|
||||
return
|
||||
elif f.cleaned_data.get('auto_refund') == 'manual':
|
||||
order = mark_order_refunded(order, user=request.user)
|
||||
order.payment_manual = True
|
||||
order.save()
|
||||
return
|
||||
|
||||
self.init_api()
|
||||
|
||||
if order.payment_info:
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
{% load bootstrap3 %}
|
||||
{% bootstrap_form form %}
|
||||
@@ -21,6 +21,18 @@ from pretix.plugins.stripe.models import ReferencedStripeObject
|
||||
logger = logging.getLogger('pretix.plugins.stripe')
|
||||
|
||||
|
||||
class RefundForm(forms.Form):
|
||||
auto_refund = forms.ChoiceField(
|
||||
initial='auto',
|
||||
label=_('Refund automatically?'),
|
||||
choices=(
|
||||
('auto', _('Automatically refund charge with Stripe')),
|
||||
('manual', _('Do not send refund instruction to Stripe, only mark as refunded in pretix'))
|
||||
),
|
||||
widget=forms.RadioSelect,
|
||||
)
|
||||
|
||||
|
||||
class StripeSettingsHolder(BasePaymentProvider):
|
||||
identifier = 'stripe_settings'
|
||||
verbose_name = _('Stripe')
|
||||
@@ -247,12 +259,30 @@ class StripeMethod(BasePaymentProvider):
|
||||
}
|
||||
return template.render(ctx)
|
||||
|
||||
def order_control_refund_render(self, order) -> str:
|
||||
return '<div class="alert alert-info">%s</div>' % _('The money will be automatically refunded.')
|
||||
def _refund_form(self, request):
|
||||
return RefundForm(data=request.POST if request.method == "POST" else None)
|
||||
|
||||
def order_control_refund_render(self, order, request) -> str:
|
||||
template = get_template('pretixplugins/stripe/control_refund.html')
|
||||
ctx = {
|
||||
'request': request,
|
||||
'form': self._refund_form(request),
|
||||
}
|
||||
return template.render(ctx)
|
||||
|
||||
def order_control_refund_perform(self, request, order) -> "bool|str":
|
||||
self._init_api()
|
||||
|
||||
f = self._refund_form(request)
|
||||
if not f.is_valid():
|
||||
messages.error(request, _('Your input was invalid, please try again.'))
|
||||
return
|
||||
elif f.cleaned_data.get('auto_refund') == 'manual':
|
||||
order = mark_order_refunded(order, user=request.user)
|
||||
order.payment_manual = True
|
||||
order.save()
|
||||
return
|
||||
|
||||
if order.payment_info:
|
||||
payment_info = json.loads(order.payment_info)
|
||||
else:
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
This order has been planned to be paid with {{ method }}, but the payment has not yet been completed.
|
||||
{% endblocktrans %}</p>
|
||||
{% endif %}
|
||||
{% if order.status == "p" %}
|
||||
{% if "source" in payment_info %}
|
||||
<dl class="dl-horizontal">
|
||||
<dt>{% trans "Charge ID" %}</dt>
|
||||
<dd>{{ payment_info.id }}</dd>
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
{% load bootstrap3 %}
|
||||
{% bootstrap_form form %}
|
||||
Reference in New Issue
Block a user