Author

Topic: [SOLVED] can some1 help me with blockchain API callback? (Read 38755 times)

hero member
Activity: 980
Merit: 504
PredX - AI-Powered Prediction Market
check with your web host to possible IP block or the log files to see why page isnt being served

previously i had very strict anti bot scripts for my old faucet and .htaccess stayed without changes, that was the reason
legendary
Activity: 1302
Merit: 1008
Core dev leaves me neg feedback #abuse #political
check with your web host to possible IP block or the log files to see why page isnt being served
hero member
Activity: 980
Merit: 504
PredX - AI-Powered Prediction Market
OK I investigated a little and here is my result (however it's still not working)

i found url how to check callback log directly on the blockchain:
https://api.blockchain.info/v2/receive/callback_log?callback=http-urlencoded_my_website/callback.php?parameters&key=my-api-key

the log shown me something like that:

Code:
callback":"http://mysite.com/callback.php?param=myparam","called_at":"2017-03-10T13:05:39Z","response_code":403,"raw_response":"\n\n403 Forbidden\n\n

Forbidden

\n

You don't have permission to access /callback.php\non this server.
\n

\n

Additionally, a 403 Forbidden\nerror was encountered while trying to use an ErrorDocument to handle the request.

\n\n"}]


can some1 help me with that?
i am an owner of this domain and i can access this page via all of my browsers
hero member
Activity: 980
Merit: 504
PredX - AI-Powered Prediction Market
first you said callback wasnt happening.

if it is happening, but not doing what you want, try printing out mysql error. maybe its not connecting properly to your DB.
Just keep printing out log variables and see at what point it breaks

to simplify my asnwer..

if i am calling callback url manually via browser with ? & &  parameters, it works , so callback url is correct, script is doing everything correctly..

but:  when i receive payment to my generated address , blockchain does not triggers the callback so the callback url is not called

Right, so what I am saying is that if the url is not called then you can't blame the script that is (not) being called.
You need to look into why blockchain isn't doing the callback.



exactly.. i agree with you...
80% of code mentioned in the main post is copy/paste from blockchain API documentation.

the reason i published here my non-secret part of php code is, that maybe somebody can find the reason why blockchain not calling the callback url.

and sorry for my english Smiley
legendary
Activity: 1302
Merit: 1008
Core dev leaves me neg feedback #abuse #political
first you said callback wasnt happening.

if it is happening, but not doing what you want, try printing out mysql error. maybe its not connecting properly to your DB.
Just keep printing out log variables and see at what point it breaks

to simplify my asnwer..

if i am calling callback url manually via browser with ? & &  parameters, it works , so callback url is correct, script is doing everything correctly..

but:  when i receive payment to my generated address , blockchain does not triggers the callback so the callback url is not called

Right, so what I am saying is that if the url is not called then you can't blame the script that is (not) being called.
You need to look into why blockchain isn't doing the callback.

hero member
Activity: 980
Merit: 504
PredX - AI-Powered Prediction Market
first you said callback wasnt happening.

if it is happening, but not doing what you want, try printing out mysql error. maybe its not connecting properly to your DB.
Just keep printing out log variables and see at what point it breaks

to simplify my asnwer..

if i am calling callback url manually via browser with ? & &  parameters, it works , so callback url is correct, script is doing everything correctly..

but:  when i receive payment to my generated address , blockchain does not triggers the callback so the callback url is not called
legendary
Activity: 1302
Merit: 1008
Core dev leaves me neg feedback #abuse #political
first you said callback wasnt happening.

if it is happening, but not doing what you want, try printing out mysql error. maybe its not connecting properly to your DB.
Just keep printing out log variables and see at what point it breaks
hero member
Activity: 980
Merit: 504
PredX - AI-Powered Prediction Market
but did you try simplifying script to get write to a text file?

Did it work or not

as i mentioned - my first callback wrote only date + txhash to the text file.. so yes, i debugged as you suggested...
also callback url is a live php file

manually worked, but when i received satoshis to my blockchain wallet generated with the first script (with callback url included)  - this event was never fired..
legendary
Activity: 1302
Merit: 1008
Core dev leaves me neg feedback #abuse #political
but did you try simplifying script to get write to a text file?

Did it work or not
hero member
Activity: 980
Merit: 504
PredX - AI-Powered Prediction Market
maybe it is using POST not GET?

again i recommend just confirm the call works with simple text log.

then you can try
parsing all parameters POST or GET to see what is passed, maybe some variables are misnamed etc



i already tested that... and manually: works  , blockchain -> no success...
blockchain API using $_GET , that's why i used GET

i think, my callback URL is not in good format or something meesed up in this part of code
legendary
Activity: 1302
Merit: 1008
Core dev leaves me neg feedback #abuse #political
maybe it is using POST not GET?

again i recommend just confirm the call works with simple text log.

then you can try
parsing all parameters POST or GET to see what is passed, maybe some variables are misnamed etc

hero member
Activity: 980
Merit: 504
PredX - AI-Powered Prediction Market
if the callback isn't called then not a prob with your code.

Simplify your callback script to do a simple debug log in a text file
and see if it gets called or not.

if it doesnt get called, then problem is on blockchain side



I already made a debug directly in the callback php file.. these lines:

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

are adding basic info about transaction to my mysqli database..
but there are 0 lines => callback is not fired...

only when i tried to call callback file manually with correct parameters.. so basic problem is (probably) in the first script, but after hours of googling and studying blockchain API , i found no reason what is the problem
legendary
Activity: 1302
Merit: 1008
Core dev leaves me neg feedback #abuse #political
if the callback isn't called then not a prob with your code.

Simplify your callback script to do a simple debug log in a text file
and see if it gets called or not.

if it doesnt get called, then problem is on blockchain side

hero member
Activity: 980
Merit: 504
PredX - AI-Powered Prediction Market
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:

Code:
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



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

SOLUTION:

The stupid solution:  remove .htaccess (or reconfigure) in the web server...  simple and it killed 4 days for me Smiley
Jump to: