-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcreditcard2.php
526 lines (459 loc) · 19.9 KB
/
creditcard2.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
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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
<?php
session_start();
if (isset($_SESSION['u_id'])) {
$uid = $_SESSION['u_id'];
} else {
header("Location: index.php");
}
include_once('connect.php');
include_once('email.php');
include_once('braintree-init.php');
//require __DIR__ . '/vendor/autoload.php';
$amt = ltrim($_POST['total_price'], '$');
$zip = $_POST['address_zip'];
$theplace = $_POST['theplace'];
$checkin = $_POST['checkin'];
$checkout = $_POST['checkout'];
$customer = "";
$charge = "";
$cusid = "";
$fname = $_SESSION['fname'];
$lname = $_SESSION['lname'];
$email = $_SESSION['email'];
$placeid = $_POST['placeid'];
// Charge the user's card:
// if(isset($_SESSION['u_id'])
// {
//$paypal_url='https://www.paypal.com/cgi-bin/webscr'; // Test Paypal API URL
//$paypal_id='[email protected]'; // Business email ID
//$book = $_REQUEST['bookid'];
//$q17 = mysqli_query($connect,'Select * from users,booking where uid="'.$_SESSION['u_id'].'" and uid=userid and bookid="'.$book.'"');
//if(mysqli_num_rows($q17)>0)
//{
//$r17=mysqli_fetch_array($q17);
// $q18 = mysqli_query($connect,"select * from booking where bookid=".$book);
// $r18 = mysqli_fetch_array($q18);
?>
<!doctype html>
<html>
<head>
<title>Credit card form</title>
<?php include 'lib/top.php';?>
<style>
.panel {
width: 80%;
margin: 2em auto;
}
.braintree-hosted-fields-focused {
border: 1px solid #0275d8;
box-shadow: inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6);
}
.braintree-hosted-fields-focused.focused-invalid {
border: 1px solid #ebcccc;
box-shadow: inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(100,100,0,.6);
}
@media (max-width: 670px) {
.form-group {
width: 100%;
}
.btn {
white-space: normal;
}
}
</style>
</head>
<body>
<div class="container-fluid"><!--container-fluid start-->
<div class="row">
<!--==============menu header=========================-->
<div class="menu-had2">
<?php include 'lib/header.php'; ?>
</div><!--menu-had close-->
<!--==============menu header close=========================-->
<?php
if (isset($_POST['payment-method-nonce'])) {
$nonceFromTheClient = $_POST['payment-method-nonce'];
//$amt = $_POST['total_price'];
$zip = $_POST['address_zip'];
$placeid = $_POST['placeid'];
$customer = "";
$charge = "";
$cusid = "";
if (isset($_POST['newcustomer'])) {
$result = Braintree_Customer::create([
'paymentMethodNonce' => $nonceFromTheClient
]);
if ($result->success) {
$cusid = $result->customer->id;
$result2 = Braintree_Transaction::sale(
[
'customerId' => $cusid,
'amount' => $amt
]
);
if ($result2->success) {
$inscus = mysqli_query($connect, 'insert into `stripeaccts` (`user_id`, `stripe_cusid`, `stripe_type`) values ("'.$uid.'", "'.$cusid.'", "cu")');
if ($inscus) {
$instrans = mysqli_query($connect, 'insert into `transactions` (`user_id`, `stripe_cusid`, `amount`) values ("'.$uid.'", "'.$cusid.'", "'.$amt.'")');
email_message($fname, $lname, $email, $sguser, $sgpass, $sgrequest, $amt, $theplace, $checkin, $checkout, $placeid,$connect);
}
} else {
$error = "true";
}
} else {
foreach($result->errors->deepAll() AS $error) {
echo($error->code . ": " . $error->message . "\n");
}
}
} else {
$result = Braintree_Transaction::sale([
'amount' => $amt,
'paymentMethodNonce' => $nonceFromTheClient,
'options' => [
'submitForSettlement' => True
]
]);
if ($result->success || !is_null($result->transaction)) {
$instrans = mysqli_query($connect, 'insert into `transactions` (`user_id`, `amount`, `comment`) values ("'.$uid.'", "'.$amt.'", "One time transaction.")');
$transaction = $result->transaction;
//$sql5 = mysqli_query($connect,'Select * from users,place where uid=user_id and place_id=5158');
//$row5 = mysqli_fetch_array($sql5);
//$email2 = $row5['email'];
email_message($fname, $lname, $email, $sguser, $sgpass, $sgrequest, $amt, $theplace, $checkin, $checkout,$placeid,$connect);
//header("Location: transaction.php?id=" . $transaction->id);
} else {
$errorString = "";
$error = "true";
foreach($result->errors->deepAll() as $error) {
$errorString .= 'Error: ' . $error->code . ": " . $error->message . "\n";
}
//echo $errorString;
//header("Location: index.php");
}
}
} else if (isset($_POST['customer'])) {
$cusid = $_POST['stripeid'];
//$amt = $_POST['total_price'];
$result = Braintree_Transaction::sale(
[
'customerId' => $cusid,
'amount' => $amt
]
);
$instrans = mysqli_query($connect, 'insert into `transactions` (`user_id`, `amount`, `cusid`) values ("'.$uid.'", "'.$amt.'", "'.$cusid.'")');
email_message($fname, $lname, $email, $sguser, $sgpass, $sgrequest, $amt, $theplace, $checkin, $checkout, $placeid, $connect);
} else {
$strq = mysqli_query($connect, 'select * from stripeaccts where user_id = "'.$uid.'" and stripe_type = "cu"');
$strres = mysqli_fetch_array($strq);
}
function email_message($fname, $lname, $email, $sguser, $sgpass, $sgrequest, $total_price, $theplace, $checkin, $checkout, $placeid, $connect) {
//error_log("email: " . $email2);
$subject = 'Your 2finda transaction';
$body = "Dear " . $fname . " " . $lname . ",<br><br>
You have successfully booked a space on 2finda.com<br>
See the details of your credit card transaction:<br>
Amount: $" . $total_price . "<br>
Location: " . $theplace . "<br>
Event Times: " . $checkin . " to " . $checkout . "<br><br>Your 2finda team";
$json_string = array(
'to' => array($email, '[email protected]'), 'category' => 'test_category'
);
/*$json_string = array(
'to' => array($email), 'category' => 'test_category'
);*/
$params = array(
'api_user' => $sguser,
'api_key' => $sgpass,
'to' => $email,
'subject' => $subject,
'html' => $body,
'from' => '[email protected]',
);
$session = curl_init($sgrequest);
curl_setopt($session, CURLOPT_POST, true);
curl_setopt($session, CURLOPT_POSTFIELDS, $params);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($session, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($session);
curl_close($session);
//mysqli_close($connect);
//error_log('Select * from users,place where uid=userid and place_id="'.$placeid.'"');
//$sql5 = mysqli_query($connect,'Select * from users,place where uid=userid and place_id="5158"');
//error_log("query result: " . $sql5);
//$row5 = mysqli_fetch_array($sql5);
//error_log($row5);
//error_log($row5['lname']);
$sql5 = mysqli_query($connect,'Select * from users,place where uid=user_id and place_id="'.$placeid.'"');
$row5 = mysqli_fetch_array($sql5);
$email2 = $row5['email'];
$subject = 'Your 2finda transaction';
//$email2 = $row5['email'];
$body = "Dear " . $row5['fname'] . " " . $row5['lname'] . ",<br><br>"
. $fname . " " . $lname . " has booked your space, " . $row5['space_name'] . ", from " . $checkin . " to " . $checkout
. "<br><br>Your 2finda team";
/*$json_string = array(
'to' => array($email, '[email protected]'), 'category' => 'test_category'
);*/
$json_string = array(
'to' => array($email2), 'category' => 'test_category'
);
$params = array(
'api_user' => $sguser,
'api_key' => $sgpass,
'to' => $email2,
'subject' => $subject,
'html' => $body,
'from' => '[email protected]',
);
$session = curl_init($sgrequest);
curl_setopt($session, CURLOPT_POST, true);
curl_setopt($session, CURLOPT_POSTFIELDS, $params);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($session, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($session);
curl_close($session);
//mysqli_close($connect);
header('Location: success.php');
}
?>
<div class="banner-txt">
<h1> Booking</h1>
</div>
<div class="container">
<div class="row">
<div class="col-lg-8 col-sm-8 col-md-8 col-xs-12 tellus-data" style="text-align: center; padding-bottom: 20px;">
<?php if ($result->success || $result2->success) {?>
<!--<div style="font-weight: bold; padding: 10px 10px;">-->
<div><h2>Your transaction was successful!</h2></div>
<div>Amount: $<?php echo $_POST['total_price']?></div>
<div>Location: <?php echo $_POST['theplace']?></div>
<div>Event Times: <?php echo $_POST['checkin'] . " to " . $_POST['checkout'] ?></div>
<div>An email has been sent to you with your transaction details.</div>
</div>
<?php } else if (isset($error)) { ?>
<div><h2>Transaction failed.</h2></div>
<div>Please contact 2finda support for help with this error.</div>
</div>
<?php } else if (!isset($strres['stripe_cusid'])) {
$clientToken = Braintree_ClientToken::generate(); ?>
<form id="checkout-form" method="post">
<div class="row">
<div class="form-group col-xs-8">
<label class="control-label">Card Number</label>
<!-- Hosted Fields div container -->
<div class="form-control" id="card-number"></div>
<span class="helper-text"></span>
</div>
<div class="form-group col-xs-4">
<div class="row">
<label class="control-label col-xs-12">Expiration Date</label>
<div class="col-xs-6">
<!-- Hosted Fields div container -->
<div class="form-control" id="expiration-month"></div>
</div>
<div class="col-xs-6">
<!-- Hosted Fields div container -->
<div class="form-control" id="expiration-year"></div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="form-group col-xs-6">
<label class="control-label">Security Code</label>
<!-- Hosted Fields div container -->
<div class="form-control" id="cvv"></div>
</div>
<div class="form-group col-xs-6">
<label class="control-label">Zipcode</label>
<!-- Hosted Fields div container -->
<div class="form-control" id="postal-code"></div>
</div>
</div>
<input type="hidden" name="total_price" value="<?php echo ltrim($_POST['total_price'], '$') ?>">
<input type="hidden" name="checkin" value="<?php echo $_POST['checkin'] ?>">
<input type="hidden" name="checkout" value="<?php echo $_POST['checkout'] ?>">
<input type="hidden" name="theplace" value="<?php echo $_POST['theplace'] ?>">
<input type="hidden" name="placeid" value="<?php echo $_POST['placeid'] ?>">
<!--<button value="submit" id="submit" class="btn btn-success btn-lg center-block">Pay with <span id="card-type">Card</span></button>-->
<input type="hidden" name="payment-method-nonce">
<div class="col-lg-4 col-md-4 col-lg-offset-3 checkbox-inline" style="">
<label>
<input type="checkbox" name="newcustomer" value="yes" id="cbox">Save credit card information
</label>
</div>
<input type="submit" value="Pay Now" disabled>
<div style="height: 10px;"></div>
</form>
<div class="clearfix"></div>
</div>
<!--</div>-->
<!-- Load the Client component. -->
<script src="https://js.braintreegateway.com/web/3.7.0/js/client.min.js"></script>
<!-- Load the Hosted Fields component. -->
<script src="https://js.braintreegateway.com/web/3.7.0/js/hosted-fields.min.js"></script>
<script>
// We generated a client token for you so you can test out this code
// immediately. In a production-ready integration, you will need to
// generate a client token on your server (see section below).
var form = document.querySelector('#checkout-form');
var submit = document.querySelector('input[type="submit"]');
var authorize = '<?php echo $clientToken ?>';
braintree.client.create({
// Replace this with your own authorization.
authorization: authorize
}, function (clientErr, clientInstance) {
if (clientErr) {
// Handle error in client creation
return;
}
braintree.hostedFields.create({
client: clientInstance,
styles: {
'input': {
'font-size': '12pt'
},
'font-family': 'helvetica, tahoma, calibri, sans-serif',
'input.invalid': {
'color': 'red'
},
'input.valid': {
'color': 'black'
}
},
fields: {
number: {
selector: '#card-number',
placeholder: ''
},
cvv: {
selector: '#cvv',
placeholder: ''
},
expirationMonth: {
selector: '#expiration-month',
placeholder: 'MM',
select: true
},
expirationYear: {
selector: '#expiration-year',
placeholder: 'YY',
select: true
},
postalCode: {
selector: '#postal-code',
placeholder: ''
}
}
}, function (hostedFieldsErr, hostedFieldsInstance) {
if (hostedFieldsErr) {
// Handle error in Hosted Fields creation
return;
}
submit.removeAttribute('disabled');
form.addEventListener('submit', function (event) {
event.preventDefault();
hostedFieldsInstance.tokenize(function (tokenizeErr, payload) {
if (tokenizeErr) {
// Handle error in Hosted Fields tokenization
return;
}
// Put `payload.nonce` into the `payment-method-nonce` input, and then
// submit the form. Alternatively, you could send the nonce to your server
// with AJAX.
console.log(payload.nonce);
document.querySelector('input[name="payment-method-nonce"]').value = payload.nonce;
form.submit();
});
}, false);
});
});
</script>
<?php } else { ?>
<!--<div style="font-weight: bold; padding: 10px 10px;">-->
<h2>Do you wish to complete your transaction?</h2>
<div>Amount: $<?php echo $_POST['total_price'] ?></div>
<div>Location: <?php echo $_POST['theplace']?></div>
<div>Event Times: <?php echo $_POST['checkin'] . " to " . $_POST['checkout'] ?></div>
<form method="post">
<input type="hidden" name="stripeid" value="<?php echo $strres['stripe_cusid'] ?>">
<input type="hidden" name="customer" value="customer">
<input type="hidden" name="total_price" value="<?php echo $_POST['total_price'] ?>">
<input type="hidden" name="checkin" value="<?php echo $_POST['checkin'] ?>">
<input type="hidden" name="checkout" value="<?php echo $_POST['checkout'] ?>">
<input type="hidden" name="theplace" value="<?php echo $_POST['theplace'] ?>">
<input type="hidden" name="placeid" value="<?php echo $_POST['placeid'] ?>">
<button type="submit">Yes</button>
</form>
</div>
<?php } ?>
<!--==========WHY LIST YOUR PLACE?============-->
<div class="col-lg-4 col-sm-4 col-md-4 col-xs-12">
<div class="tellus-data">
<div class="had-frm">Why list your place?</div>
<div class="safe-lst">
<div class="col-lg-2 col-sm-2 col-md-2 col-xs-2">
<img class="img-responsive" src="img/save.png">
</div>
<div class="col-lg-10 col-sm-10 col-md-10 col-xs10">
<span class="had-2nd">It's safe</span>
<p>We provide a trusted environment.</p>
</div>
<div class="clearfix"></div>
</div>
<div class="safe-lst">
<div class="col-lg-2 col-sm-2 col-md-2 col-xs-2">
<img class="img-responsive" src="img/easy.png">
</div>
<div class="col-lg-10 col-sm-10 col-md-10 col-xs10">
<span class="had-2nd">It's easy</span>
<p>We'll do all the hard work of finding guests, while you just enjoy earning money with a spare space.</p>
</div>
<div class="clearfix"></div>
</div>
<div class="safe-lst">
<div class="col-lg-2 col-sm-2 col-md-2 col-xs-2">
<img class="img-responsive" src="img/free.png">
</div>
<div class="col-lg-10 col-sm-10 col-md-10 col-xs10">
<span class="had-2nd">It's free</span>
<p>We don't charge you to upload your place, and you get instant access to thousands of guests.</p>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
<!--==========WHY LIST YOUR PLACE CLOSE============-->
</div><!--row close-->
</div><!--container close-->
<div id="myModal3" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="showload" style="display:none;">
<img class="showimg" src="img/loading.gif" style="margin:0 auto;display:block;">
</div>
<div class="" style="display:block;">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title"></h4>
</div>
<div class="modal-body">
"Are you ready to submit payment?"
</div>
<div class="modal-footer" style="text-align: center;">
<!-- <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> -->
<span class="showmsg" style="display:none;"></span>
</div>
</div>
</div>
</div>
</div>
<!--======footer======-->
<?php include 'lib/footer.php';
?>
<!--======footer close======-->
</body>
</html>