feat: Update subscribe buttons to use Discord OAuth flow

WHAT: Changed handleSubscribe() to redirect to OAuth endpoint
WHY: Discord-Stripe linking requires OAuth before checkout

Old flow: Button → API call → Stripe checkout (no Discord ID)
New flow: Button → Discord OAuth → Stripe checkout (Discord ID linked)

Endpoint: https://discord-bot.firefrostgaming.com/stripe/auth?tier=X

Signed-off-by: Claude <claude@firefrostgaming.com>
This commit is contained in:
Claude (Chronicler #58)
2026-04-03 23:23:30 +00:00
parent 243b9d41f0
commit 3d8d1b50d5

View File

@@ -196,42 +196,18 @@ description: Choose your tier and join the Firefrost Gaming community
<p style="font-size: 1em; color: rgba(255,255,255,0.7); margin: 0;"><em>Fire + Frost + Foundation = Where Love Builds Legacy</em></p> <p style="font-size: 1em; color: rgba(255,255,255,0.7); margin: 0;"><em>Fire + Frost + Foundation = Where Love Builds Legacy</em></p>
</div> </div>
<!-- Stripe Checkout JavaScript Handler --> <!-- Discord OAuth → Stripe Checkout Handler -->
<script> <script>
async function handleSubscribe(event, tierLevel) { function handleSubscribe(event, tierLevel) {
const button = event.currentTarget; const button = event.currentTarget;
const originalText = button.innerHTML;
// 1. Lock the button immediately (Prevent double-clicks) // Lock the button immediately (Prevent double-clicks)
button.disabled = true; button.disabled = true;
button.style.opacity = '0.7'; button.style.opacity = '0.7';
button.style.cursor = 'wait'; button.style.cursor = 'wait';
button.innerHTML = 'Connecting to Stripe...'; button.innerHTML = 'Connecting to Discord...';
try { // Redirect to OAuth flow - Discord login then Stripe checkout
const response = await fetch('https://discord-bot.firefrostgaming.com/stripe/create-checkout-session', { window.location.href = `https://discord-bot.firefrostgaming.com/stripe/auth?tier=${tierLevel}`;
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ tier_level: tierLevel })
});
if (!response.ok) throw new Error('Network response was not ok');
const data = await response.json();
// 2. Redirect to Stripe
window.location.href = data.checkout_url;
} catch (error) {
// 3. Graceful Error Recovery
console.error('Checkout Error:', error);
alert('Unable to connect to the billing system. Please try again or contact The Trinity in Discord.');
// Reset button
button.disabled = false;
button.style.opacity = '1';
button.style.cursor = 'pointer';
button.innerHTML = originalText;
}
} }
</script> </script>