Skip to content
This repository has been archived by the owner on Sep 30, 2020. It is now read-only.

Commit

Permalink
Allow changing spreedly base url in config (#31)
Browse files Browse the repository at this point in the history
enhance readme, add package.json for installing and running tests
  • Loading branch information
lasergoat authored and tuurbo committed Sep 27, 2019
1 parent c253b3c commit 73b73a9
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 6 deletions.
22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
29 changes: 24 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
@@ -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
```
Expand All @@ -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 [

Expand Down Expand Up @@ -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()`.
23 changes: 23 additions & 0 deletions spec/Tuurbo/Spreedly/ClientSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 73b73a9

Please sign in to comment.