Skip to content
This repository has been archived by the owner on Dec 28, 2018. It is now read-only.
Bungeebones edited this page Nov 3, 2014 · 23 revisions

Welcome to the bitcoin_gateway wiki!

This PHP and MySql payment gateway is something you would use on a server where you have installed bitcoin already. When the bitcoind server is running it is communicating with the bitcoin peer to peer network and is constantly updating the "blockchain" which is the heart and soul of the bitcoin system.

With this PHP script you will be able to provide the users on another server (such as a website on a shared hosting account) a connection to this bitcoin server so that they can get an address to make a deposit for example. The script will also monitor the progress of the transaction on the network as the miners process it in preparation for the transaction to be added to the next block.

Once the payment that the user has made has been processed by the miners and it has received the configured (by you) number of confirmations then the script will store a record of the transaction on both the bitcoin server's MySql database and the hosted server's.

This script is mostly concerned with what is happening on the bitcoin server, however. A user that accesses the payment page will be issued a new address for each payment or deposit they make. The script will watch their account after an address has been generated to see whether a payment has been sent to it or not. If not it will keep displaying the same, unused address to the user at subsequent page loads. But after a user has submitted a payment, the script is then watching and reporting the progress and is concerned with crediting the account if/when the proper confirmations have occurred. The actual crediting of the user account can be immediate if configured that way by the programmer (not recommended usually) or it can be configured to be performed after any desired number of confirmations occur.

It is desirable and advantageous for the user to make one and only one deposit to an address but there is no way a programmer can assure that. Bitcoin addresses are public information and users can "save" them and reuse them even though they are requested not to and the script provided them another to use instead. The script can handle that issue because each transaction gets a unique transaction id insuring proper crediting.

The script is currently processing only upon the refreshing of the page by the user. There are a number of approaches that can be taken to make sure the processing gets finished automatically such as a cron job or probably better is the Bitcoin server function "walletnotify" but inserting that functionality is being left for last. The current manual process provides more error checking and goes through a process something like this:

_ After a user has made a payment and refreshes the page the script no longer displays the address and, instead, acknowledges the deposit was made. It will display how many confirmations the transaction has received too. It will display a different message at 0 confirmations, another message at 1 confirmation and yet another after 3 confirmations (1 and three conf. are the current trigger settings). There is a confirmation on average about every 10 minutes so 3 confirmations may take 30 minutes. The user will not get a new address until after that third confirmation. If the user neglects refreshing the page until after the third or higher confirmation the script will conduct all the processing at one time and will display a new address too._

Operating Testnet

Overview of the Bitcoin Testnet


A forum post on setting up (scroll to end of posts for updated method)

A Quick And Dirty Bitcoin Test Server On A Laptop

I originally ran a server on my laptop. In order to enable my shared hosting accounts to connect to my local laptop I used ngrok.com. I've since moved the server to its own VPS but the setup on the laptop works quite well.

Download, install and use the instructions from here - https://ngrok.com/download. Especially notice the help command (./ngrok -help). use it to test after install.

Then visit the documentation tab (https://ngrok.com/usage). It tells you to use ngrok 80 to start it but you need to use the same syntax as for the help command. Enter ./ngrok 80 instead and it will generate a link - something like http://6b633173.ngrok.com -> 127.0.0.1:80.

In the included sample of the code to use on your shared server (the file index.OS.php) there is a $file = http://your_VPS_address_here/process_testnet.php. Replace that example link with the ngrok link so that it looks something like

$file="http://6b633173.ngrok.com -> 127.0.0.1:80/process_testnet.php"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $file); curl_setopt($ch, CURLOPT_POSTFIELDS, array('user_id' => $account, 'isTestCoin'=> 1 )); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($ch); curl_close($ch);

Copy and save that link for use on your shared server.

Resources

The Bitcoin Server Commands


TestNet block explorer


A Forum discussion about the basics of Multi-sig uses


PackageList - A Main repository For Composer Installable Bitcoin Packages

Code

PHP BitcoinLib Library


Easy Bitcoin PHP Class


PHP SHOP- Another PHP Class


[php-bitcoind - A Test Driven Development client class for the bitcoind JSON-RPC API] (https://github.com/martinlindhe/php-bitcoind/blob/master/test/Bitcoind/JsonRpcClientTest.php)

Installation

There are two versions of Bitcoin you can install -1) Bitcoin-QT and Bitcoind. The only difference between them is that QT also provides a GUI wallet in addition to the server. The information displayed by the GUI (and more) can also be gotten from the command line using the server version bitcoind and the server commands (link listed under "Resources" above).


Install Bitcoin-QT in Ubuntu 12.04*, 14.04*

  • I suggest using v. 12.04.5

Install Tutorial #2 in Ubuntu

Download

Bitcoin.org (Windows, Mac, Linux)