diff --git a/CHANGELOG.md b/CHANGELOG.md index 52f163a0..f62f2950 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ChangeLog ========= +1.6.1 +------------------- +Added custom headers 1.6.0 ------------------- diff --git a/README.md b/README.md index 58c9c5ec..e311a118 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Hyperwallet REST SDK (Beta) =========================== A library to manage users, transfer methods and payments through the Hyperwallet Rest V3 API -For Rest V4 APIs, please use SDK v2.1.0 +For Rest V4 APIs, please use SDK v2.x.x Prerequisites ------------ diff --git a/src/Hyperwallet/Hyperwallet.php b/src/Hyperwallet/Hyperwallet.php index 67c785f6..aaf644c6 100644 --- a/src/Hyperwallet/Hyperwallet.php +++ b/src/Hyperwallet/Hyperwallet.php @@ -68,13 +68,13 @@ class Hyperwallet { * * @throws HyperwalletArgumentException */ - public function __construct($username, $password, $programToken = null, $server = 'https://api.sandbox.hyperwallet.com', $encryptionData = array()) { + public function __construct($username, $password, $programToken = null, $server = 'https://api.sandbox.hyperwallet.com', $encryptionData = array(), $clientOptions = array()) { if (empty($username) || empty($password)) { throw new HyperwalletArgumentException('You need to specify your API username and password!'); } $this->programToken = $programToken; - $this->client = new ApiClient($username, $password, $server, array(), $encryptionData); + $this->client = new ApiClient($username, $password, $server, $clientOptions, $encryptionData); } //-------------------------------------- diff --git a/src/Hyperwallet/Util/ApiClient.php b/src/Hyperwallet/Util/ApiClient.php index 1bbf326a..2580daef 100644 --- a/src/Hyperwallet/Util/ApiClient.php +++ b/src/Hyperwallet/Util/ApiClient.php @@ -9,6 +9,7 @@ use Hyperwallet\Model\BaseModel; use Hyperwallet\Response\ErrorResponse; use Hyperwallet\Util\HyperwalletEncryption; +use Hyperwallet\Util\HyperwalletUUID; /** * The internal API client @@ -22,7 +23,7 @@ class ApiClient { * * @var string */ - const VERSION = '1.6.0'; + const VERSION = '1.6.1'; /** * The Guzzle http client @@ -38,6 +39,13 @@ class ApiClient { */ private $encryption; + /** + * The UUID generator for http request/response + * + * @var HyperwalletUUID + */ + private $uuid; + /** * Boolean flag that checks if ApiClient is constructed with encryption enabled or not * @@ -55,14 +63,17 @@ class ApiClient { * @param array $encryptionData Encryption data to initialize ApiClient with encryption enabled */ public function __construct($username, $password, $server, $clientOptions = array(), $encryptionData = array()) { + $this->uuid = HyperwalletUUID::v4(); // Setup http client if not specified $this->client = new Client(array_merge_recursive(array( 'base_uri' => $server, 'auth' => array($username, $password), 'headers' => array( 'User-Agent' => 'Hyperwallet PHP SDK v' . self::VERSION, - 'Accept' => 'application/json' - ) + 'Accept' => 'application/json', + 'x-sdk-version' => self::VERSION, + 'x-sdk-type' => 'PHP', + 'x-sdk-contextId' => $this->uuid) ), $clientOptions)); if (!empty($encryptionData) && isset($encryptionData['clientPrivateKeySetLocation']) && isset($encryptionData['hyperwalletKeySetLocation'])) { diff --git a/src/Hyperwallet/Util/HyperwalletUUID.php b/src/Hyperwallet/Util/HyperwalletUUID.php new file mode 100644 index 00000000..8c803c7f --- /dev/null +++ b/src/Hyperwallet/Util/HyperwalletUUID.php @@ -0,0 +1,57 @@ +container[0]['request']; $this->assertEquals($method, $request->getMethod()); - $this->assertCount(($hasContentType ? 6 : 4) + count($headers), $request->getHeaders()); + $this->assertCount(($hasContentType ? 9 : 7) + count($headers), $request->getHeaders()); $this->assertArrayHasKeyAndValue('Accept', $isEncrypted ? 'application/jose+json' : 'application/json', $request->getHeaders()); if ($hasContentType) { $this->assertArrayHasKeyAndValue('Content-Type', $isEncrypted ? 'application/jose+json' : 'application/json', $request->getHeaders()); diff --git a/tests/Hyperwallet/Tests/Util/HyperwalletEncryptionTest.php b/tests/Hyperwallet/Tests/Util/HyperwalletEncryptionTest.php index 98b7ef06..e491cd8e 100644 --- a/tests/Hyperwallet/Tests/Util/HyperwalletEncryptionTest.php +++ b/tests/Hyperwallet/Tests/Util/HyperwalletEncryptionTest.php @@ -1,5 +1,5 @@ v4(); + $uuid2 = $UUIDUtility->v4(); + $uuid3 = $UUIDUtility->v4(); + + // Validate result + $this->assertNotEquals($uuid1, $uuid2); + $this->assertNotEquals($uuid2, $uuid3); + $this->assertNotEquals($uuid3, $uuid1); + } +} \ No newline at end of file