-
Notifications
You must be signed in to change notification settings - Fork 24
/
signUp.html
156 lines (130 loc) · 4.39 KB
/
signUp.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
{% set title = 'Sign Up' %}
{% set admin = false %}
{% extends 'base.html' %}
{% block content %}
<div class="sign-up">
<label class="sign-up-product">
{{ product.name }}
</label>
<h2>Sign up for {{ plan.name }} — {{ plan.amount }} /
{% if (plan.interval_count > 1) %}
{{ plan.interval_count }} {{ plan.interval }}s
{% else %}
{{ plan.interval }}
{% endif %}
</h2>
{% if success %}
<div>
<p>Your payment was successful. Congrats, you've successfully signed up! </p>
</div>
{% elif error %}
<div>
<p>Your payment was unsuccessful. Please try again.</p>
</div>
{% else %}
<div class="sign-up-container">
<form action="/processPayment" method="POST" id="payment-form">
<input type="hidden" value="{{ product.name }}" name="productName"/>
<input type="hidden" value="{{ plan.id }}" name="planId"/>
<input type="hidden" value="{{ plan.amount }}" name="planAmount"/>
<input type="hidden" value="{{ plan.name }}" name="planName"/>
<input type="hidden" value="{{ plan.interval }}" name="planInterval"/>
<input type="hidden" value="{{ plan.interval_count }}" name="planIntervalCount"/>
<label>
Email Address
</label>
<input placeholder="Your Email Address" name="customerEmail"/>
<div class="form-row">
<label for="card-element">
Credit or debit card
</label>
<div id="card-element">
<!-- A Stripe Elements instance will be mounted here -->
</div>
<!-- Any error messages will be mounted here -->
<div id="card-errors" role="alert"></div>
</div>
<input class="btn" type="submit" value="Pay {{ plan.amount }}" />
</form>
</div>
{% endif %}
</div>
<script>
if (document.getElementById('card-element')) {
/* Replace 'pk_test_************************' with your publishable key */
var stripe = Stripe('pk_test_************************');
var elements = stripe.elements();
/* Custom styling can be passed to options when creating an Element */
var style = {
base: {
fontSize: '16px', '::placeholder': { color: "#aab7c4"},
fontFamily: '"Open Sans", "Helvetica", sans-serif',
fontSmoothing: 'antialiased',
},
invalid: {
color: '#fa755a',
iconColor: '#fa755a'
}
};
/* Create a Stripe Elements instance
and mount to the div with the id 'card-element' */
var card = elements.create('card', {style: style});
card.mount('#card-element');
/* Handle validation errors */
card.addEventListener('change', event => {
var displayError = document.getElementById('card-errors');
if (event.error) {
displayError.textContent = event.error.message;
} else {
displayError.textContent = '';
}
});
/* Create a token when the form is submitted */
var form = document.getElementById('payment-form');
form.addEventListener('submit', function(event) {
event.preventDefault();
stripe.createToken(card).then(function(result) {
if (result.error) {
var errorElement = document.getElementById('card-errors');
errorElement.textContent = result.error.message;
} else {
stripeTokenHandler(result.token);
}
})
});
}
function stripeTokenHandler(token) {
var form = document.getElementById('payment-form');
var hiddenInput = document.createElement('input');
hiddenInput.setAttribute('type', 'hidden');
hiddenInput.setAttribute('name', 'stripeToken');
hiddenInput.setAttribute('value', token.id);
form.appendChild(hiddenInput);
form.submit();
}
</script>
<style>
/* This CSS is taken from the Stripe Elements Quickstart Guide (https://stripe.com/docs/stripe-js/elements/quickstart).
* It is used to style the container, not the actual inputs inside */
.StripeElement {
box-sizing: border-box;
height: 40px;
padding: 10px 12px;
border: 1px solid transparent;
border-radius: 4px;
background-color: white;
box-shadow: 0 1px 3px 0 #e6ebf1;
-webkit-transition: box-shadow 150ms ease;
transition: box-shadow 150ms ease;
}
.StripeElement--focus {
box-shadow: 0 1px 3px 0 #cfd7df;
}
.StripeElement--invalid {
border-color: #fa755a;
}
.StripeElement--webkit-autofill {
background-color: #fefde5 !important;
}
</style>
{% endblock %}