-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
96 lines (88 loc) · 3.31 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
85
86
87
88
89
90
91
92
93
94
95
96
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Stripe Payment Page Recipe</title>
<meta name="description" content="A demo of Stripe Payment Intents" />
<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 class="sr-container">
<section class="container">
<h1>One-time Donation</h1>
<button data-sku-id="sku_GU4JYXyvvRb2sX">Donate $5.00 once</button>
<button data-sku-id="sku_GU4KO8nfdg8G2Z">Donate $15.00 once</button>
<button data-sku-id="sku_GU4LB0wBViiYsm">Donate $50.00 once</button>
</section>
<section class="container">
<h1>Recurring Donation</h1>
<button data-plan-id="plan_GU4MXg0k0Uv1S6">
Donate $20.00 per month
</button>
</section>
</div>
<div id="error-message"></div>
</div>
</div>
<div class="banner">
<span>
This is a
<a href="https://github.com/stripe-samples"> Stripe Sample </a> on how
to use Stripe Checkout on GitHub Pages.
<a
href="https://github.com/stripe-samples/github-pages-stripe-checkout"
>
View code on GitHub.
</a>
</span>
</div>
<script>
// Replace with your own publishable key: https://dashboard.stripe.com/test/apikeys
var PUBLISHABLE_KEY = "pk_test_Tr8olTkdFnnJVywwhNPHwnHK00HkHV4tnP";
// Replace with the domain you want your users to be redirected back to after payment
var DOMAIN = location.href.replace(/[^/]*$/, "");
if (PUBLISHABLE_KEY === "pk_test_Tr8olTkdFnnJVywwhNPHwnHK00HkHV4tnP") {
console.log(
"Replace the hardcoded publishable key with your own publishable key: https://dashboard.stripe.com/test/apikeys"
);
}
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>