forked from CGM_Public/pretix_original
PayPal: Fixed URL names and exception handling
This commit is contained in:
@@ -108,19 +108,23 @@ class Paypal(BasePaymentProvider):
|
|||||||
return self._create_payment(request, payment)
|
return self._create_payment(request, payment)
|
||||||
|
|
||||||
def _create_payment(self, request, payment):
|
def _create_payment(self, request, payment):
|
||||||
if payment.create():
|
try:
|
||||||
if payment.state not in ('created', 'approved', 'pending'):
|
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'))
|
messages.error(request, _('We had trouble communicating with PayPal'))
|
||||||
logger.error('Invalid payment state: ' + str(payment))
|
logger.error('Error on creating payment: ' + str(payment.error))
|
||||||
return
|
except Exception as e:
|
||||||
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'))
|
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:
|
def checkout_confirm_render(self, request) -> str:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ from .views import success, abort, retry
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^paypal/', include([
|
url(r'^paypal/', include([
|
||||||
url(r'^abort/$', abort, name='paypal.abort'),
|
url(r'^abort/$', abort, name='abort'),
|
||||||
url(r'^return/$', success, name='paypal.return'),
|
url(r'^return/$', success, name='return'),
|
||||||
url(r'^retry/(?P<order>[^/]+)/', retry, name='paypal.retry')
|
url(r'^retry/(?P<order>[^/]+)/', retry, name='retry')
|
||||||
])),
|
])),
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user