0
I want to start accepting Bitcoins payment on my site, I got the callback and the index working fine, the only thing is that it won't update the index once the payment is received, I'd like to give the user some kind of live feedback when the payment is received, how can I do that?
Below is what I got.
Index.php
<?php
$api_key = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx";
$xpub = "xpubxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$secret = "xxxxxxxxxxxxxxxxxxxx";
$rootURL = "https://xxxxxxxxxx.org/BlockChain";
$orderID = uniqid();
$callback_url = $rootURL . "/callback.php?invoice=" . $orderID . "&secret=" . $secret . "&username=Teste" . "&password=qwerty123";
$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'];
echo $payTo;
?>
Callback.php
$secret = "xxxxxxxxxxxxxxxxxxxx";
if ($_GET['secret'] != $secret) {
die("Stop doing that!");
}
else {
//Register new user, insert more days, etc...
//# START DEBUG #
$fff = fopen("text.txt", "w");
$value = $_GET['value'] . " - ";
$fw = fwrite($fff, $value);
$txhash = $_GET['transaction_hash'] . " - ";
$fw = fwrite($fff, $txhash);
$invoice = $_GET['invoice'] . " - ";
$fw = fwrite($fff, $invoice);
$value_in_btc = $_GET['value'] / 100000000 . " - ";
$fw = fwrite($fff, $value_in_btc);
$username = $_GET['username'] . " - ";
$fw = fwrite($fff, $username);
$password = $_GET['password'] . " - ";
$fw = fwrite($fff, $password);
fclose($fff);
//# END DEBUG #
echo "*ok*"; //Tell blockchain everything is ok, so they stop.
}
?>