JezK
Edit File: payment_success.php
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .loaderLottie { position: absolute; top: 35%; height: 150px; } #overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); display: none; z-index: 9999; } </style> </head> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script src="https://js.stripe.com/v3/"></script> <script src="https://unpkg.com/@lottiefiles/lottie-player@latest/dist/lottie-player.js"></script> <body> <div id="overlay"> <lottie-player src="data.json" background="transparent" speed="1" class="loaderLottie" loop="true" autoplay="true"></lottie-player> </div> </body> <script> document.title = "Payment Processing"; const stripe = Stripe('pk_live_51HqxNhLB5kw3RTIU9z3VDeX67Umj8GiTZT36ZW7MZsxVhPDHYDCZoE59IG0RgycmIhY4VyRCYmJZMYj6Ax2aNpXf004vC00u5A'); $(document).ready(function () { makePageTransparent(); checkStatus(); }); async function checkStatus() { const clientSecret = new URLSearchParams(window.location.search).get("payment_intent_client_secret"); const customerID = new URLSearchParams(window.location.search).get("customer_id"); if (!clientSecret) { // makePageTransparent(); window.location.href = 'https://global-reia.org/events/'; // return; } const urlParams = new URLSearchParams(window.location.search); const intentId = urlParams.get('payment_intent'); const customer_ID = urlParams.get('customer_id'); const redirect_status = urlParams.get('redirect_status'); if (redirect_status) { try { switch (redirect_status) { case "succeeded": const response = await fetch("process_payment.php", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ request_type: 'payment_insert', payment_intent: intentId, customer_id: customer_ID }), }); console.log('Response:', response); if (!response.ok) { throw new Error(`HTTP error! Status: ${response.status}`); } const data = await response.json(); console.log('Data:', data); if (data.payment_txn_id) { window.location.href = 'https://global-reia.org/events/success.php?trans_id=' + data.payment_txn_id; } else { alert(data.error || "An unknown error occurred. Please try again."); window.location.href = 'https://global-reia.org/events/'; } break; case "processing": alert("Your payment is processing."); window.location.href = 'https://global-reia.org/events/'; break; case "requires_payment_method": alert("Your payment was not successful, please try again."); window.location.href = 'https://global-reia.org/events/'; break; default: alert("Something went wrong."); window.location.href = 'https://global-reia.org/events/'; break; } } catch (error) { console.error('Fetch error:', error.message); alert('Something went wrong. Please try again later.'); window.location.href = 'https://global-reia.org/events/'; } } else { alert("Something went wrong."); window.location.href = 'https://global-reia.org/events/'; } } function makePageTransparent() { var overlay = document.getElementById('overlay'); overlay.style.display = 'block'; // Display the overlay overlay.onclick = function () { return false; }; document.onclick = function () { return false; }; } </script> </html>