public function testConfigAbleToPersistAndLoadKeys() { $root = vfsStream::setup($this->temp_path_root); $bitpay = new \Bitpay\Bitpay(array('bitpay' => array('network' => 'testnet', 'private_key' => vfsStream::url($this->temp_path_pri), 'public_key' => vfsStream::url($this->temp_path_pub)))); $pri = new \Bitpay\PrivateKey(vfsStream::url($this->temp_path_pri)); $pri->generate(); $pub = new \Bitpay\PublicKey(vfsStream::url($this->temp_path_pub)); $pub->setPrivateKey($pri)->generate(); /** * Save keys to the filesystem */ $storage = $bitpay->get('key_storage'); $storage->persist($pri); $storage->persist($pub); /** * This will load the keys, if you have not already persisted them, than * this WILL throw an Exception since this will load the keys from the * storage class */ $pri = $bitpay->get('private_key'); $pub = $bitpay->get('public_key'); }
*/ /** * 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