diff --git a/examples/CreateInvoice.php b/examples/CreateInvoice.php index c0b00fe..e6fac91 100644 --- a/examples/CreateInvoice.php +++ b/examples/CreateInvoice.php @@ -66,16 +66,31 @@ $currency->setCode('USD'); $invoice->setCurrency($currency); /** - * Create a new client. You can see the example of how to configure this using - * a yml file as well. + * To load up keys that you have previously saved, you need to use the same + * storage engine. You also need to tell it the location of the key you want + * to load. */ -$bitpay = new \Bitpay\Bitpay(__DIR__ . '/config.yml'); +$storageEngine = new \Bitpay\Storage\FilesystemStorage(); +$privateKey = $storageEngine->load('/tmp/private.key'); +$publicKey = $storageEngine->load('/tmp/public.key'); + +/** + * Create a new client. + */ +$bitpay = new \Bitpay\Bitpay(); /** * Create the client that will be used to send requests to BitPay's API */ $client = $bitpay->get('client'); +$client->setPrivateKey($privateKey); +$client->setPublicKey($publicKey); +/** + * Add your btcpayserver url + */ +$client->setUri('https://btcpay.server/'); + /** * You will need to set the token that was returned when you paired your * keys. diff --git a/examples/CreatePayout.php b/examples/CreatePayout.php index b996b61..970b98d 100644 --- a/examples/CreatePayout.php +++ b/examples/CreatePayout.php @@ -44,16 +44,14 @@ $private->setHex('662be90968bc659873d723374213fa5bf7a30c24f0f0713aa798eb7daa7230 $public = new \Bitpay\PublicKey(); $public->generate($private); -$network = new \Bitpay\Network\Testnet(); $adapter = new \Bitpay\Client\Adapter\CurlAdapter(); - $bitpay = new \Bitpay\Bitpay(); $client = new \Bitpay\Client\Client(); $client->setPrivateKey($private); $client->setPublicKey($public); -$client->setNetwork($network); +$client->setUri('https://btcpay.server/'); $client->setAdapter($adapter); $client->createPayout($payout); diff --git a/examples/Currencies.php b/examples/Currencies.php index 04a2d59..791692b 100644 --- a/examples/Currencies.php +++ b/examples/Currencies.php @@ -7,6 +7,7 @@ require __DIR__ . '/../vendor/autoload.php'; $bitpay = new \Bitpay\Bitpay(__DIR__ . '/config.yml'); $client = $bitpay->get('client'); +$client->setUri('https://btcpay.server/'); $currencies = $client->getCurrencies(); /** @var \Bitpay\Currency $currencies[0] **/ diff --git a/examples/GetRate.php b/examples/GetRate.php index 7abbf89..df63314 100644 --- a/examples/GetRate.php +++ b/examples/GetRate.php @@ -7,9 +7,8 @@ require __DIR__ . '/../vendor/autoload.php'; $client = new \Bitpay\Client\Client(); $client->setAdapter(new \Bitpay\Client\Adapter\CurlAdapter()); -$client->setNetwork(new \Bitpay\Network\Testnet()); $request = new \Bitpay\Client\Request(); -$request->setHost('test.bitpay.com'); +$request->setUri('https://btcpay.server/'); $request->setMethod(\Bitpay\Client\Request::METHOD_GET); $request->setPath('rates/USD'); diff --git a/examples/GetTokens.php b/examples/GetTokens.php index ec31b4a..30abad4 100644 --- a/examples/GetTokens.php +++ b/examples/GetTokens.php @@ -14,6 +14,14 @@ require __DIR__ . '/../vendor/autoload.php'; +/** + * To load up keys that you have previously saved, you need to use the same + * storage engine. You also need to tell it the location of the key you want + * to load. + */ +$storageEngine = new \Bitpay\Storage\FilesystemStorage(); +$privateKey = $storageEngine->load('/tmp/bitpay.pri'); +$publicKey = $storageEngine->load('/tmp/bitpay.pub'); /** * Create a new client. You can see the example of how to configure this using @@ -22,7 +30,6 @@ require __DIR__ . '/../vendor/autoload.php'; $bitpay = new \Bitpay\Bitpay( array( 'bitpay' => array( - 'network' => 'testnet', // testnet or livenet, default is livenet 'public_key' => '/tmp/bitpay.pub', //see tutorial/001.php and 002.php 'private_key' => '/tmp/bitpay.pri', 'key_storage' => 'Bitpay\Storage\EncryptedFilesystemStorage', @@ -36,5 +43,12 @@ $bitpay = new \Bitpay\Bitpay( */ $client = $bitpay->get('client'); +$client->setPrivateKey($privateKey); +$client->setPublicKey($publicKey); +/** + * Add your btcpayserver url + */ +$client->setUri('https://btcpay.server/'); + $tokens = $client->getTokens(); print_r($tokens); diff --git a/examples/SetCurlOptions.php b/examples/SetCurlOptions.php index 3d773ea..4a0a741 100644 --- a/examples/SetCurlOptions.php +++ b/examples/SetCurlOptions.php @@ -5,9 +5,6 @@ require __DIR__ . '/../vendor/autoload.php'; -// When running bitpay on your local server -$network = new Bitpay\Network\Customnet("127.0.0.1", 8088, true); - // Customize the curl options $curl_options = array( CURLOPT_SSL_VERIFYPEER => false, diff --git a/examples/tutorial/002_pair.php b/examples/tutorial/002_pair.php index c5297ce..5cd31c8 100644 --- a/examples/tutorial/002_pair.php +++ b/examples/tutorial/002_pair.php @@ -28,15 +28,6 @@ $publicKey = $storageEngine->load('/tmp/bitpay.pub'); */ $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\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 @@ -49,7 +40,12 @@ $adapter = new \Bitpay\Client\Adapter\CurlAdapter(); */ $client->setPrivateKey($privateKey); $client->setPublicKey($publicKey); -$client->setNetwork($network); + +/** + * Add your btcpayserver url + */ +$client->setUri('https://btcpay.server/'); + $client->setAdapter($adapter); /** diff --git a/examples/tutorial/003_createInvoice.php b/examples/tutorial/003_createInvoice.php index d1539f6..c4b5d66 100644 --- a/examples/tutorial/003_createInvoice.php +++ b/examples/tutorial/003_createInvoice.php @@ -17,12 +17,10 @@ $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\Livenet(); $adapter = new \Bitpay\Client\Adapter\CurlAdapter(); $client->setPrivateKey($privateKey); $client->setPublicKey($publicKey); -$client->setNetwork($network); +$client->setUri('https://btcpay.server/'); $client->setAdapter($adapter); // --------------------------- diff --git a/examples/tutorial/004_HostedPaymentPage.php b/examples/tutorial/004_HostedPaymentPage.php index fc09605..96727df 100644 --- a/examples/tutorial/004_HostedPaymentPage.php +++ b/examples/tutorial/004_HostedPaymentPage.php @@ -19,11 +19,10 @@ $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(); $adapter = new \Bitpay\Client\Adapter\CurlAdapter(); $client->setPrivateKey($privateKey); $client->setPublicKey($publicKey); -$client->setNetwork($network); +$client->setUri('https://btcpay.server/'); $client->setAdapter($adapter); // --------------------------- diff --git a/examples/tutorial/IPNlogger.php b/examples/tutorial/IPNlogger.php index 623f43c..ce7d76c 100644 --- a/examples/tutorial/IPNlogger.php +++ b/examples/tutorial/IPNlogger.php @@ -44,10 +44,8 @@ if (true === empty($ipn -> id)) { // This is needed, since the IPN does not contain any authentication $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->setUri('https://btcpay.server/'); $client->setAdapter($adapter); $token = new \Bitpay\Token(); @@ -69,4 +67,3 @@ fwrite($myfile, "Raw IPN: ". $raw_post_data."\n"); //Respond with HTTP 200, so BitPay knows the IPN has been received correctly //If BitPay receives <> HTTP 200, then BitPay will try to send the IPN again with increasing intervals for two more hours. header("HTTP/1.1 200 OK"); -?> \ No newline at end of file diff --git a/examples/tutorial/getInvoice.php b/examples/tutorial/getInvoice.php index 834cb73..b7767f6 100644 --- a/examples/tutorial/getInvoice.php +++ b/examples/tutorial/getInvoice.php @@ -16,10 +16,8 @@ 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->setUri('https://btcpay.server/'); $client->setAdapter($adapter); $token = new \Bitpay\Token(); @@ -38,5 +36,3 @@ echo (string) $request.PHP_EOL.PHP_EOL.PHP_EOL; echo (string) $response.PHP_EOL.PHP_EOL; print_r($invoice); - -?> \ No newline at end of file