-
Notifications
You must be signed in to change notification settings - Fork 0
/
6-1.credit_card_payment.php
executable file
·346 lines (292 loc) · 11.2 KB
/
6-1.credit_card_payment.php
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
<?php
$pageName = 'credit_card_payment';
$title = '信用卡結帳頁面';
require './parts/connect-db.php';
$rows = [];
$sids = [];
if (!empty($_SESSION['cart'])) {
$sids = array_keys($_SESSION['cart']);
$sql = sprintf("SELECT * FROM `items` WHERE sid IN (%s)", implode(',', $sids));
$stmt = $pdo->query($sql);
while ($r = $stmt->fetch()) {
$r['quantity'] = $_SESSION['cart'][$r['sid']];
$rows[$r['sid']] = $r;
}
}
/*
echo json_encode([
'rows' => $rows,
'sids' => $sids,
]);
*/
?>
<?php include __DIR__ . '/parts/html-head.php' ?>
<link rel="stylesheet" href="./css/credit_card_payment.css">
<?php include __DIR__ . '/parts/html-navbar.php' ?>
<!-- token store PC -->
<div class="container_pc">
<div class="token_store_title">
<div class="main_title">Token Store</div>
<div class="sub_title">支付頁面</div>
</div>
</div>
<!-- token store mobile -->
<div class="container_mobile">
<div class="token_store_title">
<div class="main_title" style="font-size:24px">Token Store</div>
<div class="sub_title" style="font-size:14px">支付頁面</div>
</div>
</div>
<!-- duo button pc -->
<!-- <div class="container_pc">
<div class="duo_button_wrap">
<label class="container_duo_button">
信用卡
<input type="radio" checked="checked" name="radio">
<span class="checkmark"></span>
</label>
<label class="container_duo_button">
第三方支付
<input type="radio" name="radio">
<span class="checkmark"></span>
</label>
</div>
</div> -->
<!-- duo button mobile -->
<div class="duo_button_wrap">
<label class="container_duo_button">
信用卡
<input type="radio" checked="checked" name="radio">
<span class="checkmark"></span>
</label>
<label class="container_duo_button">
第三方支付
<input type="radio" name="radio">
<span class="checkmark"></span>
</label>
</div>
<!-- credit card pc -->
<div class="container_pc">
<div class="credit_card" >
<div class="card__front card__part">
<img class="card__front-square card__square" src="imgs/Shoppingcard/chip.png">
<img class="card__front-logo card__logo" src="imgs/Shoppingcard/L-2.ico">
<p class="card_numer">**** **** **** 6258</p>
<div class="card__space-75">
<span class="card__label">Card holder</span>
<p class="card__info">Luxiem Hope</p>
</div>
<div class="card__space-25">
<span class="card__label">Expires</span>
<p class="card__info">05/30</p>
</div>
</div>
<div class="card__back card__part">
<div class="card__black-line"></div>
<div class="card__back-content">
<div class="card__secret">
<p class="card__secret--last">608</p>
</div>
<img class="card__back-logo card__logo" src="imgs/Shoppingcard/L-2.ico">
</div>
</div>
</div>
</div>
<!-- credit card mobile -->
<div class="container_mobile">
<div class="credit_card">
<div class="card__front card__part">
<img class="card__front-square card__square" src="imgs/Shoppingcard/chip.png">
<img class="card__front-logo card__logo" src="imgs/Shoppingcard/L-2.ico">
<p class="card_numer">**** **** **** 6258</p>
<div class="card__space-75">
<span class="card__label">Card holder</span>
<p class="card__info">Luxiem Hope</p>
</div>
<div class="card__space-25">
<span class="card__label">Expires</span>
<p class="card__info">05/30</p>
</div>
</div>
<div class="card__back card__part">
<div class="card__black-line"></div>
<div class="card__back-content">
<div class="card__secret">
<p class="card__secret--last">608</p>
</div>
<!-- <img class="card__back-square card__square" src="img/chip.png"> -->
<img class="card__back-logo card__logo" src="imgs/Shoppingcard/L-2.ico">
</div>
</div>
</div>
</div>
<!-- credit card info pc -->
<div class="container_pc">
<div class="creditcard_info">
<form action="" onsubmit="checkForm(); return false;" novalidate>
<label for="card-number">請輸入信用卡卡號</label>
<input type="text" id="card-number" name="card-number" placeholder="Card Number">
<div class="duo_info">
<div class="firstname">
<label for="fname">持卡人姓名</label>
<input type="text" id="first-name" name="first-name" placeholder="First Name">
</div>
<div class="lastname duo_info_right">
<label for="lname" style="opacity: 0;">持卡人姓名</label>
<input type="text" id="last-name" name="last-name" placeholder="Last Name">
</div>
</div>
<div class="duo_info">
<div>
<label for="valid-date">有效月/年</label>
<input type="text" id="valid-date" name="valid-date" placeholder="MM/YY">
</div>
<div class="duo_info_right" >
<label for="cvc-number">驗證碼</label>
<input type="text" id="cvc-number" name="cvc-number" placeholder="CVC ">
</div>
</div>
</form>
</div>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
<!-- credit card info mobile -->
<div class="container_mobile">
<div class="creditcard_info">
<form action="" onsubmit="checkForm(); return false;" novalidate>
<label for="card-number">請輸入信用卡卡號</label>
<input type="text" id="card-number" name="card-number" placeholder="Card Number">
<div class="duo_info">
<div class="firstname">
<label for="fname">持卡人姓名</label>
<input type="text" id="first-name" name="first-name" placeholder="First Name">
</div>
<div class="lastname duo_info_right">
<label for="lname" style="opacity: 0;">持卡人姓名</label>
<input type="text" id="last-name" name="last-name" placeholder="Last Name">
</div>
</div>
<div class="duo_info">
<div>
<label for="valid-date">有效月/年</label>
<input type="text" id="valid-date" name="valid-date" placeholder="MM/YY">
</div>
<div class="duo_info_right" >
<label for="cvc-number">驗證碼</label>
<input type="text" id="cvc-number" name="cvc-number" placeholder="CVC ">
</div>
</div>
</form>
</div>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
<!-- checkout button pc-->
<div class="container_pc">
<div class="checkout">
<button type="submit" class=""><a style="color:white" href="6-2.credit_card_payment_fin.php">確認結帳</a></button>
<button class=""><a style="color:white" href="coinshop.php">取消</a></button>
</div>
</div>
<!-- checkout button pc-->
<div class="container_mobile">
<div class="checkout">
<button type="submit" class=""><a style="color: white" href="6-2.credit_card_payment_fin.php">確認結帳</a></button>
<button class=""><a style="color:white" href="coinshop.php">取消</a></button>
</div>
</div>
<?php include __DIR__ . '/parts/html-script.php' ?>
<script>
const $card-number = $('#card-number');
const $first-name = $('#first-name');
const $last-name = $('#last-name');
const $valid-date = $('#valid-date');
const $cvc-number = $('#cvc-number');
const msgFields = [$card-number, $first-name, $last-name, $valid-date, $cvc-number];
const $modal = $('#exampleModal');
const modal = new bootstrap.Modal($modal[0]);
function checkForm() {
// 清除之前的檢查訊息
for (let f of msgFields) {
f.css('border', '#CCCCCC 1px solid');
f.next().html('');
}
// TODO: 檢查欄位資料.
let isPass = true; // 有沒有通過檢查
const first-name = $first-name.val().trim();
const last-name = $last-name.val().trim();
function validateCardNumber(cardN) {
return /^(?:3[47][0-9]{13})$/.test(cardN);
}
if (first-name.length < 2) {
$first-name.next().html('請填寫正確的名');
$first-name.css('border', 'red 1px solid');
isPass = false;
}
if (last-name.length < 2) {
$last-name.next().html('請填寫正確的姓');
$last-name.css('border', 'red 1px solid');
isPass = false;
}
if ($card-number.val() && !validateCardNumber($card-number.val())) {
$card-number.next().html('請填寫正確的信用卡號碼');
$card-number.css('border', 'red 1px solid');
isPass = false;
}
if (cvc-number.length < 3) {
$cvc-number.next().html('請填寫正確的cvc號碼');
$cvc-number.css('border', 'red 1px solid');
isPass = false;
}
// AJAX
if (isPass) {
$.post('6-3.credit_card_info_add_api.php', $(document.form1).serialize(), function(data) {
console.log(data);
if (data.success) {
// alert('資料新增成功');
// location.href = 'ab-list.php';
$modal.find('#exampleModalLabel').html('信用卡交易成功');
$modal.find('.modal-body').html('謝謝');
modal.show();
} else {
//alert(data.error || '資料新增失敗');
$modal.find('#exampleModalLabel').html('信用卡交易失敗');
$modal.find('.modal-body').html('...');
modal.show();
}
}, 'json');
}
}
</script>
<?php include __DIR__ . '/parts/html-last.php' ?>