-
-
Save anonymous/b943bd2bef536b22bd46 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Expected value of the payment in satoshi | |
$real_value = 10000; | |
$real_secret = 'ZzsMLGKe162CfA5EcG6j'; | |
$invoice_id = $_GET['invoice_id']; | |
$transaction_hash = $_GET['transaction_hash']; | |
$input_transaction_hash = $_GET['input_transaction_hash']; | |
$input_address = $_GET['input_address']; | |
$value_in_satoshi = $_GET['value']; | |
$value_in_btc = $value_in_satoshi / 100000000; | |
$my_bitcoin_address = "1Pqh1kXjMVa8KvSJFg9DoUoKz9G1kNiYvo"; | |
$secret = $_GET['secret']; | |
//Check the secret passed to the create method is equal | |
if ($real_secret != $secret) { | |
return; | |
} | |
//Commented out to test, uncomment when live | |
if ($_GET['test'] == true) { | |
return; | |
} | |
//Check the address is our address | |
if ($_GET['destination_address'] != $my_bitcoin_address) | |
return; | |
try { | |
//Open the database - EDIT THIS TO CONNECT TO YOUR DB | |
$db = new PDO('mysql:host=localhost;dbname=test', 'root', ''); | |
} catch(Exception $e) { | |
die($error); | |
} | |
//Get the amount received from this transaction | |
$amount_validated = file_get_contents('https://blockchain.info/q/txresult/' . $input_transaction_hash . '/' . $input_address); | |
//Validate the callback is passing the correct amount. | |
if ($amount_validated < $value_in_satoshi || $real_value < $value_in_satoshi) | |
return; | |
//Assert that 3 or more confirmations have been recieved, quit script execution if not | |
if ($_GET['confirmations'] < 3) | |
return; | |
//Mark the invoice as paid | |
$stmt = $db->prepare("UPDATE invoices SET paid=? WHERE id=?"); | |
$query = $stmt->execute(array(1, $invoice_id)); | |
//Send OK back to blockchain.info | |
if($query) { | |
echo "*ok*"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment