Skip to content

Commit

Permalink
Add EU support
Browse files Browse the repository at this point in the history
Test against 8.2
  • Loading branch information
nickdnk committed Sep 7, 2022
1 parent 1fcfc83 commit 940602b
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Expand Up @@ -5,7 +5,7 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
php: [ '7.1', '7.2', '7.3', '7.4', '8.0', '8.1' ]
php: [ '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
steps:
- uses: actions/checkout@v2
- run: mkdir -p build/logs
Expand Down
25 changes: 22 additions & 3 deletions CHANGELOG.md
@@ -1,39 +1,58 @@
# Changelog

## 3.3.0 - 2022-09-07

* Added support for EU-only mode: https://gatewayapi.com/blog/new-eu-setup-for-gatewayapi-customers/ - pass `true` to
the optional constructor argument and to `getPries()` to use the EU-only mode.
* Test against PHP 8.2

## 3.2.0 - 2022-02-27

* Added support for version `0.6.*` of `guzzlehttp/oauth-subscriber`.
* Switched to GitHub actions instead of Travis.

## 3.1.2 - 2021-05-10

* Added compatibility with Guzzle 7.
* Adjustments to tests and nullability.

## 3.1.1 - 2021-05-09

* Fixed use of incorrect Guzzle exception for detecting connection error vs. HTTP error.

## 3.1.0 - 2021-04-01

* Support for PHP 8.0.

## 3.0.1 - 2020-10-01

* Added the `callback_url` parameter to `SMSMessage`. Thanks to @Matthew-Kilpatrick.
* Fixed some minor nullability and phpdoc inconsistencies.

## 3.0 - 2020-04-30

* Refactored `Constructable` into a trait.
* [BC] `Webhook` constructor is now `protected` and the subclass constructors are `final`. If you implement this class like it was meant to (using the static constructors) you won't need to make any changes to your code.
* [BC] `Webhook` constructor is now `protected` and the subclass constructors are `final`. If you implement this class
like it was meant to (using the static constructors) you won't need to make any changes to your code.

## 2.0.1 - 2020-03-10

* Added `setRecipients()` to `SMSMessage`.

## 2.0 - 2020-03-05

* [BC] Restructured namespaces for entity- and webhook-classes.
* [BC] Removed `PastSendTimeException` and its handling as the API has changed so it no longer works.
* Added `SuccessfulResponseParsingException`. You should check for this if you implement automatic retries of failed requests.
* Added `SuccessfulResponseParsingException`. You should check for this if you implement automatic retries of failed
requests.
* Made `BaseException` abstract.
* Added `Prices` entity for price response.
* Added Coveralls and Travis as well as more tests.

## 1.1 - 2020-03-03
* Added more exceptions; `GatewayServerException` and `GatewayRequestException`. These allow you to distinguish between actual server errors and 400-range client/library errors. Backwards-compatibility is maintained as these extend `BaseException`.

* Added more exceptions; `GatewayServerException` and `GatewayRequestException`. These allow you to distinguish between
actual server errors and 400-range client/library errors. Backwards-compatibility is maintained as these
extend `BaseException`.
* Added proper handling of `json_decode()`-errors using `json_last_error()` instead of falsy-checks.
* Cleaned up response parsing and added more tests.
6 changes: 4 additions & 2 deletions readme.md
Expand Up @@ -15,7 +15,7 @@ Once you have that you need to generate an API key/secret pair under **API** ->

To include this in your project, install it using Composer.

This library requires PHP >= 7.1 and works on 8.0 and 8.1.
This library requires PHP >= 7.1 and works on 8.0, 8.1 and 8.2.

`composer require nickdnk/gatewayapi-php`

Expand All @@ -28,7 +28,9 @@ use nickdnk\GatewayAPI\GatewayAPIHandler;
use nickdnk\GatewayAPI\Entities\Request\Recipient;
use nickdnk\GatewayAPI\Entities\Request\SMSMessage;

$handler = new GatewayAPIHandler('my_key', 'my_secret');
// Pass `true` as the third parameter to use GatewayAPI in EU-only mode.
// This requires an EU account. See https://gatewayapi.com/blog/new-eu-setup-for-gatewayapi-customers/.
$handler = new GatewayAPIHandler('my_key', 'my_secret', false);

$message1 = new SMSMessage(

Expand Down
13 changes: 8 additions & 5 deletions src/GatewayAPIHandler.php
Expand Up @@ -35,17 +35,20 @@
class GatewayAPIHandler
{

private const DOMAIN_ROOT = 'https://gatewayapi.com';
private const DOMAIN_ROOT_COM = 'https://gatewayapi.com';
private const DOMAIN_ROOT_EU = 'https://gatewayapi.eu';

private $client;

/**
* Obtain a key and secret from the website. This is a prerequisite for sending SMS.
* Pass `true` to `$euMode` to use the EU-only setup.
*
* @param string $key
* @param string $secret
* @param bool $euMode
*/
public function __construct(string $key, string $secret)
public function __construct(string $key, string $secret, bool $euMode = false)
{

$stack = HandlerStack::create();
Expand All @@ -61,7 +64,7 @@ public function __construct(string $key, string $secret)
);
$this->client = new Client(
[
'base_uri' => self::DOMAIN_ROOT,
'base_uri' => $euMode ? self::DOMAIN_ROOT_EU : self::DOMAIN_ROOT_COM,
'handler' => $stack,
RequestOptions::AUTH => 'oauth',
RequestOptions::CONNECT_TIMEOUT => 15,
Expand Down Expand Up @@ -196,14 +199,14 @@ public function getCreditStatus(): AccountBalance
* @throws ConnectionException
* @throws GatewayRequestException
*/
public static function getPricesAsJSON(): Prices
public static function getPricesAsJSON(bool $euMode = false): Prices
{

try {

return Prices::constructFromResponse(
(new Client())->get(
self::DOMAIN_ROOT . '/api/prices/list/sms/json',
($euMode ? self::DOMAIN_ROOT_EU : self::DOMAIN_ROOT_COM) . '/api/prices/list/sms/json',
[
RequestOptions::CONNECT_TIMEOUT => 15,
RequestOptions::TIMEOUT => 30
Expand Down
13 changes: 12 additions & 1 deletion tests/GatewayAPIHandlerTest.php
Expand Up @@ -19,6 +19,7 @@ class GatewayAPIHandlerTest extends TestCase
{

// Replace these with your own key, secret and phone number to run this test. It will cost you 1 SMS per test run.
// Pass `true` in `setUp` below to test against the EU-only configuration.
private const TEST_KEY = '';
private const TEST_SECRET = '';
private const TEST_NUMBER = 4588888888;
Expand All @@ -29,7 +30,7 @@ protected function setUp(): void
{

$this->handler = new GatewayAPIHandler(
self::TEST_KEY, self::TEST_SECRET
self::TEST_KEY, self::TEST_SECRET, false
);
}

Expand Down Expand Up @@ -152,4 +153,14 @@ public function testGetPrices()
$this->assertInstanceOf(Prices::class, $prices);

}

public function testGetPricesEu()
{

/** @noinspection PhpUnhandledExceptionInspection */
$prices = GatewayAPIHandler::getPricesAsJSON(true);

$this->assertInstanceOf(Prices::class, $prices);

}
}

0 comments on commit 940602b

Please sign in to comment.