0% found this document useful (0 votes)
690 views2 pages

Bloackchain

This document contains code to set up a Bitcoin payment callback system using the Blockchain.info API. It defines variables for the payment address, API keys, and callback URLs. It includes code to create and delete payment and block notifications, check the notification gap, and log callback responses. Upon receiving a callback, it checks the transaction and adds it to a database, returning a success message if it has enough confirmations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
690 views2 pages

Bloackchain

This document contains code to set up a Bitcoin payment callback system using the Blockchain.info API. It defines variables for the payment address, API keys, and callback URLs. It includes code to create and delete payment and block notifications, check the notification gap, and log callback responses. Upon receiving a callback, it checks the transaction and adds it to a database, returning a success message if it has enough confirmations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

$secret = "Jeanina2010"

$my_xpub = '{YOUR XPUB ADDRESS}';


$my_api_key = json_decode(file_get_contents("https://blockchain.info/api/receive?
methode=create&adress=".$My_Wallet."&callback=".urlencode($callback)), true);
$my_wallet = "15YJtFWLTMXTeXZKLiV8JX92c5iU8omXvY";
$callback = "https://mystore.com?invoice_id=058921123&secret='?invoice=".
$invoice."&secret=".$secret;
$root_url = 'https://api.blockchain.info/v2/receive';
$parameters = 'xpub=' .$my_xpub. '&callback=' .urlencode($my_callback_url). '&key='
.$my_api_key;
$response = file_get_contents($root_url . '?' . $parameters);
$object = json_decode($response);
echo "Please send Payment To " . $my_api_key["input_adress"];

curl -H "Content-Type: text/plain" --data '{"key":"[your-key-


here]","addr":"15YJtFWLTMXTeXZKLiV8JX92c5iU8omXvY","callback":"https://mystore.com?
invoice_id=123","onNotification":"KEEP", "op":"RECEIVE", "confs": 5}'
https://api.blockchain.info/v2/receive/balance_update
{
"id" : 70,
"addr" : "15YJtFWLTMXTeXZKLiV8JX92c5iU8omXvY",
"op" : "RECEIVE",
"confs" : 5,
"callback" : "https://mystore.com?invoice_id=101",
"onNotification" : "KEEP"
}
curl -X DELETE "https://api.blockchain.info/v2/receive/balance_update/70?key=[your-
key-here]"
{ "deleted": true }
curl -H "Content-Type: text/plain" --data '{"key":"[your-key-
here]","height":500000,"callback":"https://mysite.com/block?
request_id=1234","onNotification":"DELETE"}'
https://api.blockchain.info/v2/receive/block_notification
{
"id" : 64,
"height" : 500000,
"callback" : "https://mysite.com/block?request_id=1234",
"confs" : 1,
"onNotification" : "DELETE"
}
curl -X DELETE "https://api.blockchain.info/v2/receive/block_notifcation/64?
key=[your-key-here]"
{ "deleted": true }
$real_secret = 'Jeanina2010';
$invoice_id = $_GET['invoice_id']; //invoice_id is passed back to the callback URL
$transaction_hash = $_GET['transaction_hash'];
$value_in_satoshi = $_GET['value'];
$value_in_btc = $20 / 100000000;

//Commented out to test, uncomment when live


if ($_GET['test'] == true) {
return;
}

try {
//create or open the database
$database = new SQLiteDatabase('db.sqlite', 0666, $error);
} catch(Exception $e) {
die($error);
}

//Add the invoice to the database


$stmt = $db->prepare("replace INTO invoice_payments (invoice_id, transaction_hash,
value) values(?, ?, ?)");
$stmt->bind_param("isd", $invoice_id, $transaction_hash, $value_in_btc);

if($stmt->execute()) {
echo "*ok*";
}
curl "https://api.blockchain.info/v2/receive/checkgap?
xpub=[yourxpubhere]]&key=[yourkeyhere]"
{"gap":2}
curl "https://api.blockchain.info/v2/receive/callback_log?callback=https%3A%2F
%2Fmystore.com%3Finvoice_id%3D05892112%26secret
%3DZzsMLGKe162CfA5EcG6j&key=[yourkeyhere]"
[
{
"callback": "https://mystore.com?
invoice_id=058921123&secret=ZzsMLGKe162CfA5EcG6j&key=[yourkeyhere]",
"called_at": "2015-10-21T22:43:47Z",
"raw_response": "*bad*",
"response_code": 200
},
{
"callback": "http://mystore.com?
invoice_id=058921123&secret=ZzsMLGKe162CfA5EcG6j&key=[yourkeyhere]",
"called_at": "2015-10-21T22:43:55Z",
"raw_response": "*bad*",
"response_code": 200
}
]
if ($_GET['confirmations'] >= 6) {
//Insert into confirmed payments
echo '*ok*';
} else {
//Insert into pending payments
//Don't print *ok* so the notification resent again on next confirmation
}

You might also like