Skip to content

Commit

Permalink
Prevent duplicate payment confirmation mails
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelm committed Jan 22, 2017
1 parent 04369ff commit 221526c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/pretix/base/services/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ def mark_order_paid(order: Order, provider: str=None, info: str=None, date: date
:type mail_text: str
:raises Quota.QuotaExceededException: if the quota is exceeded and ``force`` is ``False``
"""
if order.status == Order.STATUS_PAID:
return order

with order.event.lock() as now_dt:
can_be_paid = order._can_be_paid()
if not force and can_be_paid is not True:
Expand Down
6 changes: 5 additions & 1 deletion src/pretix/plugins/paypal/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.template.loader import get_template
from django.utils.translation import ugettext as __, ugettext_lazy as _

from pretix.base.models import Quota, RequiredAction
from pretix.base.models import Order, 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
Expand Down Expand Up @@ -199,6 +199,10 @@ def _execute_payment(self, payment, request, order):
logger.error('Invalid state: %s' % str(payment))
return

if order.status == Order.STATUS_PAID:
logger.warning('PayPal success event even though order is already marked as paid')
return

try:
mark_order_paid(order, 'paypal', json.dumps(payment.to_dict()))
except Quota.QuotaExceededException as e:
Expand Down
4 changes: 3 additions & 1 deletion src/pretix/presale/views/cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ def _item_from_post_value(self, key, value, voucher=None):
amount = int(value)
except ValueError:
raise CartError(_('Please enter numbers only.'))
if amount <= 0:
if amount < 0:
raise CartError(_('Please enter positive numbers only.'))
elif amount == 0:
return

price = self.request.POST.get('price_' + "_".join(parts[1:]), "")
if key.startswith('item_'):
Expand Down

0 comments on commit 221526c

Please sign in to comment.