i am trying to create automated receive bitcoin payments via Blockchain API.
I have my API key, xpub, everything. Using php..
here is the part of my code:
part of the code for generating wallet address:
$scrt = my_super_secret_code_60_chars_long;
$my_callback_url = "http://mysite.com/lib/payment.php?secret={$scrt}";
$my_xpub = "my_xpub_key";
$my_api_key = "my_secret_api_key";
$root_url = "https://api.blockchain.info/v2/receive";
$parameters = "xpub=" .$my_xpub. "&callback=" .urlencode($my_callback_url). "&key=" .$my_api_key;
$qry= "SELECT ID,RECEIVE_ADDR FROM MY_TABLE WHERE WALLET = '{$_GET['wallet']}' ";
$result = mysqli_query($conn,$qry);
$row = mysqli_fetch_row($result);
$reci = $row[1];
$uid = $row[0];
if ($reci=='none') {
//if the user does not have generated receive address, triggering this
$response = file_get_contents($root_url . '?' . $parameters);
$object = json_decode($response);
echo 'Send Payment To : ' . $object->address;
$qry= "UPDATE MY_TABLE SET RECEIVE_ADDR='". $object->address ."' WHERE WALLET = '{$_GET['wallet']}' ";
mysqli_query($conn,$qry);
}
this code works OK, but i have problem with callback php (payment.php).
it's not triggering when the payment is received, however manually, i can simulate the received payment with calling php with correct parameters
the part of the payment.php
<?php
$scrtt = $_GET['secret']; //password is passed back to the callback URL
$transaction_hash = $_GET['transaction_hash'];
$value_in_satoshi = $_GET['value'];
$value_in_btc = $value_in_satoshi / 100000000;
$gt='CALLBACK CALLED - TXID:'.$transaction_hash.' VALUE '.$value_in_satoshi.' SCRT:'.$scrtt.' CONFIRMS:'.$_GET['confirmations'];
$qry= "INSERT INTO DEBUG (TE) VALUES ('{$gt}')";
mysqli_query($conn,$qry);
//code above is for debugging - but not triggered however payment is received
if ($scrtt== my_super_secret_code) {
if ($_GET['confirmations'] >= 2) {
$confirms=$_GET['confirmations'];
$qry= "SELECT ID FROM MY_TABLE WHERE RECEIVE_ADDR = '{$_GET['address']}'";
$result = mysqli_query($conn,$qry);
$row = mysqli_fetch_row($result);
$uid = $row[0];
$qry= "SELECT TXHASH FROM PAYMENTS WHERE TXHASH = '{$_GET['transaction_hash']}' ";
$result = mysqli_query($conn,$qry);
$row = mysqli_fetch_row($result);
$tx = $row[0];
if ($tx <> $transaction_hash) {
$qry="INSERT INTO PAYMENTS (TXHASH,USER_ID,SATS,CONFIRMS) VALUES ('{$transaction_hash}',{$uid},{$value_in_satoshi},{$confirms})";
mysqli_query($conn,$qry);
//new tx - insert
}
//Insert into confirmed payments
}
}
echo '*ok*';
?>
my problem is, the callback is never called - can anyone check my code and tell me where i have problem?
thanks