Stripe: when Stripe no longer has a client's customer, deleted there or made under other keys, forget it and the cards saved on it so the client sets up again, let new-card payments go ahead, tell agents, and remove the unused autopay_setup_stripe.js

This commit is contained in:
johnnyq
2026-11-19 01:34:48 -05:00
parent 3b1f1e8e8d
commit 875998bbb2
8 changed files with 116 additions and 27 deletions

View File

@@ -1,23 +0,0 @@
// Initialize Stripe.js
const stripe = Stripe(document.getElementById("stripe_publishable_key").value);
initialize();
// Fetch Checkout Session and retrieve the client secret
async function initialize() {
const fetchClientSecret = async () => {
const response = await fetch("/client/post.php?create_stripe_checkout", {
method: "POST",
});
const { clientSecret } = await response.json();
return clientSecret;
};
// Initialize Checkout
const checkout = await stripe.initEmbeddedCheckout({
fetchClientSecret,
});
// Mount Checkout
checkout.mount('#checkout');
}

View File

@@ -105,6 +105,12 @@
return fetch('/client/post.php?create_stripe_checkout', {method: 'POST', credentials: 'same-origin'})
.then(function (response) { return response.json(); })
.then(function (data) {
// Their Stripe customer was gone and has been forgotten - the page
// comes back with the Add a card step that sets them up again
if (data.reload) {
window.location.reload();
return new Promise(function () {});
}
if (!data.clientSecret) {
throw new Error(data.error || 'No checkout');
}