Skip to content

Commit

Permalink
Merge pull request #68 from voucherifyio/aw/YWxp9cWJ/unify-set-endpoint
Browse files Browse the repository at this point in the history
Unify setEndpoint in SDKs
  • Loading branch information
mandraszyk authored Jul 19, 2019
2 parents 91dbdec + eae1312 commit 8cb3b42
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ $client = new VoucherifyClient($apiID, $apiKey, $apiVersion);
Check [versioning](https://docs.voucherify.io/reference?utm_source=github&utm_medium=sdk&utm_campaign=acq#versioning).

### Custom API URL
By default client is sending request to `https://api.voucherify.io/v1`. You can override default api url while creating client instance.
By default client is sending request to `https://api.voucherify.io`. You can override `$apiUrl` while creating client instance if you want to use Voucherify running in a specific region

```php
$apiVersion = null;
$apiUrl = "https://custom-api-url";
$apiUrl = "https://<region>.api.voucherify.io";

$client = new VoucherifyClient($apiID, $apiKey, $apiVersion, $apiUrl);
```
Expand Down Expand Up @@ -703,6 +703,7 @@ class Voucher extends CI_Controller {
Bug reports and pull requests are welcome through [GitHub Issues](https://github.com/rspective/voucherify-php-sdk/issues).

### Changelog
- **2019-07-19** - `2.0.0` - Hide API versioning in `$apiUrl` param
- **2018-12-28** - `1.7.10` - Add Validation Rule Assignments
- **2018-03-18** - `1.7.9` - Add Utils with verifyWebhookSignature method
- **2018-02-18** - `1.7.8` - Product delete force option support
Expand Down
4 changes: 2 additions & 2 deletions src/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ApiClient
/**
* @var string
*/
private $basePath = "https://api.voucherify.io/v1";
private $basePath = "https://api.voucherify.io";

/**
* @var string
Expand Down Expand Up @@ -103,7 +103,7 @@ private function request($method, $endpoint, $params, $body)
$setBody = $body && in_array($method, ["POST", "PUT", "DELETE"]);

$method = strtoupper($method);
$url = $this->basePath . $endpoint . ($setParams ? "?" . $this->encodeParams($params) : "");
$url = $this->basePath . "/v1" . $endpoint . ($setParams ? "?" . $this->encodeParams($params) : "");

$options = array();
$options[CURLOPT_URL] = $url;
Expand Down
16 changes: 8 additions & 8 deletions test/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use Voucherify\VoucherifyClient;
use Voucherify\ClientException;

class ClientTest extends PHPUnit_Framework_TestCase
{
class ClientTest extends PHPUnit_Framework_TestCase
{
protected static $headers;
protected static $apiId;
protected static $apiKey;
Expand Down Expand Up @@ -61,17 +61,17 @@ public function testCustomApiUrl()
->reply(200, [ "status" => "ok" ]);

$client = new VoucherifyClient(self::$apiId, self::$apiKey);

$result = $client->vouchers->get("test-voucher-1");
$this->assertEquals($result, (object)[ "status" => "ok" ]);

CurlMock::register("https://custom-api.voucherify.io/v1", $headers)
->get("/vouchers/test-voucher-2")
->reply(200, [ "status" => "ok" ]);

$customUrl = "https://custom-api.voucherify.io/v1";
$customUrl = "https://custom-api.voucherify.io";
$client = new VoucherifyClient(self::$apiId, self::$apiKey, null, $customUrl);

$result = $client->vouchers->get("test-voucher-2");
$this->assertEquals($result, (object)[ "status" => "ok" ]);

Expand All @@ -92,7 +92,7 @@ public function testVersioning()
->reply(200, [ "status" => "ok" ]);

$client = new VoucherifyClient(self::$apiId, self::$apiKey);

$result = $client->vouchers->get("test-voucher-1");
$this->assertEquals($result, (object)[ "status" => "ok" ]);

Expand All @@ -109,13 +109,13 @@ public function testVersioning()
->reply(200, [ "status" => "ok" ]);

$client = new VoucherifyClient(self::$apiId, self::$apiKey, "v2017-04-05");

$result = $client->vouchers->get("test-voucher-2");
$this->assertEquals($result, (object)[ "status" => "ok" ]);

CurlMock::done();
}

public function testErrorHandling()
{
CurlMock::register("https://api.voucherify.io/v1", self::$headers)
Expand Down
2 changes: 1 addition & 1 deletion test/UtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function testVerifyWebhookSignature()
// /////////////////////////////////////// UNHAPPY PATH (INVALID SIGNATURE)

$signature = "invalid_signature";
$data = "Example test message";
$message = "Example test message";
$secretKey = "secret_01234567890_secret";

$result = Utils::verifyWebhookSignature($signature, $message, $secretKey);
Expand Down

0 comments on commit 8cb3b42

Please sign in to comment.