User avatar
coinableS
Nickel Bitcoiner
Nickel Bitcoiner
Posts: 65
Joined: Wed Sep 30, 2015 6:06 am

Donate BTC of your choice to 1J9ikqFuwrzPbczsDkquA9uVYeq6dEehsj

Contact: Website Twitter

Using Blockchain.info New Receive Payments API v2 HD BIP32 xpub

Fri Nov 27, 2015 8:50 pm

Using blockchain's new receive payments API. (https://blockchain.info/api/api_receive)

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'];
Implement the callback: http://pastebin.com/7RNyEiTQ

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! }
Link to github shopping cart: https://github.com/coinables/Blockchain ... pping-Cart

BTC: 1NPrfWgJfkANmd1jt88A141PjhiarT8d9U

Return to “Development & Technical Discussion”

Who is online

Users browsing this forum: No registered users and 34 guests