forked from stripe/elements-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example4.js
79 lines (71 loc) · 1.83 KB
/
example4.js
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
(function() {
"use strict";
var elements = stripe.elements({
fonts: [
{
cssSrc: "https://rsms.me/inter/inter-ui.css"
}
],
// Stripe's examples are localized to specific languages, but if
// you wish to have Elements automatically detect your user's locale,
// use `locale: 'auto'` instead.
locale: window.__exampleLocale
});
/**
* Card Element
*/
var card = elements.create("card", {
style: {
base: {
color: "#32325D",
fontWeight: 500,
fontFamily: "Inter UI, Open Sans, Segoe UI, sans-serif",
fontSize: "16px",
fontSmoothing: "antialiased",
"::placeholder": {
color: "#CFD7DF"
}
},
invalid: {
color: "#E25950"
}
}
});
card.mount("#example4-card");
/**
* Payment Request Element
*/
var paymentRequest = stripe.paymentRequest({
country: "US",
currency: "usd",
total: {
amount: 2000,
label: "Total"
}
});
paymentRequest.on("token", function(result) {
var example = document.querySelector(".example4");
example.querySelector(".token").innerText = result.token.id;
example.classList.add("submitted");
result.complete("success");
});
var paymentRequestElement = elements.create("paymentRequestButton", {
paymentRequest: paymentRequest,
style: {
paymentRequestButton: {
type: "donate"
}
}
});
paymentRequest.canMakePayment().then(function(result) {
if (result) {
document.querySelector(".example4 .card-only").style.display = "none";
document.querySelector(
".example4 .payment-request-available"
).style.display =
"block";
paymentRequestElement.mount("#example4-paymentRequest");
}
});
registerElements([card, paymentRequestElement], "example4");
})();