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:


$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 {
} else {
    die("Blank secret");


$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 :)


1 Answer 1


Not an expert, but have I have an ecommerce site that relies on blockchain's API and the error log I have looked at seems to indicate that cloud flare is preventing the return of the info that I'm looking to populate my stores db (just checking balances, etc).

Are there error logs that you've looked at and do they confirm that cloud flare is not the issue? Seems like it plagues everybody using their API for basic functions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.