JezK
Edit File: payment_success_live_24th.php
<?php require_once('../wp-load.php'); ?> <?php define('WP_USE_THEMES', false); require('../wp-blog-header.php'); get_header(); //Include header ?> <?php include 'db_connection.php'; // if($_GET['trans_id']=='') { // header('Location:index.php'); // } $trans_id = $_GET['payment_intent']; // echo $trans_id; exit; $sqlQ = "UPDATE `payments` SET `payment_status`='succeeded' WHERE `payment_intent_id`='$trans_id'"; $result = $conn->query($sqlQ); $payment_details = "SELECT * FROM `payments` WHERE `payment_intent_id` = '$trans_id'"; $result = $conn->query($payment_details); $data = $result->fetch_assoc(); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Payment Success</title> <!-- Bootstrap CSS --> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> </head> <body> <div class="container mt-5"> <div class="jumbotron text-center"> <?php if($data['payment_status'] == 'succeeded') { ?> <h1 class="display-4">Payment Successful</h1> <?php } else { ?> <h1 class="display-4">Payment Failed</h1> <?php } ?> <hr class="my-4"> <h4>Transaction Details:</h4> <ul class="list-group"> <li class="list-group-item"><strong>Booking ID:</strong> <?php echo $data['booking_id']; ?></li> <li class="list-group-item"><strong>Payment Status:</strong> <?php echo $data['payment_status']; ?></li> <li class="list-group-item"><strong>Amount:</strong> € <?php echo $data['price']; ?></li> <li class="list-group-item"><strong>Date:</strong> <?php echo $data['date']; ?></li> <!-- <li class="list-group-item"><strong>Payment Method:</strong> Credit Card</li> --> </ul> </div> </div> </body> <script> document.title="Payment Success"; $(document).ready(function() { checkStatus() }) // Fetch the PaymentIntent status after payment submission async function checkStatus() { const clientSecret = new URLSearchParams(window.location.search).get( "payment_intent_client_secret" ); console.log(clientSecret,'clientSecret'); const customerID = new URLSearchParams(window.location.search).get( "customer_id" ); console.log(customerID,'customerID'); if (!clientSecret) { return; } const { paymentIntent } = await stripe.retrievePaymentIntent(clientSecret); console.log(paymentIntent,'paymentIntent'); // alert(paymentIntent) if (paymentIntent) { switch (paymentIntent.status) { case "succeeded": //showMessage("Payment succeeded!"); // Post the transaction info to the server-side script and redirect to the payment status page fetch("process_payment.php", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ request_type:'payment_insert', payment_intent: paymentIntent, customer_id: customerID }), }) .then(response => response.json()) .then(data => { if (data.payment_txn_id) { window.location.href = 'https://global-reia.org/events/payment_success.php?trans_id='+data.payment_txn_id; } else { alert(data.error); // setReinit(); } }) .catch(console.error); break; case "processing": alert("Your payment is processing."); // setReinit(); break; case "requires_payment_method": alert("Your payment was not successful, please try again."); // setReinit(); break; // default: alert("Something went wrong."); // setReinit(); break; } } else { alert("Something went wrong."); // setReinit(); } } </script> </html> <?php get_footer(); //Include header ?>