https://www.youtube.com/watch?v=D2__AFoOdec
Their new version using extended public keys, no forwarding of payments needed, fast callbacks for website and database integration.
Initiate the receiving address: http://pastebin.com/MB4Byif9
Code: Select all
//set parameters
$api_key = "your_blockchain_api_Key";
$xpub = "xpubYour_extended_public_key";
$secret = "your_secret"; //this can be anything you want
$rootURL = "http://yourrooturl.com/directory"; //example https://mysite.org or http://yourhomepage.com/store
$orderID = uniqid();
//call blockchain info receive payments API
$callback_url = $rootURL."/callback.php?invoice=".$orderID."&secret=".$secret;
$receive_url = "https://api.blockchain.info/v2/receive?key=".$api_key."&xpub=".$xpub."&callback=".urlencode($callback_url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $receive_url);
$ccc = curl_exec($ch);
$json = json_decode($ccc, true);
$payTo = $json['address'];
Code: Select all
//implementing the callback file
$secret = "your_secret";
if($_GET['secret'] != $secret)
{
die('Stop doing that');
}
else
{
//update DB
$order_num = $_GET['invoice'];
$amount = $_GET['value']; //default value is in satoshis
//$amountCalc = $amount / 100000000; //optional convert to bitcoins
$queryUpdate = "UPDATE orders SET paid = 1, recd = $amount WHERE orderid = '$order_num'";
$doUpdate = mysqli_query($conn, $queryUpdate) or die(mysqli_error($conn));
echo "*ok*"; // you must echo *ok* on the page or blockchain will keep sending callback requests every block up to 1,000 times!
}
BTC: 1NPrfWgJfkANmd1jt88A141PjhiarT8d9U