array( 'network' => 'testnet', // Valid values are testnet/livenet 'public_key' => $publicKeyPath, 'private_key' => $privateKeyPath, 'key_storage_password' => $keyStoragePassword, ) ) ); echo 'Bitpay class initialized.'.PHP_EOL; /** * If you have not already generated and persisted you keys, please uncomment * this code. This should only be ran once. Once you have generated your key * pairs, keep you keys in a secure location. If you regenerate your keys, you * will need to repair and get a new token. * $privateKey = \Bitpay\PrivateKey::create($privateKeyPath)->generate(); $publicKey = \Bitpay\PublicKey::create($publicKeyPath)->setPrivateKey($privateKey)->generate(); $bitpay->get('key_manager')->persist($privateKey); $bitpay->get('key_manager')->persist($publicKey); echo 'Public and Private keys have been generated and persisted.'.PHP_EOL; //exit(0); // exit in case you just wanted to generate keys */ /** * If you have not already obtained a token, please uncomment this code, you * will need a pairing code. A pairing code is a one time use code and can only * be used once. * $publicKey = $bitpay->get('public_key'); // @var \Bitpay\PublicKey $sin = \Bitpay\SinKey::create()->setPublicKey($publicKey)->generate(); // @var \Bitpay\SinKey if (empty($pairingCode)) { throw new \Exception('Please set a pairing code to a value.'); } $token = $bitpay->get('client')->createToken( array( 'pairingCode' => $pairingCode, 'label' => 'Tutorial 004', 'id' => (string) $sin, ) ); echo 'Token Obtained "'.$token->getToken().'"'.PHP_EOL; //exit(0); */ /** * If you already have a token, uncomment this code * */ $token = new \Bitpay\Token(); $token->setToken($tokenString); /** * Code that makes the invoice */ $invoice = new \Bitpay\Invoice(); $item = new \Bitpay\Item(); $item ->setCode('skuNumber') ->setDescription('General Description of Item') ->setPrice('1.99'); $invoice->setCurrency(new \Bitpay\Currency('USD')); $invoice->setItem($item); $client = $bitpay->get('client'); $client->setToken($token); try { $client->createInvoice($invoice); } catch (\Exception $e) { $request = $client->getRequest(); $response = $client->getResponse(); echo (string) $request.PHP_EOL.PHP_EOL.PHP_EOL; echo (string) $response.PHP_EOL.PHP_EOL; exit(1); // We do not want to continue if something went wrong } echo 'Invoice "'.$invoice->getId().'" created, see '.$invoice->getUrl().PHP_EOL; /** * Q: PHP Fatal error: Uncaught exception 'Exception' with message 'Unable to create token' * A: This error will happen if you are are trying to use a pairing code that has already * been used. To fix this issue, create a new pairing code and use that one. * * It might also mean that the pairing code you obtained was generated on 'bitpay.com' * and you have the network setup for 'testnet' or you generated a pairing code on * 'test.bitpay.com' and have the network set to 'livenet'. Please double check your * configuration settings. * * Q: PHP Fatal error: Uncaught exception 'Exception' with message 'Could not decode key' * A: The key was found, however when trying to decrypt it, it was unabled because the key * is either not encrypted or the key is encrypted and the password you have to decrypt * it is invalid. Double check and make sure that the settings are correct, if unsure, * regenerate your keys. You will need to decrypt using the same storage engine. */