-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpayment.html
More file actions
387 lines (352 loc) · 10.5 KB
/
payment.html
File metadata and controls
387 lines (352 loc) · 10.5 KB
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
<!DOCTYPE html>
<%@page import="com.conn.DbConnect"%>
<%@page import="java.sql.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Payment</title>
</head>
<body>
<link
href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css"
rel="stylesheet" id="bootstrap-css">
<script
src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<style>
body {
background: url("https://cityofrockwood.com/wp-content/uploads/2019/01/online-bill-pay.jpg");
background-size: 100%;
background-repeat: no-repeat;
width: 100%;
height: 50vh;
}
/* CSS for Credit Card Payment form */
.credit-card-box .panel-title {
display: inline;
font-weight: bold;
}
.credit-card-box .form-control.error {
border-color: red;
outline: 0;
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px
rgba(255, 0, 0, 0.6);
}
.credit-card-box label.error {
font-weight: bold;
color: red;
padding: 2px 8px; //
margin-top: 2px;
}
.credit-card-box .payment-errors {
font-weight: bold;
color: red;
padding: 2px 8px; //
margin-top: 2px;
}
.credit-card-box label {
display: block;
}
/* The old "center div vertically" hack */
.credit-card-box .display-table {
display: table;
}
.credit-card-box .display-tr {
display: table-row;
}
.credit-card-box .display-td {
display: table-cell;
vertical-align: middle;
width: 50%;
}
/* Just looks nicer */
.credit-card-box .panel-heading img {
min-width: 180px;
}
</style>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script>
var $form = $('#payment-form');
$form.find('.subscribe').on('click', payWithStripe);
/* If you're using Stripe for payments */
function payWithStripe(e) {
e.preventDefault();
/* Abort if invalid form data */
if (!validator.form()) {
return;
}
/* Visual feedback */
$form.find('.subscribe').html(
'Validating <i class="fa fa-spinner fa-pulse"></i>').prop(
'disabled', true);
var PublishableKey = 'pk_test_6pRNASCoBOKtIshFeQd4XMUh'; // Replace with your API publishable key
Stripe.setPublishableKey(PublishableKey);
/* Create token */
var expiry = $form.find('[name=cardExpiry]').payment(
'cardExpiryVal');
var ccData = {
number : $form.find('[name=cardNumber]').val().replace(/\s/g,
''),
cvc : $form.find('[name=cardCVC]').val(),
exp_month : expiry.month,
exp_year : expiry.year
};
Stripe.card
.createToken(
ccData,
function stripeResponseHandler(status, response) {
if (response.error) {
/* Visual feedback */
$form.find('.subscribe').html('Try again')
.prop('disabled', false);
/* Show Stripe errors on the form */
$form.find('.payment-errors').text(
response.error.message);
$form.find('.payment-errors').closest(
'.row').show();
} else {
/* Visual feedback */
$form
.find('.subscribe')
.html(
'Processing <i class="fa fa-spinner fa-pulse"></i>');
/* Hide Stripe errors on the form */
$form.find('.payment-errors').closest(
'.row').hide();
$form.find('.payment-errors').text("");
// response contains id and card, which contains additional card details
console.log(response.id);
console.log(response.card);
var token = response.id;
// AJAX - you would send 'token' to your server here.
$
.post('/account/stripe_card_token',
{
token : token
})
// Assign handlers immediately after making the request,
.done(
function(data, textStatus,
jqXHR) {
$form
.find(
'.subscribe')
.html(
'Payment successful <i class="fa fa-check"></i>');
})
.fail(
function(jqXHR, textStatus,
errorThrown) {
$form
.find(
'.subscribe')
.html(
'There was a problem')
.removeClass(
'success')
.addClass(
'error');
/* Show Stripe errors on the form */
$form
.find(
'.payment-errors')
.text(
'Try refreshing the page and trying again.');
$form
.find(
'.payment-errors')
.closest('.row')
.show();
});
}
});
}
/* Fancy restrictive input formatting via jQuery.payment library*/
$('input[name=cardNumber]').payment('formatCardNumber');
$('input[name=cardCVC]').payment('formatCardCVC');
$('input[name=cardExpiry').payment('formatCardExpiry');
/* Form validation using Stripe client-side validation helpers */
jQuery.validator.addMethod("cardNumber", function(value, element) {
return this.optional(element)
|| Stripe.card.validateCardNumber(value);
}, "Please specify a valid credit card number.");
jQuery.validator.addMethod("cardExpiry", function(value, element) {
/* Parsing month/year uses jQuery.payment library */
value = $.payment.cardExpiryVal(value);
return this.optional(element)
|| Stripe.card.validateExpiry(value.month, value.year);
}, "Invalid expiration date.");
jQuery.validator.addMethod("cardCVC", function(value, element) {
return this.optional(element) || Stripe.card.validateCVC(value);
}, "Invalid CVC.");
validator = $form.validate({
rules : {
cardNumber : {
required : true,
cardNumber : true
},
cardExpiry : {
required : true,
cardExpiry : true
},
cardCVC : {
required : true,
cardCVC : true
}
},
highlight : function(element) {
$(element).closest('.form-control').removeClass('success')
.addClass('error');
},
unhighlight : function(element) {
$(element).closest('.form-control').removeClass('error')
.addClass('success');
},
errorPlacement : function(error, element) {
$(element).closest('.form-group').append(error);
}
});
paymentFormReady = function() {
if ($form.find('[name=cardNumber]').hasClass("success")
&& $form.find('[name=cardExpiry]').hasClass("success")
&& $form.find('[name=cardCVC]').val().length > 1) {
return true;
} else {
return false;
}
}
$form.find('.subscribe').prop('disabled', true);
var readyInterval = setInterval(function() {
if (paymentFormReady()) {
$form.find('.subscribe').prop('disabled', false);
clearInterval(readyInterval);
}
}, 250);
</script>
<link rel="stylesheet"
href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<script type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.13.1/jquery.validate.min.js"></script>
<script type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/jquery.payment/1.2.3/jquery.payment.min.js"></script>
<!-- If you're using Stripe for payments -->
<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
<br>
<br>
<br>
<br>
<br>
<br>
<%
String msg = request.getParameter("msg");
if ("valid".equals(msg)) {
%>
<script>
alert("Bill Paid SuccessFully");
window.location.assign("viewmybill.jsp");
</script>
<%
}
%>
<%
if ("invalid".equals(msg)) {
%>
<script>
alert("Something Went Wrong");
</script>
<%
}
%>
<%
try {
int total = 0;
String billid = request.getParameter("id");
Connection con = DbConnect.getConn();
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from bill where billid=" + billid + "");
if (rs.next()) {
total = rs.getInt("finalamount");
%>
<div class="container">
<div class="row">
<!-- You can make it whatever width you want. I'm making it full width
on <= small devices and 4/12 page width on >= medium devices -->
<div class="col-xs-4 col-md-4"></div>
<div class="col-xs-4 col-md-4">
<!-- CREDIT CARD FORM STARTS HERE -->
<div class="panel panel-default credit-card-box">
<div class="panel-heading display-table">
<div class="row display-tr">
<h3 class="panel-title display-td">Payment Details</h3>
<div class="display-td">
<img class="img-responsive pull-right" src="images/bg1.jpg">
</div>
</div>
</div>
<div class="panel-body">
<form action="paymentAction.jsp" method="POST">
<div class="row">
<div class="col-xs-12">
<div class="form-group">
<label for="cardNumber">CARD NUMBER</label>
<div class="input-group">
<input type="tel" class="form-control" name="cardnumber"
placeholder="Valid Card Number" autocomplete="cc-number"
autofocus /> <span class="input-group-addon"><i
class="fa fa-credit-card"></i></span>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-7 col-md-7">
<div class="form-group">
<label for="cardExpiry"><span class="hidden-xs">EXPIRATION</span><span
class="visible-xs-inline">EXP</span> DATE</label> <input type="tel"
class="form-control" name="cardex" placeholder="MM / YY"
autocomplete="cc-exp" />
</div>
</div>
<div class="col-xs-5 col-md-5 pull-right">
<div class="form-group">
<label for="cardCVC">CVC CODE</label> <input type="tel"
class="form-control" name="cvc" placeholder="CVC"
autocomplete="cc-csc" />
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div class="form-group">
<label for="couponCode">Amount In $</label> <input type="text"
class="form-control" value="<%out.println(total);%>"
name="amount" readonly />
</div>
</div>
</div>
<input type="hidden" id="billid" name="billid"
value="<%=rs.getInt("billid")%>">
<div class="col-xs-12">
<input type="submit" class="btn btn-success btn-lg btn-block"
name="payment" value="payment">
</div>
</div>
<div class="row" style="display: none;">
<div class="col-xs-12">
<p class="payment-errors"></p>
</div>
</div>
</form>
</div>
</div>
<!-- CREDIT CARD FORM ENDS HERE -->
</div>
</div>
</div>
<%
}
} catch (Exception e) {
System.out.println(e);
}
%>
</body>
</html>