-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsuccess.php
More file actions
130 lines (109 loc) · 4.35 KB
/
success.php
File metadata and controls
130 lines (109 loc) · 4.35 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
<?php
include_once("./app/_dbConnection.php");
// SMTP MAILER
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require './services/phpmailer/src/Exception.php';
require './services/phpmailer/src/PHPMailer.php';
require './services/phpmailer/src/SMTP.php';
if (!isset($_SESSION)) {
session_start();
}
// Get user email from session if available
$email = isset($_SESSION['Email']) ? $_SESSION['Email'] : null;
function smtp_mailer($to, $subject, $msg)
{
$mail = new PHPMailer();
try {
//Server settings
$mail->isSMTP(); //Send using SMTP
$mail->Host = 'smtp.gmail.com'; //Set the SMTP server to send through
$mail->SMTPAuth = true; //Enable SMTP authentication
$mail->Username = getenv('SMTP_USERNAME'); //SMTP username
$mail->Password = getenv('SMTP_PASSWORD'); //SMTP password
$mail->SMTPSecure = 'tls'; //Enable TLS encryption
$mail->Port = 587; //TCP port to connect to
$mail->SMTPDebug = 0; // Set to 2 for verbose SMTP debug output in error_log
$mail->Debugoutput = 'error_log';
//Recipients
$mail->setFrom(getenv('SMTP_USERNAME'));
$mail->addAddress($to); //Add a recipient
//Content
$mail->isHTML(true); //Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $msg;
if ($mail->send())
null;
else {
error_log('[smtp_mailer] Send failed: ' . $mail->ErrorInfo);
die(header("HTTP/1.0 500 Internal Server Error Email"));
}
} catch (Exception $e) {
error_log('[smtp_mailer] Exception: ' . $e->getMessage());
die(header("HTTP/1.0 500 Internal Server Error Email"));
}
}
$val_id = urlencode($_POST['val_id']);
$store_id = urlencode(getenv('SSLCOMMERZ_STORE_ID'));
$store_passwd = urlencode(getenv('SSLCOMMERZ_STORE_PASSWD'));
$requested_url = ("https://sandbox.sslcommerz.com/validator/api/validationserverAPI.php?val_id=" . $val_id . "&store_id=" . $store_id . "&store_passwd=" . $store_passwd . "&v=1&format=json");
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $requested_url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, false); # IF YOU RUN FROM LOCAL PC
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false); # IF YOU RUN FROM LOCAL PC
$result = curl_exec($handle);
$code = curl_getinfo($handle, CURLINFO_HTTP_CODE);
if ($code == 200 && !(curl_errno($handle))) {
$result = json_decode($result);
# TRANSACTION INFO
$tran_date = $result->tran_date;
$tran_id = $result->tran_id;
$val_id = $result->val_id;
$amount = $result->amount;
$card_no = $result->card_no;
# ISSUER INFO
$card_type = $result->card_type;
# API AUTHENTICATION
$user_id = $result->value_a;
$package_id = $result->value_b;
$transactionInstance = new Transactions();
$transactionInstance->createNewTransaction($tran_id, $user_id, $package_id, $amount, $tran_date, $card_no, $val_id, $card_type);
$packagesInstance = new Packages();
$res = $packagesInstance->getPackage($package_id);
$package = mysqli_fetch_assoc($res);
$count = $package['package_booked'];
$count = $count + 1;
$packagesInstance->updatePackagePurchase($package_id, $count);
$mailHtml = "<div>
<h3>You Purchase of Taka <b>" . $amount . "</b> via <b>" . $card_type . "</b> has been successfully confirmed. <br>
<a href='http://localhost/triptrip/auth/user_dashboard.php'>Visit your dashboard</a> to check your purchase confirmation.
</div>";
// Undo Comment for sending mail
if ($email && getenv('SMTP_USERNAME') && getenv('SMTP_PASSWORD')) {
smtp_mailer($email, 'Account Verification', $mailHtml);
} else {
if (!$email)
error_log('[success.php] No session Email set; skipping confirmation email.');
}
} else {
echo "Failed to connect with SSLCOMMERZ";
}
?>
<html>
<title>Successful Purchase</title>
<body>
<h1>Your purchase is completed.</h1>
<p>Redirecting to dashboard in <span class="counter"></span></p>
<script>
let countDown = 5;
setInterval(() => {
countDown--;
document.querySelector(".counter").innerHTML = countDown;
}, 1000)
setTimeout(() => {
location.href = "./auth/user_dashboard.php";
}, 5000);
</script>
</body>
</html>