HOw does the redirection for order page work in pretix?
ChatGPT said:
In Pretix, redirection for the order page typically occurs after a customer completes their checkout process. Here’s how the redirection logic generally works:
🔁 Redirection Overview in Pretix
- User Journey:
- A user selects tickets → fills in attendee info → selects payment method → submits the order.
- After order submission, the system generates an order code (like
ABC12) and redirects the user to the order page URL: php-templateCopyEdit/event/<organizer>/<event>/order/<order_code>/
- Code Behind the Redirection: The redirection is handled in the
pretix/control/views/event.pyorpretix/presale/views/order.pydepending on context. - Typical Redirect Example (after successful payment or order submission): pythonCopyEdit
return redirect(event.get_absolute_url() + 'order/' + order.code + '/') - Order URL Structure: The URL looks like: php-templateCopyEdit
https://example.com/<organizer>/<event>/order/<order_code>/This is served by theOrderDetailViewinpretix/presale/views/order.py. - Session Storage for Redirection:
- Pretix stores the
orderin the session (session['pretix_order_code']). - This allows for automatic redirection to the order page if the user is returning from an external payment provider.
- Pretix stores the
✅ Payment Flow Redirection
If a payment method (e.g., Stripe, PayPal) is used:
- The user may leave the site → pay → get redirected back to: php-templateCopyEdit
/<organizer>/<event>/order/<order_code>/?paid=1 - Pretix uses this to display a confirmation message like “Your order was successfully paid.”
🧠 Developer Tip
If you’re customizing Pretix or creating a plugin, you can trigger an order page redirect with:
pythonCopyEditfrom django.shortcuts import redirect
return redirect(order.event.get_absolute_url() + 'order/' + order.code + '/')
Want to trace how it works in source code or debug something specific? I can help you follow the exact function call path.
You said:
der.code + ‘/’)
camn you give simple prototype code to have a custom web page with a pulldown of available seats, a custormer name, an additional text field, and send this to pretix to complete the order?
ChatGPT said:
Absolutely! Here’s a simple prototype that creates a custom web page where a user:
- Selects an available seat (via dropdown)
- Enters their name
- Adds some extra info
- Submits the form → sends data to Pretix to place the order
⚠️ This is a simplified example and assumes Pretix is already set up with a product and seating plan.
🧩 Assumptions
- Event has a seating plan enabled.
- The product is already created in Pretix and tied to seats.
- Your code interacts with Pretix via its REST API.
🔧 Flask Web Prototype (Python)
pythonCopyEditfrom flask import Flask, render_template_string, request, redirect
import requests
app = Flask(__name__)
# Your Pretix API credentials
API_TOKEN = 'YOUR_PRETIX_API_TOKEN'
ORGANIZER = 'yourorg'
EVENT = 'yourevent'
API_URL = f'https://pretix.yourdomain/api/v1/organizers/{ORGANIZER}/events/{EVENT}'
# HTML template with dropdown and fields
HTML = '''
<form method="POST">
<label for="seat">Select a Seat:</label>
<select name="seat" required>
{% for seat in seats %}
<option value="{{ seat['id'] }}">{{ seat['name'] }}</option>
{% endfor %}
</select><br><br>
<label for="name">Your Name:</label>
<input type="text" name="name" required><br><br>
<label for="note">Extra Info:</label>
<input type="text" name="note"><br><br>
<button type="submit">Submit</button>
</form>
'''
# Get available seats from Pretix
def get_available_seats():
r = requests.get(f'{API_URL}/seating/plan/', headers={'Authorization': f'Token {API_TOKEN}'})
plans = r.json()
seats = []
for plan in plans:
for seat in plan.get('seats', []):
if seat['free']: # filter only free seats
seats.append(seat)
return seats
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
seat_id = request.form['seat']
name = request.form['name']
note = request.form['note']
# Create order payload
payload = {
"positions": [{
"item": YOUR_PRODUCT_ID, # Replace with real item ID
"seat": seat_id,
"attendee_name": name
}],
"locale": "en",
"order_meta_data": {
"note": note
}
}
response = requests.post(f'{API_URL}/orders/', headers={
'Authorization': f'Token {API_TOKEN}',
'Content-Type': 'application/json'
}, json=payload)
if response.status_code == 201:
order = response.json()
return redirect(order['url']) # Redirect to order page
else:
return f"Error creating order: {response.text}", 400
seats = get_available_seats()
return render_template_string(HTML, seats=seats)
if __name__ == '__main__':
app.run(debug=True)
🔐 You Need To Replace:
YOUR_PRETIX_API_TOKEN→ your API tokenyourorgandyourevent→ your actual organizer and event slugsYOUR_PRODUCT_ID→ the actual product/item ID (can fetch via/items/endpoint)
✅ Outcome
This prototype:
- Lists available seats
- Lets the user fill in name + note
- Sends it to Pretix via API
- Redirects to the generated Pretix order page
Would you like help making it production-ready or integrating with a Pretix plugin?
