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.
- PHP 5.0+
- MySQL server
The example uses JQuery library version 1.8.0 and Blockchain.info socket API to monitor payment and refresh status on a page.
- Deploy files to an internet host. Localhost is not applicable because callback to localhost impossible.
- 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.
- 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.
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