53 lines
1.8 KiB
HTML
53 lines
1.8 KiB
HTML
{% load static %}
|
|
<!DOCTYPE html>
|
|
<html>
|
|
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<link rel="icon" type="image/x-icon" href="/static/images/icon.png">
|
|
<title>Goodtimes</title>
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css">
|
|
<script defer src="https://use.fontawesome.com/releases/v6.4.0/js/all.js"></script>
|
|
<script src="https://js.stripe.com/v3/"></script>
|
|
</head>
|
|
|
|
<body>
|
|
<section class="section">
|
|
<div class="container">
|
|
<button class="button is-primary" id="submitBtn">Subscribe!</button>
|
|
</div>
|
|
</section>
|
|
|
|
|
|
<script>
|
|
console.log("Sanity check!");
|
|
|
|
// Get Stripe publishable key
|
|
fetch("http://localhost:8000/subscriptions/stripe-subscription/")
|
|
.then((result) => { return result.json(); })
|
|
.then((data) => {
|
|
// Initialize Stripe.js
|
|
const stripe = Stripe(data.publicKey);
|
|
|
|
// new
|
|
// Event handler
|
|
document.querySelector("#submitBtn").addEventListener("click", () => {
|
|
// Get Checkout Session ID
|
|
fetch("http://localhost:8000/subscriptions/create-checkout-session/")
|
|
.then((result) => { return result.json(); })
|
|
.then((data) => {
|
|
console.log(data);
|
|
// Redirect to Stripe Checkout
|
|
return stripe.redirectToCheckout({ sessionId: data.sessionId })
|
|
})
|
|
.then((res) => {
|
|
console.log(res);
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html> |