forked from blockchain/receive-payments-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
callback.php
47 lines (35 loc) · 1.28 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
<?php
include 'include.php';
mysql_connect($mysql_host, $mysql_username, $mysql_password) or die(__LINE__ . ' Invalid connect: ' . mysql_error());
mysql_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;
//Commented out to test, uncomment when live
if ($_GET['test'] == true) {
echo 'Ignoring Test Callback';
return;
}
if ($_GET['address'] != $my_bitcoin_address) {
echo 'Incorrect Receiving Address';
return;
}
if ($_GET['secret'] != $secret) {
echo 'Invalid Secret';
return;
}
if ($_GET['confirmations'] >= 4) {
//Add the invoice to the database
$result = mysql_query("replace INTO invoice_payments (invoice_id, transaction_hash, value) values($invoice_id, '$transaction_hash', $value_in_btc)");
//Delete from pending
mysql_query("delete from pending_invoice_payments where invoice_id = $invoice_id limit 1");
if($result) {
echo "*ok*";
}
} else {
//Waiting for confirmations
//create a pending payment entry
mysql_query("replace INTO pending_invoice_payments (invoice_id, transaction_hash, value) values($invoice_id, '$transaction_hash', $value_in_btc)");
echo "Waiting for confirmations";
}
?>