-
Notifications
You must be signed in to change notification settings - Fork 1
/
py.html
252 lines (218 loc) · 5.48 KB
/
py.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css" />
<title>Page Title</title>
<script src="https://js.stripe.com/v3/"></script>
</head>
<style>
.modal-overlay {
background: rgba(0, 0, 0, 0.7);
width: 100%;
height: 100%;
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.modal-wrapper {
width: 400px;
height: 400px;
background: ghostwhite;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.open-modal-btn-wrapper {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.close-modal-btn,
.open-modal-btn {
padding: 8px;
background: slateblue;
font-family: Verdana, Geneva, Tahoma, sans-serif;
font-size: 15px;
color: ghostwhite;
font-weight: 5px;
margin-left: auto;
margin-top: 10px;
margin-right: 10px;
cursor: pointer;
}
.close-btn-wrapper {
display: flex;
}
.modal-content {
margin: 20px auto;
max-width: 210px;
width: 100%;
}
.hide {
display: none;
}
h1 {
text-align: center;
}
/***********************/
.container {
max-width: 400px;
margin: 50px auto;
background-color: #fff;
border-radius: 8px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
padding: 20px;
}
h1 {
text-align: center;
color: #333;
}
label {
display: block;
margin-bottom: 5px;
font-size: 14px;
color: #555;
}
.input-field {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
margin-bottom: 15px;
font-size: 14px;
}
.select-field {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
margin-bottom: 15px;
font-size: 14px;
appearance: none;
background: url('arrow-down.svg') no-repeat right center;
}
.payment-methods {
display: flex;
justify-content: space-between;
margin-bottom: 15px;
}
.payment-method {
flex: 1;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
text-align: center;
cursor: pointer;
transition: background-color 0.3s ease;
}
.payment-method:hover {
background-color: #f5f5f5;
}
#card-element {
border: 1px solid #ccc;
border-radius: 4px;
padding: 10px;
margin-bottom: 15px;
}
#submit-button {
background-color: #28a745;
color: #fff;
border: none;
padding: 10px 15px;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
width: 100%;
}
#submit-button:hover {
background-color: #218838;
}
</style>
<body>
<div class="open-modal-btn-wrapper">
<button class="open-modal-btn">
Open Modal
</button>
</div>
<div class="modal-overlay hide">
<div class="modal-wrapper">
<div class="close-btn-wrapper">
<button class="close-modal-btn">
Close
</button>
</div>
<div class="modal-content">
<form id="payment-form">
<label for="payment-method">Select Payment Method:</label>
<select id="payment-method">
<option value="credit-card">Credit Card</option>
<option value="cash-on-delivery">Cash on Delivery</option>
</select>
<div id="credit-card">
<label for="card-holder-name">Cardholder Name:</label>
<input id="card-holder-name" type="text">
<div id="card-element"></div>
</div>
<button id="submit-button">Submit Payment</button>
</form>
</div>
</div>
</div>
<script>
document.addEventListener("DOMContentLoaded", function () {
const stripe = Stripe('YOUR_PUBLISHABLE_KEY');
const elements = stripe.elements();
const paymentMethodSelector = document.getElementById('payment-method');
const creditCardSection = document.getElementById('credit-card');
const cardHolderName = document.getElementById('card-holder-name');
const cardElement = elements.create('card');
cardElement.mount('#card-element');
paymentMethodSelector.addEventListener('change', function () {
if (paymentMethodSelector.value === 'credit-card') {
creditCardSection.style.display = 'block';
} else {
creditCardSection.style.display = 'none';
}
});
const form = document.getElementById('payment-form');
form.addEventListener('submit', async function (event) {
event.preventDefault();
if (paymentMethodSelector.value === 'credit-card') {
const {token, error} = await stripe.createToken(cardElement, {
name: cardHolderName.value
});
if (error) {
console.error(error);
} else {
// Send the token to your server for processing
// Implement your server-side logic here
}
} else {
// Handle cash on delivery
// Implement your cash on delivery logic here
}
});
});
///////////////////////////
const openBtn = document.querySelector(".open-modal-btn");
const modal = document.querySelector(".modal-overlay");
const closeBtn = document.querySelector(".close-modal-btn");
function openModal() {
modal.classList.remove("hide");
}
function closeModal(e, clickedOutside) {
if (clickedOutside) {
if (e.target.classList.contains("modal-overlay"))
modal.classList.add("hide");
} else modal.classList.add("hide");
}
openBtn.addEventListener("click", openModal);
modal.addEventListener("click", (e) => closeModal(e, true));
closeBtn.addEventListener("click", closeModal);
</script>
</body>
</html>