Reputation: 49
I'm developing a system that will send BTC to a certain receiver via coinbase php api. The system is working fine in my localhost but after moving it to live it doesn't work and no error message. I tried tracing an error step by step by echoing the -3 and run the script and I found that when I put the echo after
$account = $client->getPrimaryAccount();
echo -3;
...I've got a white page and no -3 as a test result.
Here's the full construction of this process:
$apiKey = "dfdsfsd";
$apiSecret = "fdsfdsfsfdff";
$configuration = Configuration::apiKey($apiKey, $apiSecret);
$client = Client::create($configuration);
$_btc_wallet = @$_GET['_btcwallet'];
$_btc_amount = @$_GET['_btc_amount'];
$transaction = Transaction::send([
'toBitcoinAddress' => $_btc_wallet,
'bitcoinAmount' => $_btc_amount,
'description' => 'Group Fund Transfer',
]);
$account = $client->getPrimaryAccount();
echo -3;
$client->createAccountTransaction($account, $transaction);
echo 1;
exit;
Need help badly.... :-(
Upvotes: 0
Views: 672
Reputation: 121
Tl;dr. You must install and run
Composer
and add this line before the rest of your code:require __DIR__ . '/vendor/autoload.php';
Coinbase PHP API uses Composer
to handle its dependencies, so that following the install procedure detailed on Github is mandatory to avoid headaches.
Composer
reads a configuration file provided by the author of the Coinbase PHP API, and creates automatically a directory structure that contains all the dependencies needed, and, most important, an autoload script.
PHP used to be 100% self contained, having a plethora of functions and classes already built in, so many PHP coders (me for example) had some problems to switch to a more modular approach, someway similar to the Python style with its pip
command or to PEAR
in Perl galaxy, and so on, with some important differences, of course.
So, be sure to follow this sequence:
1) Let's say you are on Linux, you have a local web server installed, and the document root of your web site is /var/www/newsite
.
2) Enter the your document root, download the latest Coinbase PHP API release and untar/unzip it. I suggest to go for the releases, and not to clone the repository.
$
$ cd /var/www/newsite
$
$ tar xzvf coinbase-php-2.5.0.ta.gz
3) Now you need to download Composer
. Go to its homepage at https://getcomposer.org/ and click on Download. Follow the instructions in the Command-line installation section.
I report them here for convenience, but they may change so always check the Composer
's homepage. From your document root:
$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
$ php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
$ php composer-setup.php
$ php -r "unlink('composer-setup.php');"
4) last step, run Composer
and wait while he does the job:
$ php composer.phar install
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 26 installs, 0 updates, 0 removals
- Installing guzzlehttp/promises (v1.3.1): Downloading (100%)
- Installing psr/http-message (1.0.1): Downloading (100%)
- Installing guzzlehttp/psr7 (1.4.2): Downloading (100%)
- Installing guzzlehttp/guzzle (6.2.3): Downloading (100%)
- Installing psr/log (1.0.2): Downloading (100%)
- Installing symfony/yaml (v3.2.8): Downloading (100%)
- Installing sebastian/version (1.0.6): Downloading (100%)
- Installing sebastian/global-state (1.1.1): Downloading (100%)
- Installing sebastian/recursion-context (1.0.5): Downloading (100%)
- Installing sebastian/exporter (1.2.2): Downloading (100%)
- Installing sebastian/environment (1.3.8): Downloading (100%)
- Installing sebastian/diff (1.4.2): Downloading (100%)
- Installing sebastian/comparator (1.2.4): Downloading (100%)
- Installing doctrine/instantiator (1.0.5): Downloading (100%)
- Installing phpunit/php-text-template (1.2.1): Downloading (100%)
- Installing phpunit/phpunit-mock-objects (2.3.8): Downloading (100%)
- Installing phpunit/php-timer (1.0.9): Downloading (100%)
- Installing phpunit/php-file-iterator (1.4.2): Downloading (100%)
- Installing phpunit/php-token-stream (1.4.11): Downloading (100%)
- Installing phpunit/php-code-coverage (2.2.4): Downloading (100%)
- Installing webmozart/assert (1.2.0): Downloading (100%)
- Installing phpdocumentor/reflection-common (1.0): Downloading (100%)
- Installing phpdocumentor/type-resolver (0.2.1): Downloading (100%)
- Installing phpdocumentor/reflection-docblock (3.1.1): Downloading (100%)
- Installing phpspec/prophecy (v1.7.0): Downloading (100%)
- Installing phpunit/phpunit (4.8.35): Downloading (100%)
symfony/yaml suggests installing symfony/console (For validating YAML files using the lint command)
sebastian/global-state suggests installing ext-uopz (*)
phpunit/phpunit-mock-objects suggests installing ext-soap (*)
phpunit/php-code-coverage suggests installing ext-xdebug (>=2.2.1)
phpunit/phpunit suggests installing phpunit/php-invoker (~1.1)
Writing lock file
Generating autoload files
$
5) Mind the last line above. The examples on the Github's README of the Coinbase PHP API are a little bit misleading, since Composer
is nice and creates a file called autoload.php
which must be used to load the new libraries the proper way.
So, here is your code modified to use it, thus loading all the needed dependencies:
<?php
require __DIR__ . '/vendor/autoload.php';
$apiKey = 'topsecret';
$apiSecret = 'topkey';
$configuration = Configuration::apiKey($apiKey, $apiSecret);
$client = Client::create($configuration);
$account = $client->getPrimaryAccount();
The line:
require __DIR__ . '/vendor/autoload.php';
should make the difference. Without it, the script exits with no errors on screen, but with many errors in the php log file, but this behaviour depends on the server configuration.
Hope this helps!
Upvotes: 2