Integrations / Bitcoin Simple Advertisement Board
This example show that generated addresses related to supplied identifier. These addresses are reusable. We will endlessly monitor it regardless of payments because the Store can sell the same goods repeatedly. Or you can use this address to top-up user's account balance in a project, for example, the game balance or advertisement balance.
We show paid advertisement on the top of page and last five unpaid at the bottom. Paid advertisement sorted descently by total peid amount.
- PHP 5.0+
- MySQL server
Also this example uses JQuery library version 1.11 and Ajax query to update 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.
- $count_of_confirmations - count of network confirmations for transaction. Minimum 1, recomend 3
- $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.
How does it work?
Open index.php in a browser. Submit any message. At payment page you will see generated Bitcoin address with QR code.
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. Ajax script periodically refresh tag <div> and show status of transaction. Page status.php get payment status from database.
Our API server monitors the generated address and notifies specified URL to callback.php page with information about transaction. This callback page save transaction status to database. See more at API documentation.
The payment is considered paid when the number of confirmations in the Bitcoin network is equal to the variable $count_of_confirmations.