- Create BilletBuyer entity: event, user (nullable for guests), firstName,
lastName, email, reference (ETICKET-XXXX-XXXX-XXXX), totalHT, status,
stripeSessionId, paidAt, items (OneToMany)
- Create BilletBuyerItem entity: billet, billetName (snapshot), quantity,
unitPriceHT, line total helpers
- OrderController with full checkout flow:
- POST /evenement/{id}/commander: create order from cart JSON
- GET/POST /commande/{id}/informations: guest form (name, email)
- GET /commande/{id}/paiement: payment page with recap
- POST /commande/{id}/stripe: Stripe Checkout on connected account
with application_fee, productId, and quantities
- GET /commande/{id}/confirmation: success page
- Cart JS: POST cart data on Commander click, redirect to guest/payment
- Templates: guest form, payment page, order summary partial, success page
- Stripe payment uses organizer connected account, application_fee based
on commissionRate, existing productId when available
- Tests: BilletBuyerTest (12), BilletBuyerItemTest (6), cart.test.js (13)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
101 lines
3.2 KiB
JavaScript
101 lines
3.2 KiB
JavaScript
function formatEur(value) {
|
|
return value.toFixed(2).replace('.', ',') + ' \u20AC'
|
|
}
|
|
|
|
export function initCart() {
|
|
const billetterie = document.getElementById('billetterie')
|
|
if (!billetterie) return
|
|
|
|
const items = billetterie.querySelectorAll('[data-cart-item]')
|
|
const totalEl = document.getElementById('cart-total')
|
|
const countEl = document.getElementById('cart-count')
|
|
const checkoutBtn = document.getElementById('cart-checkout')
|
|
if (!totalEl || !countEl) return
|
|
|
|
function updateTotals() {
|
|
let total = 0
|
|
let count = 0
|
|
|
|
for (const item of items) {
|
|
const price = Number.parseFloat(item.dataset.price) || 0
|
|
const qtyInput = item.querySelector('[data-cart-qty]')
|
|
const lineTotalEl = item.querySelector('[data-cart-line-total]')
|
|
const qty = Number.parseInt(qtyInput.value, 10) || 0
|
|
|
|
const lineTotal = price * qty
|
|
total += lineTotal
|
|
count += qty
|
|
|
|
lineTotalEl.textContent = formatEur(lineTotal)
|
|
}
|
|
|
|
totalEl.textContent = formatEur(total)
|
|
countEl.textContent = String(count)
|
|
|
|
if (checkoutBtn) {
|
|
checkoutBtn.disabled = count === 0
|
|
}
|
|
}
|
|
|
|
for (const item of items) {
|
|
const qtyInput = item.querySelector('[data-cart-qty]')
|
|
const minusBtn = item.querySelector('[data-cart-minus]')
|
|
const plusBtn = item.querySelector('[data-cart-plus]')
|
|
const max = Number.parseInt(item.dataset.max, 10) || 0
|
|
|
|
minusBtn.addEventListener('click', () => {
|
|
const current = Number.parseInt(qtyInput.value, 10) || 0
|
|
if (current > 0) {
|
|
qtyInput.value = current - 1
|
|
updateTotals()
|
|
}
|
|
})
|
|
|
|
plusBtn.addEventListener('click', () => {
|
|
const current = Number.parseInt(qtyInput.value, 10) || 0
|
|
if (max === 0 || current < max) {
|
|
qtyInput.value = current + 1
|
|
updateTotals()
|
|
}
|
|
})
|
|
}
|
|
|
|
if (checkoutBtn) {
|
|
checkoutBtn.addEventListener('click', () => {
|
|
const cart = []
|
|
for (const item of items) {
|
|
const qty = Number.parseInt(item.querySelector('[data-cart-qty]').value, 10) || 0
|
|
if (qty > 0) {
|
|
cart.push({ billetId: item.dataset.billetId, qty })
|
|
}
|
|
}
|
|
|
|
if (cart.length === 0) return
|
|
|
|
const orderUrl = checkoutBtn.dataset.orderUrl
|
|
if (!orderUrl) return
|
|
|
|
checkoutBtn.disabled = true
|
|
checkoutBtn.textContent = 'Chargement...'
|
|
|
|
globalThis.fetch(orderUrl, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(cart),
|
|
})
|
|
.then(r => r.json())
|
|
.then(data => {
|
|
if (data.redirect) {
|
|
globalThis.location.href = data.redirect
|
|
}
|
|
})
|
|
.catch(() => {
|
|
checkoutBtn.disabled = false
|
|
checkoutBtn.textContent = 'Commander'
|
|
})
|
|
})
|
|
}
|
|
|
|
updateTotals()
|
|
}
|