Integrations / Bitcoin Simple Shop

Proof of concept for a Bitcoin e-commerce site using our API. This example is a fork of Blockchain.info V1 Bitcoin simple shop.

Requirements

The example uses JQuery library version 1.8.0 and Blockchain.info socket API to monitor payment and refresh status on a page.

Setup

  1. Deploy files to an internet host. Localhost is not applicable because callback to localhost impossible.
  2. Edit include.php, change parameters:
    • $mysite_root - your website URL where callback.php file located. Symbol slash at the end of string is required.
    • $secret - any secret string without spaces.
    • $my_bitcoin_address - CHANGE IT to your own bitcoin address to receive payments.
    • $mysql_host - MySQL host name.
    • $mysql_username - MySQL username.
    • $mysql_password - MySQL password.
    • $mysql_database - MySQL database.
  3. Open setup.php in a browser. This file connects to the database to create database and tables.

Done. Open index.php in a browser.

How does it work?

File index.php contain variables (you can experiment with it):

$invoice_id = 9001;
$price_in_usd = 15;

Open page in a browser. Click button "Bitcoin Pay now" and you will see invoice page. This page prepare request with $my_bitcoin_address, concatenate callback URL $mysite_root + callback.php and add $secret key to query. See more at API documentation.

Then this request goes to our API server. The server returns the generated Bitcoin address for this invoice. Page get current Bitcoin price variable $price_in_usd and show QR code with the amount to pay. JavaScript uses socket to see arrived transaction and show status.

Our API server monitors the generated address and notifies specified callback.php page with information about payment. See more at API documentation.

After success payment with four Bitcoin network confirmations, you will see page order_status.php?invoice_id=9001

Bitcoin Demo Shop. Example how to accept Bitcoin payments. Demo of Bitcoin Simple Shop

Github Logotype Bitcoin Simple Shop at Apirone GitHub Repositories

ZIP archive ZIP archive of source code for Bitcoin Simple Shop