Skip to content

Instantly share code, notes, and snippets.

Created March 19, 2013 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/266b166175d059b3d723 to your computer and use it in GitHub Desktop.
Save anonymous/266b166175d059b3d723 to your computer and use it in GitHub Desktop.
<?php
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);
}
//Create new invoice in table
$stmt = $db->prepare("INSERT INTO invoices VALUES(null, :refund_addr, 0)");
$stmt->execute(array(':refund_addr' => $_GET['refund_addr']));
//Get the ID of the invoice
$invoice_id = $db->lastInsertId();
$secret = 'ZzsMLGKe162CfA5EcG6j';
$my_address = '1Pqh1kXjMVa8KvSJFg9DoUoKz9G1kNiYvo';
$my_callback_url = 'https://mystore.com?invoice_id='.$invoice_id.'&secret='.$secret;
$root_url = 'http://blockchain.info/api/receive';
$parameters = 'method=create&address=' . $my_address .'&shared=false&callback='. urlencode($my_callback_url);
$response = file_get_contents($root_url . '?' . $parameters);
$object = json_decode($response);
echo "Your invoice ID is $invoice_id. Send payment to " . $object->input_address;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment