|
| 1 | +<?php include 'partials/header.php'; ?> |
| 2 | +<h1>Simulation de paiement</h1> |
| 3 | +<h2>Total: <?= htmlspecialchars((string) $total) ?> €</h2> |
| 4 | + |
| 5 | +<form id="payment-form"> |
| 6 | + <!-- Nom Complet --> |
| 7 | + <label for="full-name">Nom Complet</label> |
| 8 | + <input type="text" id="full-name" name="customer_name"/> |
| 9 | + |
| 10 | + <!-- Email --> |
| 11 | + <label for="email">Email</label> |
| 12 | + <input type="email" id="email" name="email"/> |
| 13 | + |
| 14 | + <!-- Adresse --> |
| 15 | + <label for="address">Adresse de livraison</label> |
| 16 | + <input type="text" id="address" name="address"/> |
| 17 | + |
| 18 | + <hr> |
| 19 | + |
| 20 | + <!-- Numéro de carte --> |
| 21 | + <label for="card-number">Numéro de carte</label> |
| 22 | + <input type="text" id="card-number" name="card-number"/> |
| 23 | + |
| 24 | + <!-- CVC (Corrigé : l'ID doit correspondre au FOR) --> |
| 25 | + <label for="cvc-number">CVC</label> |
| 26 | + <input type="text" id="cvc-number" name="cvc-number"/> |
| 27 | + |
| 28 | + <!-- Date d'expiration (Corrigé : Ajout de l'ID manquant) --> |
| 29 | + <label for="expiration-date">Date d'expiration</label> |
| 30 | + <input type="date" id="expiration-date" name="expiration-date"/> |
| 31 | + |
| 32 | + <!-- Boutons --> |
| 33 | + <button type="submit" onclick="this.form.dataset.status=2" name="pay-success">Simuler succès</button> |
| 34 | + <button type="submit" onclick="this.form.dataset.status=3" name="pay-failure">Simuler échec</button> |
| 35 | +</form> |
| 36 | +<h3 id="checkout-info"></h3> |
| 37 | + |
| 38 | +<script> |
| 39 | + |
| 40 | +fetch('/account-data') |
| 41 | + .then(response => { |
| 42 | + // Session has been lost |
| 43 | + if (response.status === 401) { |
| 44 | + window.location.href = '/sign-in'; |
| 45 | + return; |
| 46 | + } |
| 47 | + |
| 48 | + return response.json(); |
| 49 | +}) |
| 50 | +.then(data => { |
| 51 | +if (data && !data.error) { |
| 52 | + document.getElementById("full-name").placeholder = |
| 53 | + data.first_name + |
| 54 | + " " + |
| 55 | + data.last_name; |
| 56 | + |
| 57 | + document.getElementById("email").placeholder = data.email |
| 58 | +} |
| 59 | +}) |
| 60 | + |
| 61 | +document.getElementById('payment-form').addEventListener('submit', function(e) { |
| 62 | + e.preventDefault(); |
| 63 | + |
| 64 | + const formData = new FormData(this); |
| 65 | + const data = Object.fromEntries(formData.entries()); |
| 66 | + const checkoutInfo = document.getElementById("checkout-info"); |
| 67 | + |
| 68 | + data.simulate_status = this.dataset.status; |
| 69 | + fetch('/checkout/saveOrder', { |
| 70 | + method: 'POST', |
| 71 | + headers: { 'Content-Type': 'application/json' }, |
| 72 | + body: JSON.stringify(data) |
| 73 | + }) |
| 74 | + .then(response => response.json()) |
| 75 | + .then(result => { |
| 76 | + checkoutInfo.innerText = result.message; |
| 77 | + }); |
| 78 | +}); |
| 79 | + |
| 80 | +</script> |
0 commit comments