bitpay / php-bitpay-client

PHP implementation for the BitPay cryptographically secure RESTful API
MIT License
166 stars 147 forks source link

Unable to create token #245

Closed ghost closed 7 years ago

ghost commented 7 years ago

Client.php line:505

ghost commented 7 years ago
        $storageEngine = new \Bitpay\Storage\FilesystemStorage();
        $privateKey = $storageEngine->load('/tmp/bitpay.pri');
        $publicKey = $storageEngine->load('/tmp/bitpay.pub');
        /**
         * Generate our SIN:
         */
        $sin = \Bitpay\SinKey::create()->setPublicKey($publicKey)->generate();
        /**
         * Create the client:
         */
        $client = new \Bitpay\Client\Client();
        /**
         * The network is either livenet or testnet. You
         * can also create your own as long as it
         * implements the NetworkInterface. In this
         * example we will use testnet.
         */
        $network = new \Bitpay\Network\Livenet();
        /**
         * The adapter is what will make the calls to
         * BitPay and return the response from BitPay.
         * This can be updated or changed as long
         * as it implements the AdapterInterface.
         */
        $adapter = new \Bitpay\Client\Adapter\CurlAdapter();
        /**
         * Now all the objects are created and we can
         * inject them into the client.
         */
        $client->setPrivateKey($privateKey);
        $client->setPublicKey($publicKey);
        $client->setNetwork($network);
        $client->setAdapter($adapter);
        /**
         * Paste the pairing code you generated
         * in your merchant dashboard in STEP 2:
         */
        $pairingCode = 'uw5deZ4';
        $token = $client->createToken(
         array(
         'pairingCode' => $pairingCode,
         'label' => 'Some description...',
         'id' => (string) $sin,
         )
        );
        /**
         * Now persist (save) the token obtained OR,
         * after it's created initially, you can call the
         * getTokens() method to retrieve all tokens
         * associated with your key.
         */
        $persistThisValue = $token->getToken();
        echo 'Token obtained: ' . $persistThisValue . PHP_EOL;
ghost commented 7 years ago

$client->createToken respond error: Unable to create token

pieterpoorthuis commented 7 years ago

Please make sure you use a valid pairingCode, created with a valid BitPay merchant account on www.bitpay.com.

The code examples from the tutorial show to catch the exception and print more info: https://github.com/bitpay/php-bitpay-client/blob/master/examples/tutorial/002_pair.php