This commit is contained in:
2025-03-09 22:13:57 -04:00
parent 792a64fd13
commit 279d56481b
4 changed files with 126 additions and 76 deletions

View File

@@ -13,7 +13,7 @@
Number of Tickets:<br>
<input type="number" min="1" max="4" step="1" placeholder="1" name="qty"><br>
Pay how much for each ticket:<br>
<input type="number" min="1.00" max="1000.00" step="0.01" placeholder="50.00" name="amount"><br>
<input type="number" min="1.00" max="1000.00" step="0.01" placeholder="50.00" name="amounteach"><br>
<button id="Submit" type="submit">Pay</button>
</form>
</div>

View File

@@ -8,8 +8,9 @@
<%- include('partials/nav') %>
<div class="content">
<form id="payment-form">
Payment Here!!!<%=amount%>
<!-- Stripe Elements will inject the Card Element here -->
You are about to charge $<%=payforwhat.total.toFixed(2)%> for <%=payforwhat.qty%> tickets.<br>
<label for="card-number-element">Card Number</label>
<div id="card-number-element"></div>
@@ -23,7 +24,7 @@ Payment Here!!!<%=amount%>
<label for="card-postal-element">ZIP Code</label>
<div id="card-postal-element"></div>
<button id="submit-button" type="submit">Pay <%=amount%> Now</button>
<button id="submit-button" type="submit">Pay Now</button>
</form>
</div>
<!-- Stripe.js -->
@@ -46,54 +47,54 @@ Payment Here!!!<%=amount%>
const paymentForm = document.getElementById("payment-form");
paymentForm.addEventListener("submit", async (e) => {
e.preventDefault();
e.preventDefault();
// 1. Create a PaymentMethod
const { paymentMethod, error } = await stripe.createPaymentMethod({
// 1. Create a PaymentMethod
const { paymentMethod, error } = await stripe.createPaymentMethod({
type: "card",
card: cardNumberElement,
});
});
if (error) {
if (error) {
console.error(error);
alert(error.message);
return;
}
}
// 2. Send PaymentMethod ID to server
const response = await fetch("/charge", {
// 2. Send PaymentMethod ID to server
console.log("Payforwhat: ",<%-JSON.stringify(payforwhat)%>);
const pfw = <%-JSON.stringify(payforwhat)%>;
const response = await fetch("/charge", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ paymentMethodId: paymentMethod.id, ticket:"<%=ticket%>", amount:"<%=amount%>" }),
});
body: JSON.stringify({ paymentMethodId: paymentMethod.id, payforwhat: pfw }),
});
const responseData = await response.json();
const responseData = await response.json();
if (responseData.error) {
if (responseData.error) {
console.error(responseData.error);
alert(responseData.error);
return;
}
}
if (responseData.requiresAction) {
// 3. Handle Additional Action if required (e.g., 3DS)
const { error: confirmError } = await stripe.confirmCardPayment(
responseData.paymentIntentClientSecret
);
if (responseData.requiresAction) {
// 3. Handle Additional Action if required (e.g., 3DS)
const { error: confirmError } = await stripe.confirmCardPayment(responseData.paymentIntentClientSecret);
if (confirmError) {
if (confirmError) {
console.error(confirmError);
alert(confirmError.message);
return;
}
}
alert("Payment succeeded");
// redirect or show success message
window.location.href = responseData.redirect_url;
} else if (responseData.success) {
// Payment succeeded without additional action
alert("Payment succeeded.");
window.location.href = responseData.redirect_url;
alert("Payment succeeded");
// redirect or show success message
window.location.href = responseData.redirect_url;
} else if (responseData.success) {
// Payment succeeded without additional action
alert("Payment succeeded.");
window.location.href = responseData.redirect_url;
}
});
</script>

View File

@@ -23,7 +23,13 @@
<form action='/deserialize' method='post'>
<button type="submit" >Deserialize</button>
</form>
<form action='/killmagiclink' method='post'>
Deactivate Magic Links for:
<input type="email" name="email">
<button type="submit">Deactivate</button>
</form>
<form action="/importfb" method="post" enctype="multipart/form-data">
Import Tickets (Frostburn Format):
<input type="file" name="file">
<input type="submit" value="Upload">
</form>