-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpayments-proccess-loggedin.php
executable file
·140 lines (107 loc) · 2.75 KB
/
payments-proccess-loggedin.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
<?php
// [INCLUDE] //
include('./common/session.php');
include('./connection.php');
// [REQUIRE] //
require_once('./api/stripe/index.php');
// [REDIRECT] //
if ($_SESSION['loggedin'] != true) { header('Location: ./login.php'); }
// [STRIPE] //
$StripeWrapper = new StripeWrapper();
// [INIT] //
$stripe_cus_id = $_SESSION['stripe_cus_id'];
$email = $_SESSION['email'];
$authenticated = false;
$paid = false;
$vin = '';
$error = '';
// Processing form data when form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// [GET-VALUES] //
if (empty($_POST['vin'])) { $error = 'no vin passed'; }
else {
$vin = trim($_POST['vin']);
// [SANITIZE] //
$vin = filter_var($vin, FILTER_SANITIZE_STRING);
// [STRIPE] //
$chargeObj = $StripeWrapper->createOneDollarCharge(
$stripe_cus_id,
$vin
);
$stripe_pi_id = $chargeObj['id'];
if ($chargeObj['status'] = 'succeeded') {
$paid = true;
// [DB][PAYMENTS] Create //
$stmt = $conn->prepare(
"INSERT INTO payments (
email,
stripe_pi_id
)
VALUES (?,?)"
);
$stmt->bind_param(
'ss',
$email,
$stripe_pi_id
);
$stmt->execute();
$stmt->close();
}
else { $error = 'Payment failed'; }
}
}
else {
// [GET-VALUES] //
if (empty($_GET['vin'])) { $error = 'no vin passed'; }
else {
$vin = trim($_GET['vin']);
// [SANITIZE] //
$vin = filter_var($vin, FILTER_SANITIZE_STRING);
}
}
?>
<!-- [HTML] ------------------------------------------------------->
<!-- [HEADER] -->
<?php include('header.php'); ?>
<!-- [SPACER] -->
<section class="w3l-about-breadcrumb position-relative text-center">
<div class="breadcrumb-bg breadcrumb-bg-about py-sm-5 py-4"></div>
</section>
<div class="container my-5">
<!-- [ERROR] -->
<?php if ($error): ?>
<div class="alert alert-danger mb-3 shadow">
<h4 class="text-danger"><?php echo $error; ?></h4>
</div>
<?php else: ?>
<?php if ($paid): ?>
<!-- [SUCCESS] -->
<h3 class="text-center text-dark">
Thank You! You can now generate a report for the provided vin
</h3>
<hr>
<a
href="./generate-report.php?stripe_pi_id=<?php echo $stripe_pi_id; ?>"
class="text-center"
>
<button class="btn btn-primary w-100">
Go to Generate Report Page
</button>
</a>
<?php else: ?>
<div class="card card-body mb-3 shadow">
<form
action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>"
method="POST"
>
<input type="hidden" name="vin" value="<?php echo $vin ?>">
<button class="btn btn-primary w-100">Use Default Card</button>
</form>
</div>
<?php endif; ?>
<?php endif; ?>
</div>
<?php include('footer.php'); ?>
<?php include('./common/bottom_script.php'); ?>
</body>
</html>