Walletnotify needs to be defined in your bitcoin.conf file,
example:
walletnotify = /usr/bin/php some/path/newdeposit.php?tx=%s
In the above example every time there is a new transaction on your wallet, the newdeposit.php script will run and the transaction ID will be stored in a GET named "tx".
Then we can pull the transaction id from the tx GET and put it through a gettransaction
command.
$tx = $_GET['tx'];
$getTrans = $bitcoin->gettransaction($tx);
From there we need to look through the API response, see if it has at least once confirmation, and how much was sent. We'll do this by running a loop, checking for the "receive" category. If there is a match you can do whatever you want in your database.
$confirmations = $getTrans["confirmations"];
if($confirmations < 1){
die();
} else {
$countDetails = count($getTrans['details']);
for($i=0;$i<$countDetails;$i++){
$getAddress = $getTrans['details'][$i]['address'];
$getReceive = $getTrans['details'][$i]['category'];
if($getAddress == $myAddress && $getReceive == "receive"){
$amount = $getTrans['details'][$i]['amount'];
$amount = $amount * 100000000;
//do something with $amount
}
}
}
Walletnotify only fires twice. Once when the transaction first appears on the network, and a second time after it has been included in a block(one confirmation).
Don't forget to multiply the amount by 100 million to turn it into satoshis so you're not working with floats.