forked from stripe-samples/github-pages-stripe-checkout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
84 lines (77 loc) · 3 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>CourseHorse Tips</title>
<meta name="description" content="Tip CourseHorse!" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="css/normalize.css" />
<link rel="stylesheet" href="css/global.css" />
<!-- Load Stripe.js on your website. -->
<script src="https://js.stripe.com/v3/"></script>
</head>
<body>
<div class="sr-root">
<div class="sr-main" style="display: flex;">
<header class="sr-header">
<div class="sr-header__logo"></div>
</header>
<div>
<p>Thanks so much for joining us!</p>
<p>If you enjoyed it & have the means, we really appreciate any tips.</p>
<p>They truly go a long way to helping us continue to offer these free events.</p>
</div>
<div class="sr-container">
<section class="container">
<button data-sku-id="sku_HF3lFSibY71hbk">Tip $1.00</button>
<button data-sku-id="sku_HF3l3nQfEvJ3Wt">Tip $2.00</button>
<button data-sku-id="sku_HF3l8wPWJhEPtu">Tip $5.00</button>
<button data-sku-id="sku_HF3lRqnoDUWdBM">Tip $10.00</button>
<button data-sku-id="sku_HF3lXD5Whw0tgF">Tip $20.00</button>
</section>
</div>
<div id="error-message"></div>
</div>
</div>
<div class="footer">
<span class="banner">
Made with 🐴 by CourseHorse
</span>
</div>
<script>
// Replace with your own publishable key: https://dashboard.stripe.com/test/apikeys
var PUBLISHABLE_KEY = "pk_live_X3Cozk41eAnopPXQoavHLBVl";
// Replace with the domain you want your users to be redirected back to after payment
var DOMAIN = location.href.replace(/[^/]*$/, "");
var stripe = Stripe(PUBLISHABLE_KEY);
// Handle any errors from Checkout
var handleResult = function(result) {
if (result.error) {
var displayError = document.getElementById("error-message");
displayError.textContent = result.error.message;
}
};
document.querySelectorAll("button").forEach(function(button) {
button.addEventListener("click", function(e) {
var skuId = e.target.dataset.skuId;
var planId = e.target.dataset.planId;
var items = skuId
? [{ sku: skuId, quantity: 1 }]
: [{ plan: planId, quantity: 1 }];
// Make the call to Stripe.js to redirect to the checkout page
// with the sku or plan ID.
stripe
.redirectToCheckout({
items: items,
successUrl:
DOMAIN + "success.html?session_id={CHECKOUT_SESSION_ID}",
cancelUrl:
DOMAIN + "canceled.html?session_id={CHECKOUT_SESSION_ID}"
})
.then(handleResult);
});
});
</script>
</body>
</html>