diff --git a/package.json b/package.json new file mode 100644 index 0000000..67f2869 --- /dev/null +++ b/package.json @@ -0,0 +1,22 @@ +{ + "name": "spreedly", + "description": "A simple php sdk for Spreedly.com's API.", + "directories": { + "doc": "docs" + }, + "scripts": { + "test": "vendor/bin/phpspec run", + "install": "composer install" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/tuurbo/spreedly.git" + }, + "keywords": [], + "author": "https://github.com/tuurbo", + "license": "MIT", + "bugs": { + "url": "https://github.com/tuurbo/spreedly/issues" + }, + "homepage": "https://github.com/tuurbo/spreedly#readme" +} \ No newline at end of file diff --git a/readme.md b/readme.md index 8f7875c..1f0de57 100644 --- a/readme.md +++ b/readme.md @@ -1,10 +1,11 @@ -**[changelog](#changelog) !! As of the 2.0 release the amount must be an integer as required by Spreedly. E.g., 1098 for $10.98 !!** +**[changelog](#changelog) !! As of the 2.0 release the amount must be an integer as required by Spreedly. E.g., 1098 for \$10.98 !!** # Getting Started ## Setup/Install Install through Composer. + ``` composer require tuurbo/spreedly ``` @@ -28,6 +29,7 @@ Next, update app/config/app.php to include a reference to this package's service [Login](https://spreedly.com) to your Spreedly account to retrieve your api credentials. You can set your default gateway once you've created your first gateway. Add to app/config/services.php config file. + ```php return [ @@ -136,24 +138,41 @@ Spreedly::transaction()->capture(); Spreedly::transaction()->complete(); ``` +## Development + +Clone the repo and run `npm install`. This will `composer install`. + +**Testing** + +Tests are in the spec directory. They are written with [phpspec](https://www.phpspec.net/en/stable/). + +To run your tests, simply do `npm test`. If you don't want to use npm, that's fine, simply run `vendor/bin/phpspec run` + +Please ensure you have added proper test coverage for each Pull Request. + ## Changelog ### 2.4+ + See releases page https://github.com/tuurbo/spreedly/releases ### 2.3 + - added support for laravel 5.4 ### 2.2 + - added ability to merge configs. ### 2.1 + - changed default timeout from 15 seconds to 64 seconds as recommended by Spreedly. -- added timeout method to change timeout per api call. E.g., ```Spreedly::timeout(25)->payment()->purchase()```. -- added new ```Tuurbo\Spreedly\Exceptions\TimeoutException``` for catching timeouts. +- added timeout method to change timeout per api call. E.g., `Spreedly::timeout(25)->payment()->purchase()`. +- added new `Tuurbo\Spreedly\Exceptions\TimeoutException` for catching timeouts. ### 2.0 + - amount is no longer converted to cents. - - the amount must be an integer as required by Spreedly. E.g., 1098 for $10.98 + - the amount must be an integer as required by Spreedly. E.g., 1098 for \$10.98 - switched from Spreedly xml api to json api. -- renamed ```->declined()``` method to ```->message()```. +- renamed `->declined()` method to `->message()`. diff --git a/spec/Tuurbo/Spreedly/ClientSpec.php b/spec/Tuurbo/Spreedly/ClientSpec.php index b5dd8c4..7dba178 100644 --- a/spec/Tuurbo/Spreedly/ClientSpec.php +++ b/spec/Tuurbo/Spreedly/ClientSpec.php @@ -147,6 +147,29 @@ public function it_throws_an_exception_if_the_config_is_invalid($client) $this->shouldThrow('Exception') ->duringGet(self::END_POINT); } + + public function it_should_allow_overriding_the_base_url($client) + { + // for this test, reconstruct the client with the new base url + $overrideBaseUrl = 'https://otherdomain.com/'; + + $config = [ + 'key' => '12345', + 'secret' => '67890', + 'baseUrl' => $overrideBaseUrl + ]; + + $this->beConstructedWith($client, $config); + + // check that client really did use the overriden base url + $client->post($overrideBaseUrl.self::END_POINT, Argument::type('array')) + ->shouldBeCalled() + ->willReturn(new ClientStub200()); + + $this->post(self::END_POINT) + ->success() + ->shouldReturn(true); + } } class ClientStub200 extends GuzzleResponse diff --git a/src/Client.php b/src/Client.php index c418de2..b1bd286 100644 --- a/src/Client.php +++ b/src/Client.php @@ -26,6 +26,11 @@ class Client */ public function __construct(GuzzleInterface $client, $config) { + // allow overriding BASE_URL + if (!isset($config['baseUrl'])) { + $config['baseUrl'] = self::BASE_URL; + } + $this->client = $client; $this->config = $config; } @@ -57,7 +62,9 @@ public function put($url, array $data = null) protected function request($url, $method, array $data = null) { try { - $response = $this->client->{$method}(self::BASE_URL.$url, $this->buildData($data)); + $baseUrl = $this->config['baseUrl']; + + $response = $this->client->{$method}($baseUrl.$url, $this->buildData($data)); if (!in_array($response->getStatusCode(), [200, 201])) { $contentType = $response->getHeader('Content-Type');