Bitcoin Forum
May 08, 2024, 10:37:58 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: [SOLVED] can some1 help me with blockchain API callback?  (Read 38736 times)
tomos81 (OP)
Hero Member
*****
Offline Offline

Activity: 896
Merit: 504


View Profile
March 09, 2017, 05:49:36 PM
Last edit: March 10, 2017, 01:57:07 PM by tomos81
 #1

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:
 <?php   $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



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

SOLUTION:

The stupid solution:  remove .htaccess (or reconfigure) in the web server...  simple and it killed 4 days for me Smiley
1715164678
Hero Member
*
Offline Offline

Posts: 1715164678

View Profile Personal Message (Offline)

Ignore
1715164678
Reply with quote  #2

1715164678
Report to moderator
1715164678
Hero Member
*
Offline Offline

Posts: 1715164678

View Profile Personal Message (Offline)

Ignore
1715164678
Reply with quote  #2

1715164678
Report to moderator
"Governments are good at cutting off the heads of a centrally controlled networks like Napster, but pure P2P networks like Gnutella and Tor seem to be holding their own." -- Satoshi
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715164678
Hero Member
*
Offline Offline

Posts: 1715164678

View Profile Personal Message (Offline)

Ignore
1715164678
Reply with quote  #2

1715164678
Report to moderator
1715164678
Hero Member
*
Offline Offline

Posts: 1715164678

View Profile Personal Message (Offline)

Ignore
1715164678
Reply with quote  #2

1715164678
Report to moderator
jonald_fyookball
Legendary
*
Offline Offline

Activity: 1302
Merit: 1004


Core dev leaves me neg feedback #abuse #political


View Profile
March 09, 2017, 06:09:28 PM
 #2

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


tomos81 (OP)
Hero Member
*****
Offline Offline

Activity: 896
Merit: 504


View Profile
March 09, 2017, 06:13:39 PM
 #3

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
jonald_fyookball
Legendary
*
Offline Offline

Activity: 1302
Merit: 1004


Core dev leaves me neg feedback #abuse #political


View Profile
March 09, 2017, 06:16:11 PM
 #4

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


tomos81 (OP)
Hero Member
*****
Offline Offline

Activity: 896
Merit: 504


View Profile
March 09, 2017, 06:18:40 PM
 #5

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
jonald_fyookball
Legendary
*
Offline Offline

Activity: 1302
Merit: 1004


Core dev leaves me neg feedback #abuse #political


View Profile
March 09, 2017, 06:21:24 PM
 #6

but did you try simplifying script to get write to a text file?

Did it work or not

tomos81 (OP)
Hero Member
*****
Offline Offline

Activity: 896
Merit: 504


View Profile
March 09, 2017, 06:24:47 PM
 #7

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..
jonald_fyookball
Legendary
*
Offline Offline

Activity: 1302
Merit: 1004


Core dev leaves me neg feedback #abuse #political


View Profile
March 09, 2017, 06:27:15 PM
 #8

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

tomos81 (OP)
Hero Member
*****
Offline Offline

Activity: 896
Merit: 504


View Profile
March 09, 2017, 06:30:29 PM
 #9

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
jonald_fyookball
Legendary
*
Offline Offline

Activity: 1302
Merit: 1004


Core dev leaves me neg feedback #abuse #political


View Profile
March 09, 2017, 06:36:36 PM
 #10

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.


tomos81 (OP)
Hero Member
*****
Offline Offline

Activity: 896
Merit: 504


View Profile
March 09, 2017, 06:46:37 PM
 #11

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
tomos81 (OP)
Hero Member
*****
Offline Offline

Activity: 896
Merit: 504


View Profile
March 10, 2017, 01:16:43 PM
 #12

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":"<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n<title>403 Forbidden</title>\n</head><body>\n<h1>Forbidden</h1>\n<p>You don't have permission to access /callback.php\non this server.<br />\n</p>\n<p>Additionally, a 403 Forbidden\nerror was encountered while trying to use an ErrorDocument to handle the request.</p>\n</body></html>\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
jonald_fyookball
Legendary
*
Offline Offline

Activity: 1302
Merit: 1004


Core dev leaves me neg feedback #abuse #political


View Profile
March 10, 2017, 04:43:40 PM
 #13

check with your web host to possible IP block or the log files to see why page isnt being served

tomos81 (OP)
Hero Member
*****
Offline Offline

Activity: 896
Merit: 504


View Profile
March 10, 2017, 06:01:44 PM
 #14

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
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!