1// Create a Stripe client.
2var stripe = Stripe('pk_test_51I0lG1CctxAFe6g03VnMrgE5cfG7a5q66dZau9Is2C7PMt3K2ZOEWw84Kb4K06Kdyl75qoe5zRXBqPwjBENQ3RZX004Z5By1rn');
3
4// Create an instance of Elements.
5var elements = stripe.elements();
6
7// Custom styling can be passed to options when creating an Element.
8// (Note that this demo uses a wider set of styles than the guide below.)
9var style = {
10 base: {
11 color: '#32325d',
12 fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
13 fontSmoothing: 'antialiased',
14 fontSize: '16px',
15 '::placeholder': {
16 color: '#aab7c4'
17 }
18 },
19 invalid: {
20 color: '#fa755a',
21 iconColor: '#fa755a'
22 }
23};
24
25// Create an instance of the card Element.
26var card = elements.create('card', {style: style});
27
28// Add an instance of the card Element into the `card-element` <div>.
29card.mount('#card-element');
30// Handle real-time validation errors from the card Element.
31card.on('change', function(event) {
32 var displayError = document.getElementById('card-errors');
33 if (event.error) {
34 displayError.textContent = event.error.message;
35 } else {
36 displayError.textContent = '';
37 }
38});
39
40// Handle form submission.
41var form = document.getElementById('payment-form');
42form.addEventListener('submit', function(event) {
43 event.preventDefault();
44
45 stripe.createToken(card).then(function(result) {
46 if (result.error) {
47 // Inform the user if there was an error.
48 var errorElement = document.getElementById('card-errors');
49 errorElement.textContent = result.error.message;
50 } else {
51 // Send the token to your server.
52 stripeTokenHandler(result.token);
53 }
54 });
55});
56
57// Submit the form with the token ID.
58function stripeTokenHandler(token) {
59 // Insert the token ID into the form so it gets submitted to the server
60 var form = document.getElementById('payment-form');
61 var hiddenInput = document.createElement('input');
62 hiddenInput.setAttribute('type', 'hidden');
63 hiddenInput.setAttribute('name', 'stripeToken');
64 hiddenInput.setAttribute('value', token.id);
65 form.appendChild(hiddenInput);
66
67 // Submit the form
68 form.submit();
69}// Create a Stripe client.
70var stripe = Stripe('pk_test_51I0lG1CctxAFe6g03VnMrgE5cfG7a5q66dZau9Is2C7PMt3K2ZOEWw84Kb4K06Kdyl75qoe5zRXBqPwjBENQ3RZX004Z5By1rn');
71
72// Create an instance of Elements.
73var elements = stripe.elements();
74
75// Custom styling can be passed to options when creating an Element.
76// (Note that this demo uses a wider set of styles than the guide below.)
77var style = {
78 base: {
79 color: '#32325d',
80 fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
81 fontSmoothing: 'antialiased',
82 fontSize: '16px',
83 '::placeholder': {
84 color: '#aab7c4'
85 }
86 },
87 invalid: {
88 color: '#fa755a',
89 iconColor: '#fa755a'
90 }
91};
92
93// Create an instance of the card Element.
94var card = elements.create('card', {style: style});
95
96// Add an instance of the card Element into the `card-element` <div>.
97card.mount('#card-element');
98
1/**
2 * The CSS shown here will not be introduced in the Quickstart guide, but shows
3 * how you can use CSS to style your Element's container.
4 */
5.StripeElement {
6 box-sizing: border-box;
7
8 height: 40px;
9
10 padding: 10px 12px;
11
12 border: 1px solid transparent;
13 border-radius: 4px;
14 background-color: white;
15
16 box-shadow: 0 1px 3px 0 #e6ebf1;
17 -webkit-transition: box-shadow 150ms ease;
18 transition: box-shadow 150ms ease;
19}
20
21.StripeElement--focus {
22 box-shadow: 0 1px 3px 0 #cfd7df;
23}
24
25.StripeElement--invalid {
26 border-color: #fa755a;
27}
28
29.StripeElement--webkit-autofill {
30 background-color: #fefde5 !important;}/**
31 * The CSS shown here will not be introduced in the Quickstart guide, but shows
32 * how you can use CSS to style your Element's container.
33 */
34.StripeElement {
35 box-sizing: border-box;
36
37 height: 40px;
38
39 padding: 10px 12px;
40
41 border: 1px solid transparent;
42 border-radius: 4px;
43 background-color: white;
44
45 box-shadow: 0 1px 3px 0 #e6ebf1;
46 -webkit-transition: box-shadow 150ms ease;
47 transition: box-shadow 150ms ease;
48}
49
50.StripeElement--focus {
51 box-shadow: 0 1px 3px 0 #cfd7df;
52}
53
54.StripeElement--invalid {
55 border-color: #fa755a;
56}
57
58.StripeElement--webkit-autofill {
59 background-color: #fefde5 !important;