I want to accept payments with the Blockchain Receive Payments API (https://blockchain.info/api/api_receive) but I can't seem to figure out how to work it. I cannot test it too much because there is a minimum amount of BTC that can be sent to the account for it to work and I just ran out from testing because there is no destination for the address but that's another story- I just need to know that it should work. This is what I have so far:
callback.php
$secret = "testSecret";
if (isset($_GET['secret'])) {
if ($_GET['secret'] != $secret) {
die("Invalid secret");
} else {
define("HOST", "localhost");
define("USER", "root");
define("PASSWORD", "DBPASS");
define("DATABASE", "xeon.io");
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
$query = "INSERT INTO invoices (item_id, price_in_btc, bought_by, deliver_to, time) VALUES ('2', '001', '1', '1', '0')";
if ($mysqli->query($query)) {
echo "*ok*";
} else {
die("ERROR!!!!1");
}
}
} else {
die("Blank secret");
}
receive.php
$secret = 'testSecret';
$my_address = '1339LGRGE44QMLYa4hTuyAsbKVjVAGXwHW';
$my_callback_url = 'http://example.com/pay?secret='.$secret;
$root_url = 'https://blockchain.info/api/receive';
$parameters = 'method=create&address=' . $my_address .'&callback='. urlencode($my_callback_url);
$response = file_get_contents($root_url . '?' . $parameters);
$object = json_decode($response);
echo 'Send Payment To : ' . $object->input_address;
Generating new accounts works just fine but that's not the problem. The test callback on their site works but when I actually test it, nothing gets written to the database and the BTC isn't returned to the original account nor sent to the destination account. I basically just want to know if I am doing anything wrong with the above code. Thanks for the help :)