Fix #74 -- Warn if quota exceeds after payment

This commit is contained in:
Raphael Michel
2017-01-04 19:19:58 +01:00
parent 847997ea9b
commit b23d95b6c3
8 changed files with 74 additions and 12 deletions

View File

@@ -8,7 +8,7 @@ from django.contrib import messages
from django.template.loader import get_template
from django.utils.translation import ugettext as __, 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
@@ -203,6 +203,12 @@ class Paypal(BasePaymentProvider):
mark_order_paid(order, 'paypal', json.dumps(payment.to_dict()))
except Quota.QuotaExceededException as e:
messages.error(request, str(e))
RequiredAction.objects.create(
event=request.event, action_type='pretix.plugins.paypal.overpaid', data=json.dumps({
'order': order.code,
'payment': payment.id
})
)
except SendMailException:
messages.warning(request, _('There was an error sending the confirmation mail.'))
return None

View File

@@ -39,10 +39,15 @@ def pretixcontrol_logentry_display(sender, logentry, **kwargs):
@receiver(signal=requiredaction_display, dispatch_uid="paypal_requiredaction_display")
def pretixcontrol_action_display(sender, action, request, **kwargs):
if action.action_type != 'pretix.plugins.paypal.refund':
if not action.action_type.startswith('pretix.plugins.paypal'):
return
data = json.loads(action.data)
template = get_template('pretixplugins/paypal/action_refund.html')
if action.action_type == 'pretix.plugins.paypal.refund':
template = get_template('pretixplugins/paypal/action_refund.html')
elif action.action_type == 'pretix.plugins.paypal.overpaid':
template = get_template('pretixplugins/paypal/action_overpaid.html')
ctx = {'data': data, 'event': sender, 'action': action}
return template.render(ctx, request)

View File

@@ -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 payment=data.payment order="<a href='"|add:ourl|add:"'>"|add:data.order|add:"</a>"|safe %}
The PayPal transaction {{ payment }} 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 PayPal's interface.
{% endblocktrans %}
</p>

View File

@@ -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.multidomain.urlreverse import eventreverse
@@ -103,8 +103,18 @@ def webhook(request, *args, **kwargs):
'sale': sale['id']
})
)
elif order.status == Order.STATUS_PENDING and sale['state'] == 'completed':
mark_order_paid(order, user=None)
elif order.status in (Order.STATUS_PENDING, Order.STATUS_EXPIRED) and sale['state'] == 'completed':
try:
mark_order_paid(order, user=None)
except Quota.QuotaExceededException:
if not RequiredAction.objects.filter(event=request.event, action_type='pretix.plugins.paypal.overpaid',
data__icontains=order.code).exists():
RequiredAction.objects.create(
event=request.event, action_type='pretix.plugins.paypal.overpaid', data=json.dumps({
'order': order.code,
'payment': sale['parent_payment']
})
)
return HttpResponse(status=200)