This repository has been archived by the owner on Mar 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 246
/
callback.php
63 lines (48 loc) · 1.68 KB
/
callback.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
<?php
include 'include.php';
$db = new mysqli($mysql_host, $mysql_username, $mysql_password) or die(__LINE__ . ' Invalid connect: ' . mysqli_error());
$db->select_db($mysql_database) or die( "Unable to select database. Run setup first.");
$invoice_id = $_GET['invoice_id'];
$transaction_hash = $_GET['transaction_hash'];
$value_in_btc = $_GET['value'] / 100000000;
$stmt = $db->prepare("select address from invoices where invoice_id = ?");
$stmt->bind_param("i",$invoice_id);
$success = $stmt->execute();
if (!$success) {
die(__LINE__ . ' Invalid query: ' . mysql_error());
}
$result = $stmt->get_result();
while($row = $result->fetch_array()) {
$my_address = $row['address'];
}
$result->close();
$stmt->close();
if ($_GET['address'] != $my_address) {
echo 'Incorrect Receiving Address';
return;
}
if ($_GET['secret'] != $secret) {
echo 'Invalid Secret';
return;
}
if ($_GET['confirmations'] >= 4) {
//Add the invoice to the database
$stmt = $db->prepare("replace INTO invoice_payments (invoice_id, transaction_hash, value) values(?, ?, ?)");
$stmt->bind_param("isd",$invoice_id, $transaction_hash, $value_in_btc);
$stmt->execute();
//Delete from pending
$stmt = $db->prepare(" delete from pending_invoice_payments where invoice_id = ? limit 1");
$stmt->bind_param("i",$invoice_id);
$result = $stmt->execute();
if($result) {
echo "*ok*";
}
} else {
//Waiting for confirmations
//create a pending payment entry
$stmt = $db->prepare("replace INTO pending_invoice_payments (invoice_id, transaction_hash, value) values(?, ?, ?)");
$stmt->bind_param("isd",$invoice_id, $transaction_hash, $value_in_btc);
$stmt->execute();
echo "Waiting for confirmations";
}
?>