diff --git a/examples/Account.php b/examples/Account.php index d5d0ae3..8f729be 100644 --- a/examples/Account.php +++ b/examples/Account.php @@ -5,7 +5,7 @@ use Uphold\UpholdClient as Client; // Initialize the client. -$client = new Client(); +$client = new Client(array('sandbox' => true)); // Get user. $user = $client->getUser('AUTHORIZATION_TOKEN'); diff --git a/examples/Card.php b/examples/Card.php index 51c91a2..b9ebce2 100644 --- a/examples/Card.php +++ b/examples/Card.php @@ -5,7 +5,7 @@ use Uphold\UpholdClient as Client; // Initialize the client. -$client = new Client(); +$client = new Client(array('sandbox' => true)); // Get user. $user = $client->getUser('AUTHORIZATION_TOKEN'); diff --git a/examples/Reserve.php b/examples/Reserve.php index 992c509..f34d716 100644 --- a/examples/Reserve.php +++ b/examples/Reserve.php @@ -5,7 +5,7 @@ use \Uphold\UpholdClient as Client; // Initialize the client. -$client = new Client(); +$client = new Client(array('sandbox' => true)); // Get the reserve summary of all the obligations and assets within it (public endpoint). $statistics = $client->getReserve()->getStatistics(); diff --git a/examples/Ticker.php b/examples/Ticker.php index 959f4ab..ec4a3fa 100644 --- a/examples/Ticker.php +++ b/examples/Ticker.php @@ -5,7 +5,7 @@ use Uphold\UpholdClient as Client; // Initialize the client. -$client = new Client(); +$client = new Client(array('sandbox' => true)); // Get rates (public endpoint). $rates = $client->getRates(); diff --git a/examples/Transaction.php b/examples/Transaction.php index 3aecdfa..e182176 100644 --- a/examples/Transaction.php +++ b/examples/Transaction.php @@ -5,7 +5,7 @@ use Uphold\UpholdClient as Client; // Initialize the client. -$client = new Client(); +$client = new Client(array('sandbox' => true)); // Get user. $user = $client->getUser('AUTHORIZATION_TOKEN'); diff --git a/examples/User.php b/examples/User.php index 79426fa..69b1c40 100644 --- a/examples/User.php +++ b/examples/User.php @@ -5,7 +5,7 @@ use Uphold\UpholdClient as Client; // Initialize the client. -$client = new Client(); +$client = new Client(array('sandbox' => true)); // Get user. $user = $client->getUser('AUTHORIZATION_TOKEN'); diff --git a/lib/Uphold/Command/CreateTokenCommand.php b/lib/Uphold/Command/CreateTokenCommand.php index 70ddf72..4194ad7 100644 --- a/lib/Uphold/Command/CreateTokenCommand.php +++ b/lib/Uphold/Command/CreateTokenCommand.php @@ -2,15 +2,16 @@ namespace Uphold\Command; -use Uphold\UpholdClient; -use Uphold\Exception\AuthenticationRequiredException; -use Uphold\Exception\BadRequestException; -use Uphold\Exception\TwoFactorAuthenticationRequiredException; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Formatter\OutputFormatterStyle; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Process\Process; +use Uphold\Exception\AuthenticationRequiredException; +use Uphold\Exception\BadRequestException; +use Uphold\Exception\TwoFactorAuthenticationRequiredException; +use Uphold\UpholdClient; /** * Command to create a new Personal Access Token @@ -22,8 +23,16 @@ class CreateTokenCommand extends Command */ protected function configure() { - $this->setName('tokens:create') - ->setDescription('Create a new Personal Access Token'); + $this + ->setName('tokens:create') + ->setDescription('Create a new Personal Access Token') + ->addOption( + 'sandbox', + null, + InputOption::VALUE_NONE, + 'If set, the request will be made to Uphold\'s sandbox API' + ) + ; } /** @@ -40,7 +49,7 @@ protected function initialize(InputInterface $input, OutputInterface $output) $this->output = $output; // Uphold client. - $this->client = new UpholdClient(); + $this->client = new UpholdClient(array('sandbox' => $input->getOption('sandbox'))); // Input variables. $this->description = null; diff --git a/lib/Uphold/UpholdClient.php b/lib/Uphold/UpholdClient.php index 18f6a06..fbbf9c9 100644 --- a/lib/Uphold/UpholdClient.php +++ b/lib/Uphold/UpholdClient.php @@ -17,6 +17,12 @@ */ class UpholdClient { + /** + * Uphold API urls. + */ + const UPHOLD_API_URL = 'https://api.uphold.com'; + const UPHOLD_SANDBOX_API_URL = 'https://api-sandbox.uphold.com'; + /** * Guzzle instance used to communicate with Uphold. * @@ -36,8 +42,8 @@ class UpholdClient */ private $options = array( 'api_version' => 'v0', - 'base_url' => 'https://api.uphold.com/', 'debug' => false, + 'sandbox' => false, 'timeout' => 10, 'user_agent' => 'uphold-sdk-php {version} (https://github.com/seegno/uphold-sdk-php)', 'version' => '4.2.0', @@ -50,6 +56,10 @@ class UpholdClient */ public function __construct(array $options = array()) { + if (!isset($options['base_url'])) { + $options['base_url'] = isset($options['sandbox']) && $options['sandbox'] ? self::UPHOLD_SANDBOX_API_URL : self::UPHOLD_API_URL; + } + $this->options = array_merge($this->options, $options); $this->setHttpClient(new HttpClient($this->options)); diff --git a/test/Uphold/Tests/Functional/ReserveTest.php b/test/Uphold/Tests/Functional/ReserveTest.php index 40572e2..b481325 100644 --- a/test/Uphold/Tests/Functional/ReserveTest.php +++ b/test/Uphold/Tests/Functional/ReserveTest.php @@ -28,7 +28,7 @@ public function shouldReturnTransactions() */ public function shouldReturnOneTransactions() { - $exampleTransactionId = '66fc2a0d-a933-45f0-ba27-8cf12870fcce'; + $exampleTransactionId = 'af3ef9a7-9262-4022-b376-7b4d928f7206'; $transaction = $this->client->getReserve()->getTransactionById($exampleTransactionId); diff --git a/test/Uphold/Tests/Functional/TestCase.php b/test/Uphold/Tests/Functional/TestCase.php index 7db2dd4..b897a45 100644 --- a/test/Uphold/Tests/Functional/TestCase.php +++ b/test/Uphold/Tests/Functional/TestCase.php @@ -18,7 +18,7 @@ class TestCase extends \PHPUnit_Framework_TestCase */ public function setUp() { - $client = new UpholdClient(); + $client = new UpholdClient(array('sandbox' => true)); $this->client = $client; }