diff --git a/src/pretix/plugins/paypal/payment.py b/src/pretix/plugins/paypal/payment.py index 22c4b9b9f7..95a0509b1e 100644 --- a/src/pretix/plugins/paypal/payment.py +++ b/src/pretix/plugins/paypal/payment.py @@ -108,19 +108,23 @@ class Paypal(BasePaymentProvider): return self._create_payment(request, payment) def _create_payment(self, request, payment): - if payment.create(): - if payment.state not in ('created', 'approved', 'pending'): + try: + if payment.create(): + if payment.state not in ('created', 'approved', 'pending'): + messages.error(request, _('We had trouble communicating with PayPal')) + logger.error('Invalid payment state: ' + str(payment)) + return + request.session['payment_paypal_id'] = payment.id + request.session['payment_paypal_event'] = self.event.id + for link in payment.links: + if link.method == "REDIRECT" and link.rel == "approval_url": + return str(link.href) + else: messages.error(request, _('We had trouble communicating with PayPal')) - logger.error('Invalid payment state: ' + str(payment)) - return - request.session['payment_paypal_id'] = payment.id - request.session['payment_paypal_event'] = self.event.id - for link in payment.links: - if link.method == "REDIRECT" and link.rel == "approval_url": - return str(link.href) - else: + logger.error('Error on creating payment: ' + str(payment.error)) + except Exception as e: messages.error(request, _('We had trouble communicating with PayPal')) - logger.error('Error on creating payment: ' + str(payment.error)) + logger.error('Error on creating payment: ' + str(e)) def checkout_confirm_render(self, request) -> str: """ diff --git a/src/pretix/plugins/paypal/urls.py b/src/pretix/plugins/paypal/urls.py index 1c6e5f4cc5..fb6148b23c 100644 --- a/src/pretix/plugins/paypal/urls.py +++ b/src/pretix/plugins/paypal/urls.py @@ -5,8 +5,8 @@ from .views import success, abort, retry urlpatterns = [ url(r'^paypal/', include([ - url(r'^abort/$', abort, name='paypal.abort'), - url(r'^return/$', success, name='paypal.return'), - url(r'^retry/(?P[^/]+)/', retry, name='paypal.retry') + url(r'^abort/$', abort, name='abort'), + url(r'^return/$', success, name='return'), + url(r'^retry/(?P[^/]+)/', retry, name='retry') ])), ]