Improved verbose information in examples

This commit is contained in:
Pieter Poorthuis 2018-03-08 11:54:05 +01:00
parent 83e2e0e678
commit 70514da027
5 changed files with 56 additions and 3 deletions

View File

@ -33,7 +33,9 @@ $client = new \Bitpay\Client\Client();
* own as long as it implements the NetworkInterface. In this example
* we will use testnet
*/
$network = new \Bitpay\Network\Testnet();
//$network = new \Bitpay\Network\Testnet();
$network = new \Bitpay\Network\Livenet();
/**
* The adapter is what will make the calls to BitPay and return the response
@ -79,7 +81,9 @@ try {
* decided that it makes more sense to allow your application to handle
* this exception since each app is different and has different requirements.
*/
echo "Pairing failed. Please check whether you're trying to pair a production pairing code on test.";
echo "Exception occured: " . $e->getMessage().PHP_EOL;
echo "Pairing failed. Please check whether you're trying to pair a production pairing code on test.".PHP_EOL;
$request = $client->getRequest();
$response = $client->getResponse();
/**

View File

@ -17,7 +17,8 @@ $storageEngine = new \Bitpay\Storage\EncryptedFilesystemStorage('YourTopSecretPa
$privateKey = $storageEngine->load('/tmp/bitpay.pri');
$publicKey = $storageEngine->load('/tmp/bitpay.pub');
$client = new \Bitpay\Client\Client();
$network = new \Bitpay\Network\Testnet();
//$network = new \Bitpay\Network\Testnet();
$network = new \Bitpay\Network\Livenet();
$adapter = new \Bitpay\Client\Adapter\CurlAdapter();
$client->setPrivateKey($privateKey);
$client->setPublicKey($publicKey);
@ -81,8 +82,10 @@ $invoice
* a customer can view the invoice.
*/
try {
echo "Creating invoice at BitPay now.".PHP_EOL;
$client->createInvoice($invoice);
} catch (\Exception $e) {
echo "Exception occured: " . $e->getMessage().PHP_EOL;
$request = $client->getRequest();
$response = $client->getResponse();
echo (string) $request.PHP_EOL.PHP_EOL.PHP_EOL;
@ -91,3 +94,5 @@ try {
}
echo 'Invoice "'.$invoice->getId().'" created, see '.$invoice->getUrl().PHP_EOL;
echo "Verbose details.".PHP_EOL;
print_r($invoice);

View File

@ -31,6 +31,7 @@ $client->setAdapter($adapter);
* The last object that must be injected is the token object.
*/
$token = new \Bitpay\Token();
$token->setToken('HE7gQXJfm2CnTQ94bgKE9DiqHFqsPgBCvjgQRsU2tmkv'); // UPDATE THIS VALUE
$token->setToken('UpdateThisValue'); // UPDATE THIS VALUE
/**

View File

@ -51,6 +51,7 @@ $client->setNetwork($network);
$client->setAdapter($adapter);
$token = new \Bitpay\Token();
$token->setToken('UpdateThisValue'); // UPDATE THIS VALUE
$client->setToken($token);
/**

View File

@ -0,0 +1,42 @@
<?php
/**
* Copyright (c) 2014-2017 BitPay
*
* getInvoice
*
* Requirements:
* - Account on https://test.bitpay.com
* - Baisic PHP Knowledge
* - Private and Public keys from 001.php
* - Token value obtained from 002.php
* - Invoice created
*/
require __DIR__.'/../../vendor/autoload.php';
// Now fetch the invoice from BitPay
$client = new \Bitpay\Client\Client();
//$network = new \Bitpay\Network\Testnet();
$network = new \Bitpay\Network\Livenet();
$adapter = new \Bitpay\Client\Adapter\CurlAdapter();
$client->setNetwork($network);
$client->setAdapter($adapter);
$token = new \Bitpay\Token();
$token->setToken('UpdateThisValue'); // UPDATE THIS VALUE
$client->setToken($token);
/**
* This is where we will fetch the invoice object
*/
$invoice = $client->getInvoice("UpdateThisValue");
$request = $client->getRequest();
$response = $client->getResponse();
echo (string) $request.PHP_EOL.PHP_EOL.PHP_EOL;
echo (string) $response.PHP_EOL.PHP_EOL;
print_r($invoice);
?>