Return URL: Append error/success message to query

This commit is contained in:
Raphael Michel
2021-12-03 10:30:33 +01:00
parent c6fd5bc864
commit d0685e99ad
2 changed files with 25 additions and 2 deletions

View File

@@ -97,7 +97,8 @@ For example, if you want users to be redirected to ``https://example.org/order/r
either enter ``https://example.org`` or ``https://example.org/order/``. either enter ``https://example.org`` or ``https://example.org/order/``.
The user will be redirected back to your page instead of pretix' order confirmation page after the payment, The user will be redirected back to your page instead of pretix' order confirmation page after the payment,
**regardless of whether it was successful or not**. Make sure you use our API to check if the payment actually **regardless of whether it was successful or not**. We will append an ``error=…`` query parameter with an error
message, but you should not rely on that and instead make sure you use our API to check if the payment actually
worked! Your final URL could look like this:: worked! Your final URL could look like this::
https://test.pretix.eu/democon/3vjrh/order/NSLEZ/ujbrnsjzbq4dzhck/pay/123/?return_url=https%3A%2F%2Fexample.org%2Forder%2Freturn%3Ftx_id%3D1234 https://test.pretix.eu/democon/3vjrh/order/NSLEZ/ujbrnsjzbq4dzhck/pay/123/?return_url=https%3A%2F%2Fexample.org%2Forder%2Freturn%3Ftx_id%3D1234

View File

@@ -19,6 +19,10 @@
# You should have received a copy of the GNU Affero General Public License along with this program. If not, see # You should have received a copy of the GNU Affero General Public License along with this program. If not, see
# <https://www.gnu.org/licenses/>. # <https://www.gnu.org/licenses/>.
# #
from urllib.parse import urlencode
from django.contrib.messages import get_messages
from django.contrib.messages import constants as messages
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
from django.dispatch import receiver from django.dispatch import receiver
from django.shortcuts import redirect from django.shortcuts import redirect
@@ -43,7 +47,25 @@ def returnurl_process_request(sender, request, **kwargs):
key = 'order_{}_{}_{}_return_url'.format(urlkwargs.get('organizer', '-'), urlkwargs.get('event', '-'), key = 'order_{}_{}_{}_return_url'.format(urlkwargs.get('organizer', '-'), urlkwargs.get('event', '-'),
urlkwargs['order']) urlkwargs['order'])
if urlname == 'event.order' and key in request.session: if urlname == 'event.order' and key in request.session:
r = redirect(request.session.get(key)) url = request.session.get(key)
query = []
storage = get_messages(request)
for message in storage:
if message.level == messages.ERROR:
query.append(('error', str(message)))
elif message.level == messages.WARNING:
query.append(('warning', str(message)))
if message.level == messages.INFO:
query.append(('info', str(message)))
if message.level == messages.SUCCESS:
query.append(('success', str(message)))
if query:
if '?' in url:
url += '&' + urlencode(query)
else:
url += '?' + urlencode(query)
r = redirect(url)
del request.session[key] del request.session[key]
return r return r
elif urlname != 'event.order' and 'return_url' in request.GET: elif urlname != 'event.order' and 'return_url' in request.GET: