mirror of
https://github.com/pretix/pretix.git
synced 2026-05-03 14:54:04 +00:00
* [WIP] Failed Payment error handling When finished, this should fix #248 * rename PaymentFailedException to PaymentException\nimported Exception where neccessary * comments fixed * minor style fixes * Fixed a name error
This commit is contained in:
committed by
Raphael Michel
parent
8e4b71eb19
commit
c251a48e31
@@ -9,7 +9,7 @@ from django.template.loader import get_template
|
||||
from django.utils.translation import ugettext as __, ugettext_lazy as _
|
||||
|
||||
from pretix.base.models import Order, Quota, RequiredAction
|
||||
from pretix.base.payment import BasePaymentProvider
|
||||
from pretix.base.payment import BasePaymentProvider, PaymentException
|
||||
from pretix.base.services.mail import SendMailException
|
||||
from pretix.base.services.orders import mark_order_paid, mark_order_refunded
|
||||
from pretix.multidomain.urlreverse import build_absolute_uri
|
||||
@@ -145,17 +145,16 @@ class Paypal(BasePaymentProvider):
|
||||
"""
|
||||
if (request.session.get('payment_paypal_id', '') == ''
|
||||
or request.session.get('payment_paypal_payer', '') == ''):
|
||||
messages.error(request, _('We were unable to process your payment. See below for details on how to '
|
||||
'proceed.'))
|
||||
raise PaymentException(_('We were unable to process your payment. See below for details on how to '
|
||||
'proceed.'))
|
||||
|
||||
self.init_api()
|
||||
payment = paypalrestsdk.Payment.find(request.session.get('payment_paypal_id'))
|
||||
if str(payment.transactions[0].amount.total) != str(order.total) or payment.transactions[0].amount.currency != \
|
||||
self.event.currency:
|
||||
messages.error(request, _('We were unable to process your payment. See below for details on how to '
|
||||
'proceed.'))
|
||||
logger.error('Value mismatch: Order %s vs payment %s' % (order.id, str(payment)))
|
||||
return
|
||||
raise PaymentException(_('We were unable to process your payment. See below for details on how to '
|
||||
'proceed.'))
|
||||
|
||||
return self._execute_payment(payment, request, order)
|
||||
|
||||
@@ -196,9 +195,9 @@ class Paypal(BasePaymentProvider):
|
||||
return
|
||||
|
||||
if payment.state != 'approved':
|
||||
messages.error(request, _('We were unable to process your payment. See below for details on how to '
|
||||
'proceed.'))
|
||||
logger.error('Invalid state: %s' % str(payment))
|
||||
raise PaymentException(_('We were unable to process your payment. See below for details on how to '
|
||||
'proceed.'))
|
||||
return
|
||||
|
||||
if order.status == Order.STATUS_PAID:
|
||||
@@ -208,13 +207,14 @@ class Paypal(BasePaymentProvider):
|
||||
try:
|
||||
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
|
||||
})
|
||||
)
|
||||
raise PaymentException(str(e))
|
||||
|
||||
except SendMailException:
|
||||
messages.warning(request, _('There was an error sending the confirmation mail.'))
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user