Skip to content
This repository has been archived by the owner on Jan 22, 2021. It is now read-only.

Unable to create token #245

Closed
ghost opened this issue Aug 5, 2017 · 3 comments
Closed

Unable to create token #245

ghost opened this issue Aug 5, 2017 · 3 comments

Comments

@ghost
Copy link

ghost commented Aug 5, 2017

Client.php line:505

@ghost
Copy link
Author

ghost commented Aug 5, 2017

        $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
Copy link
Author

ghost commented Aug 5, 2017

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

@pieterpoorthuis
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant