forked from stripe/elements-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example5.js
88 lines (81 loc) · 2.06 KB
/
example5.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
80
81
82
83
84
85
86
87
88
(function() {
"use strict";
var elements = stripe.elements({
// 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", {
iconStyle: "solid",
style: {
base: {
iconColor: "#fff",
color: "#fff",
fontWeight: 400,
fontFamily: "Helvetica Neue, Helvetica, Arial, sans-serif",
fontSize: "16px",
fontSmoothing: "antialiased",
"::placeholder": {
color: "#BFAEF6"
},
":-webkit-autofill": {
color: "#fce883"
}
},
invalid: {
iconColor: "#FFC7EE",
color: "#FFC7EE"
}
}
});
card.mount("#example5-card");
/**
* Payment Request Element
*/
var paymentRequest = stripe.paymentRequest({
country: "US",
currency: "usd",
total: {
amount: 2500,
label: "Total"
},
requestShipping: true,
shippingOptions: [
{
id: "free-shipping",
label: "Free shipping",
detail: "Arrives in 5 to 7 days",
amount: 0
}
]
});
paymentRequest.on("token", function(result) {
var example = document.querySelector(".example5");
example.querySelector(".token").innerText = result.token.id;
example.classList.add("submitted");
result.complete("success");
});
var paymentRequestElement = elements.create("paymentRequestButton", {
paymentRequest: paymentRequest,
style: {
paymentRequestButton: {
theme: "light"
}
}
});
paymentRequest.canMakePayment().then(function(result) {
if (result) {
document.querySelector(".example5 .card-only").style.display = "none";
document.querySelector(
".example5 .payment-request-available"
).style.display =
"block";
paymentRequestElement.mount("#example5-paymentRequest");
}
});
registerElements([card], "example5");
})();