-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfirm.php
160 lines (146 loc) · 4.58 KB
/
confirm.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
<?php
require_once('config.php');
//session
session_start();
//count items in array
$cartItems = count($_SESSION['tedi']);
$cart = $_SESSION['tedi'];
if($cartItems < 1)
{
header("Location: cart.php");
}
mysqli_set_charset($conn,"utf8");
$usdOwed = 0;
for($i=0; $i<$cartItems; $i++)
{
$queryLoopCart = "SELECT * FROM products WHERE id = '$cart[$i]'";
$doLoopCart = mysqli_query($conn, $queryLoopCart) or die(mysqli_error($conn));
$rowLoopCart = mysqli_fetch_assoc($doLoopCart);
$loopPrice = $rowLoopCart['price'];
$usdOwed += $loopPrice;
}
$btcOwed = $usdOwed / $_SESSION['exr'];
if(isset($_POST['confirm']))
{
$uniq = uniqid();
$paid = 0;
$time = time();
$complete = 0;
$orderID = md5($uniq);
$orderData = implode(" ",$_SESSION['tedi']);
$orderCost = round($btcOwed, 4);
$_SESSION['orderCost'] = $orderCost;
$email = $_SESSION['email'];
$name = $_SESSION['name'];
$address = $_SESSION['address'];
$address2 = $_SESSION['address2'];
$city = $_SESSION['city'];
$state = $_SESSION['state'];
$zip = $_SESSION['zip'];
$country = $_SESSION['country'];
//call blockchain info receive payments API
$callback_url = $rootURL."/callback.php?invoice=".$orderID."&secret=".$secret;
$receive_url = "https://api.blockchain.info/v2/receive?key=".$api_key."&xpub=".$xpub."&callback=".urlencode($callback_url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $receive_url);
$ccc = curl_exec($ch);
$json = json_decode($ccc, true);
$payTo = $json['address'];
$_SESSION['payTo'] = $payTo;
//insert into DB
$queryOrder = "INSERT INTO orders (orderid, time, name, address, address2, city, state, zip, country, email, cost, payto, items, paid, complete) VALUES ('$orderID', '$time', '$name', '$address', '$address2', '$city', '$state', '$zip', '$country', '$email', '$orderCost', '$payTo', '$orderData', '$paid', '$complete')";
$doOrder = mysqli_query($conn, $queryOrder) or die(mysqli_error($conn));
if(!$doOrder)
{
die('Error: '.mysqli_error($conn));
}
else
{
$host = $_SERVER['SERVER_NAME'];
$emailTitle = "New Purchase";
$emailTitle_Customer = "Order Confirmation";
$bodyEmail = <<<EOD
<h1>New Purchase</h1>
Order: $orderID <br>
Email: $email <br>
Name: $name <br>
Address: $address <br>
$address2 <br>
City: $city <br>
State: $state <br>
Zip: $zip <br>
Payment Address: $payTo <br>
Payment Amount: $orderCost <br>
EOD;
$headers = "From: noreply@".$host."\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail("$yourEmail", "$emailTitle", "$bodyEmail", "$headers");
$custEmail = <<<EOD
<h3>Please send payment to finalize your purchase</h3>
Payment Address: $payTo <br>
Payment Amount: $orderCost <br>
Order: $orderID <br>
Email: $email <br>
Name: $name <br>
Address: $address <br>
$address2 <br>
City: $city <br>
State: $state <br>
Zip: $zip <br>
EOD;
$customerCopy = mail($email, $emailTitle_Customer, $custEmail, $headers);
header('Location: pay.php');
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Confirm</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1><?php echo $storeName; ?></h1>
<div id="viewCart">
<span id="viewTitle">Review & Confirm</span><br>
Ship To:
<div class="confirmShip">
<?php
echo htmlspecialchars($_SESSION['name'])."<br>";
echo htmlspecialchars($_SESSION['address'])."<br>";
echo htmlspecialchars($_SESSION['address2'])."<br>";
echo htmlspecialchars($_SESSION['city']);
echo ", ".htmlspecialchars($_SESSION['state']);
echo " ".htmlspecialchars($_SESSION['zip'])."<br>";
echo htmlspecialchars($_SESSION['email'])."<br>";
?>
<a href="checkout.php">EDIT</a>
</div><br><br>
Order:
<div class="confirmShip">
<?php
$usdOwed = 0;
for($i=0; $i<$cartItems; $i++)
{
$queryLoopCart = "SELECT * FROM products WHERE id = '$cart[$i]'";
$doLoopCart = mysqli_query($conn, $queryLoopCart);
$rowLoopCart = mysqli_fetch_assoc($doLoopCart);
$loopName = $rowLoopCart['name'];
$loopPrice = $rowLoopCart['price'];
$usdOwed += $loopPrice;
$btcOwed = $usdOwed / $_SESSION['exr'];
echo $loopName." $".$loopPrice."<br>";
}
echo "$".$usdOwed."<br>";
echo "฿".round($btcOwed, 4)."<br>";
?>
<a href="cart.php">EDIT</a>
</div><br>
<div id="checkCont"><form method="post"><input type="submit" class="button" value="CONFIRM & PAY" name="confirm"></form></div>
<br>
</div>
<br>
</body>
</html>