You need to run a local nodejs service. From there you can then integrate with php.
As of January 2016 Blockchain.info made changes to the wallet API service that now require you to run a local nodeJS service to handle the calls. This will require you to have root access to your webserver so you will need to use a VPS instead of a basic shared web host.
- Create an account with blockchain.info, and register an email
address.
- Request an API key here https://blockchain.info/api/api_create_code
- Login to your blockchain wallet, goto account settings, IP Restrictions and check the box to allow API access
- Goto DigitalOcean, register, create a new droplet, goto one-click-install and choose the MEAN stack Other options are up to you, I chose $5/month and IPv6
- Open your console or SSH through putty
- type
root
, enter your password, create a new password
- Now you're in!
- type
sudo apt-get update
- now install nodejs
- type
sudo apt-get install nodejs
- press
y
to accept
- install NPM
- sudo
apt-get install npm
y
to accept
- install blockchain-wallet
- type
npm install -g blockchain-wallet-service
- if you see some warnings or errors, don't worry
- once complete verify it installed
- navigate to
usr/local/bin
- type
node blockchain-wallet-service -V
- if installed it should return with the version number
- you can now launch the service, but first we will want to install apache and PHP so we can interact with it outside of nodejs
- Navigate back to root
- Install Apache
- type
sudo apt-get update
- type
sudo apt-get install apache2
- Install PHP
- type
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
- Install curl
- type
sudo apt-get install php5-curl
- Restart your VPS
reboot
- Launch the blockchain-wallet-service
- navigate to
usr/local/bin
- type
node blockchain-wallet-service start --port 3030
Login to your wallet using the below code
$url = "http://127.0.0.1:3030/merchant/YOUR-GUID/login?password=YOUR-PASSWORD&api_code=YOUR-API-CODE";
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
$ccc = curl_exec($ch);
$json = json_decode($ccc, true);
var_dump($json);
Save the above and run it on your server. The file should keep spinning and loading since blockchain doesn't recognize the IP address. Wait for it to timeout about 60 seconds, and then check your email. Blockchain should have sent you an API access attempt showing what IP tried to connect. Follow the link and authorize the attempt, also the IP address from the email and whitelist it in your wallet account settings.
Now try running the file again.
If you did everything correctly you should see a response that lists your GUID followed by Success TRUE
Now you're connected and you can start sending requests with your wallet.
The calls work the same as version one, except you will send your requests through this service instead of get requests to blockchain.info.