mirror of
https://github.com/pretix/pretix.git
synced 2026-05-05 15:14:04 +00:00
Fix #74 -- Warn if quota exceeds after payment
This commit is contained in:
@@ -8,7 +8,7 @@ from django.contrib import messages
|
||||
from django.template.loader import get_template
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from pretix.base.models import Quota
|
||||
from pretix.base.models import Quota, RequiredAction
|
||||
from pretix.base.payment import BasePaymentProvider
|
||||
from pretix.base.services.mail import SendMailException
|
||||
from pretix.base.services.orders import mark_order_paid, mark_order_refunded
|
||||
@@ -137,6 +137,12 @@ class Stripe(BasePaymentProvider):
|
||||
mark_order_paid(order, 'stripe', str(charge))
|
||||
except Quota.QuotaExceededException as e:
|
||||
messages.error(request, str(e))
|
||||
RequiredAction.objects.create(
|
||||
event=request.event, action_type='pretix.plugins.stripe.overpaid', data=json.dumps({
|
||||
'order': order.code,
|
||||
'charge': charge.id
|
||||
})
|
||||
)
|
||||
except SendMailException:
|
||||
messages.warning(request, _('There was an error sending the confirmation mail.'))
|
||||
|
||||
|
||||
@@ -63,10 +63,15 @@ def pretixcontrol_logentry_display(sender, logentry, **kwargs):
|
||||
|
||||
@receiver(signal=requiredaction_display, dispatch_uid="stripe_requiredaction_display")
|
||||
def pretixcontrol_action_display(sender, action, request, **kwargs):
|
||||
if action.action_type != 'pretix.plugins.stripe.refund':
|
||||
if not action.action_type.startswith('pretix.plugins.stripe'):
|
||||
return
|
||||
|
||||
data = json.loads(action.data)
|
||||
template = get_template('pretixplugins/stripe/action_refund.html')
|
||||
|
||||
if action.action_type == 'pretix.plugins.stripe.refund':
|
||||
template = get_template('pretixplugins/stripe/action_refund.html')
|
||||
elif action.action_type == 'pretix.plugins.stripe.overpaid':
|
||||
template = get_template('pretixplugins/stripe/action_overpaid.html')
|
||||
|
||||
ctx = {'data': data, 'event': sender, 'action': action}
|
||||
return template.render(ctx, request)
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
{% load i18n %}
|
||||
|
||||
<p>
|
||||
{% url "control:event.order" organizer=event.organizer.slug event=event.slug code=data.order as ourl %}
|
||||
{% blocktrans trimmed with charge=data.charge stripe_href="href='https://dashboard.stripe.com/payments/"|add:data.charge|add:"' target='_blank'"|safe order="<a href='"|add:ourl|add:"'>"|add:data.order|add:"</a>"|safe %}
|
||||
The Stripe transaction <a {{ stripe_href }}>{{ charge }}</a> has succeeded, but the order {{ order }} is
|
||||
expired and the product was sold out in the meantime. Therefore, the payment could not be acceped. Please
|
||||
contact the user and refund the money via Stripe's interface.
|
||||
{% endblocktrans %}
|
||||
</p>
|
||||
@@ -11,7 +11,7 @@ from django.utils.translation import ugettext_lazy as _
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.views.decorators.http import require_POST
|
||||
|
||||
from pretix.base.models import Order, RequiredAction
|
||||
from pretix.base.models import Order, Quota, RequiredAction
|
||||
from pretix.base.services.orders import mark_order_paid, mark_order_refunded
|
||||
from pretix.control.permissions import event_permission_required
|
||||
from pretix.plugins.stripe.payment import Stripe
|
||||
@@ -68,8 +68,18 @@ def webhook(request, *args, **kwargs):
|
||||
'charge': charge_id
|
||||
})
|
||||
)
|
||||
elif order.status == Order.STATUS_PENDING and charge['status'] == 'succeeded' and not is_refund:
|
||||
mark_order_paid(order, user=None)
|
||||
elif order.status in (Order.STATUS_PENDING, Order.STATUS_EXPIRED) and charge['status'] == 'succeeded' and not is_refund:
|
||||
try:
|
||||
mark_order_paid(order, user=None)
|
||||
except Quota.QuotaExceededException:
|
||||
if not RequiredAction.objects.filter(event=request.event, action_type='pretix.plugins.stripe.overpaid',
|
||||
data__icontains=order.code).exists():
|
||||
RequiredAction.objects.create(
|
||||
event=request.event, action_type='pretix.plugins.stripe.overpaid', data=json.dumps({
|
||||
'order': order.code,
|
||||
'charge': charge.id
|
||||
})
|
||||
)
|
||||
|
||||
return HttpResponse(status=200)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user