From 0cb2f1a580b34d3ada15ab50180f50e2852875f1 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 12 Nov 2020 13:09:26 +1100 Subject: [PATCH 1/6] Backporting changes merged to v4, also in v3 --- src/Hyperwallet/Hyperwallet.php | 4 ++-- .../Hyperwallet/Tests/Util/HyperwalletEncryptionTest.php | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Hyperwallet/Hyperwallet.php b/src/Hyperwallet/Hyperwallet.php index f1063a13..d0ba080f 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/tests/Hyperwallet/Tests/Util/HyperwalletEncryptionTest.php b/tests/Hyperwallet/Tests/Util/HyperwalletEncryptionTest.php index 4c185537..fbaad8a2 100644 --- a/tests/Hyperwallet/Tests/Util/HyperwalletEncryptionTest.php +++ b/tests/Hyperwallet/Tests/Util/HyperwalletEncryptionTest.php @@ -1,5 +1,5 @@ decrypt($encryptedMessage); $this->fail('Exception expected'); } catch (\Exception $e) { - $this->assertEquals('Decryption error', $e->getMessage()); - } + $this->assertThat($e->getMessage(), $this->logicalOr( + $this->equalTo('Decryption error'), + $this->equalTo('Ciphertext representative out of range') + )); } } public function testShouldFailSignatureVerificationWhenWrongPublicKeyIsUsed() { From 7c4525a8c557373041be776cc6e437f4be0bccd5 Mon Sep 17 00:00:00 2001 From: Rajendran Rathinasabapathy Date: Tue, 17 Nov 2020 21:24:20 +0530 Subject: [PATCH 2/6] Added changes for addition of custom headers --- .DS_Store | Bin 0 -> 8196 bytes src/Hyperwallet/Util/ApiClient.php | 18 +++++- src/Hyperwallet/Util/HyperwalletUUID.php | 57 ++++++++++++++++++ tests/Hyperwallet/Tests/HyperwalletTest.php | 28 ++++++++- .../Hyperwallet/Tests/Util/ApiClientTest.php | 2 +- 5 files changed, 99 insertions(+), 6 deletions(-) create mode 100644 .DS_Store create mode 100644 src/Hyperwallet/Util/HyperwalletUUID.php diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..dd9b8311795289521d65a2ef1ab3b8deec880a95 GIT binary patch literal 8196 zcmeHMTWl0n82-Puv~vQ;DRSv7mac4|6vgu1&k(23L8vNO8{ zd|4BXFJi=KOf)euydmG@8P0dcI?^Fe8DYEd+cegY90|9dgdv{#an24peW#FBF5m zFmTM_TxFY-D^>pBOyCqe|EOK`8HIRb+3MyEo9^x0_TcW!)#Z1rkc}&am~brH3!D>< zT^yNptYB(9>*sCHa=eqHWyg1Nu08B!r|rht--NijW^L1QGhyB}=USLz$doZw$~mV> zPH-liV||M$j#<3&!v#ytV#&7+5qeTBrunGy^c8JxEyD=St!<_l_W3DfHVSO-5Muao z$Fro*OHd2%+A7QuH=DCvX$hUyy*=5aOi zp{ySa&e$HW>SLZhe7Y91-!R6Nx7V_GRjG8F-tUlxRJv1-q+xKR>)g93)|u#I)A8KQVzDOn_3zL8BVxU_Oe^%xRjb#h+B&vw-`RU( zCl~D9ts)AQqool_W=;~}=FQWg+HEtjPBd53@(3%=K5Z!3$OavqOl&Y%DKeCbnb??U zHCWEFCiIHU369JfvQ`Ig5nTq$Q!dfo`$e~40n0k=-647m)~T%5-d!Rs)K5&39&b!! zgdtH)eO0yhI$fkI^dWu1n){lr)A#fv{SHDsWT>|U)}a}j(29Go8SU7HZdTq7^dN)1 z=*NCm-w=jz6r&ht_2onLP2m)Z2vA}bR`4Wi@M$~~sqjU-gx7Fkf#wG0)TR-aZfdSP zRP@|}cakl03Y{Muk75S?Lky_1pG%Xv|L?8-{XYzfo0x%^f&V81sLKpx_VBY+JJr-( zJIVDiuBxcGipDU7n|U7sczoj@hTKnbsLDx4SkcH9E`R%nfcX3md5@dhn}I(8Z*g-^ literal 0 HcmV?d00001 diff --git a/src/Hyperwallet/Util/ApiClient.php b/src/Hyperwallet/Util/ApiClient.php index 1bbf326a..f6010f96 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.7.0'; /** * 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,18 @@ 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( + 'verify'=>false, '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 @@ +doGet('/rest/v3/users/{user-token}/transfer-methods', array('user-token' => 'test-user-token'), array('type'=>TransferMethod::TYPE_PREPAID_CARD)); } + + private $includeIntegrationTest = true; //change this value to true if integration tests have to be run + + /*Following are the methods for integration testing. Please change $includeIntegrationTest to True if you want + *the following test cases + */ + + public function testGetUserSampleIT() { + $username = "selrestuser@1861681"; + $password = "Password1!"; + $programToken = "prg-eedaf875-01f1-4524-8b94-d4936255af78"; + $server = "https://localhost-hyperwallet.aws.paylution.net:8181"; + $userToken = "usr-f49967a9-9b7f-4cfc-9fc7-037d736711ba"; + $hyperwallet = new \Hyperwallet\Hyperwallet($username, $password, $programToken, $server); + try { + if (!$this->includeIntegrationTest) { + $this->markTestSkipped('This test is skipped.'); + } + $user = $hyperwallet->getUser($userToken); + var_dump('User details', $user); + echo "Got the user successfully"; + } catch (\Hyperwallet\Exception\HyperwalletException $e) { + echo $e->getMessage(); + die("\n"); + } + } } diff --git a/tests/Hyperwallet/Tests/Util/ApiClientTest.php b/tests/Hyperwallet/Tests/Util/ApiClientTest.php index 20c6a046..54ba6b61 100644 --- a/tests/Hyperwallet/Tests/Util/ApiClientTest.php +++ b/tests/Hyperwallet/Tests/Util/ApiClientTest.php @@ -929,7 +929,7 @@ private function validateRequest($method, $path, $query, array $body, $hasConten $request = $this->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()); From 604dbee268bc5feb594cf64bda28971ad232cb99 Mon Sep 17 00:00:00 2001 From: Rajendran Rathinasabapathy Date: Tue, 17 Nov 2020 21:47:24 +0530 Subject: [PATCH 3/6] Added test cases after changes for adding custom headers --- tests/Hyperwallet/Tests/HyperwalletTest.php | 47 ++++++++++++++++++- .../Tests/Util/HyperwalletUUIDTest.php | 23 +++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 tests/Hyperwallet/Tests/Util/HyperwalletUUIDTest.php diff --git a/tests/Hyperwallet/Tests/HyperwalletTest.php b/tests/Hyperwallet/Tests/HyperwalletTest.php index 9344d3fd..494d6add 100644 --- a/tests/Hyperwallet/Tests/HyperwalletTest.php +++ b/tests/Hyperwallet/Tests/HyperwalletTest.php @@ -4718,7 +4718,7 @@ public function testListTransferMethods_withParameters() { /*Following are the methods for integration testing. Please change $includeIntegrationTest to True if you want *the following test cases */ - +/* public function testGetUserSampleIT() { $username = "selrestuser@1861681"; $password = "Password1!"; @@ -4738,4 +4738,49 @@ public function testGetUserSampleIT() { die("\n"); } } +*/ + public function testCreateUser_successfulIT() { + $username = "selrestuser@1861681"; + $password = "Password1!"; + $programToken = "prg-eedaf875-01f1-4524-8b94-d4936255af78"; + $server = "https://localhost-hyperwallet.aws.paylution.net:8181"; + $userToken = "usr-f49967a9-9b7f-4cfc-9fc7-037d736711ba"; + + $hyperwallet = new \Hyperwallet\Hyperwallet($username, $password, $programToken, $server); + $user = $hyperwallet->getUser($userToken); + var_dump('User details', $user); + + $user = new User(array( "clientUserId"=> "user1877253", + "email"=> "user1877253@sink.sendgrid.net", + "profileType"=> "INDIVIDUAL", + "firstName"=> "Stan", + "middleName"=> "QA", + "lastName"=> "Fung", + "dateOfBirth"=> "1980-01-01", + "phoneNumber"=> "647-90531", + "addressLine1"=> "abc", + "city"=> "vancouver", + "gender"=> "MALE", + "stateProvince"=> "AZ", + "country"=> "US", + "postalCode"=> "12345", + "language"=> "en", + "mobileNumber"=> "605-555-1323", + "timeZone"=> "MST", + "programToken"=> $programToken, + "governmentId"=> "987654321", + "verificationStatus"=>"NOT_REQUIRED", + "businessStakeholderVerificationStatus"=>"VERIFIED", + "letterOfAuthorizationStatus"=>"VERIFIED", + "governmentIdType"=>"NATIONAL_ID_CARD" + )); + // Run test + if (!$this->includeIntegrationTest) { + $this->markTestSkipped('This test is skipped.'); + } + $newStatusTransition = $hyperwallet->createUser($user); + var_dump('--------New user------',$user); + $this->assertNotNull($newStatusTransition); + $this->assertEquals('NOT_REQUIRED', $newStatusTransition->getVerificationStatus()); + } } diff --git a/tests/Hyperwallet/Tests/Util/HyperwalletUUIDTest.php b/tests/Hyperwallet/Tests/Util/HyperwalletUUIDTest.php new file mode 100644 index 00000000..83bca552 --- /dev/null +++ b/tests/Hyperwallet/Tests/Util/HyperwalletUUIDTest.php @@ -0,0 +1,23 @@ +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 From f69ae6747cfe8fe9317f242657e93e3bd794cf72 Mon Sep 17 00:00:00 2001 From: Rajendran Rathinasabapathy Date: Tue, 17 Nov 2020 21:49:58 +0530 Subject: [PATCH 4/6] Updated HyperwalletTest methods --- src/Hyperwallet/Util/ApiClient.php | 1 - tests/Hyperwallet/Tests/HyperwalletTest.php | 71 --------------------- 2 files changed, 72 deletions(-) diff --git a/src/Hyperwallet/Util/ApiClient.php b/src/Hyperwallet/Util/ApiClient.php index f6010f96..c5b5eb08 100644 --- a/src/Hyperwallet/Util/ApiClient.php +++ b/src/Hyperwallet/Util/ApiClient.php @@ -66,7 +66,6 @@ public function __construct($username, $password, $server, $clientOptions = arra $this->uuid = HyperwalletUUID::v4(); // Setup http client if not specified $this->client = new Client(array_merge_recursive(array( - 'verify'=>false, 'base_uri' => $server, 'auth' => array($username, $password), 'headers' => array( diff --git a/tests/Hyperwallet/Tests/HyperwalletTest.php b/tests/Hyperwallet/Tests/HyperwalletTest.php index 494d6add..23bff175 100644 --- a/tests/Hyperwallet/Tests/HyperwalletTest.php +++ b/tests/Hyperwallet/Tests/HyperwalletTest.php @@ -4712,75 +4712,4 @@ public function testListTransferMethods_withParameters() { // Validate mock \Phake::verify($apiClientMock)->doGet('/rest/v3/users/{user-token}/transfer-methods', array('user-token' => 'test-user-token'), array('type'=>TransferMethod::TYPE_PREPAID_CARD)); } - - private $includeIntegrationTest = true; //change this value to true if integration tests have to be run - - /*Following are the methods for integration testing. Please change $includeIntegrationTest to True if you want - *the following test cases - */ -/* - public function testGetUserSampleIT() { - $username = "selrestuser@1861681"; - $password = "Password1!"; - $programToken = "prg-eedaf875-01f1-4524-8b94-d4936255af78"; - $server = "https://localhost-hyperwallet.aws.paylution.net:8181"; - $userToken = "usr-f49967a9-9b7f-4cfc-9fc7-037d736711ba"; - $hyperwallet = new \Hyperwallet\Hyperwallet($username, $password, $programToken, $server); - try { - if (!$this->includeIntegrationTest) { - $this->markTestSkipped('This test is skipped.'); - } - $user = $hyperwallet->getUser($userToken); - var_dump('User details', $user); - echo "Got the user successfully"; - } catch (\Hyperwallet\Exception\HyperwalletException $e) { - echo $e->getMessage(); - die("\n"); - } - } -*/ - public function testCreateUser_successfulIT() { - $username = "selrestuser@1861681"; - $password = "Password1!"; - $programToken = "prg-eedaf875-01f1-4524-8b94-d4936255af78"; - $server = "https://localhost-hyperwallet.aws.paylution.net:8181"; - $userToken = "usr-f49967a9-9b7f-4cfc-9fc7-037d736711ba"; - - $hyperwallet = new \Hyperwallet\Hyperwallet($username, $password, $programToken, $server); - $user = $hyperwallet->getUser($userToken); - var_dump('User details', $user); - - $user = new User(array( "clientUserId"=> "user1877253", - "email"=> "user1877253@sink.sendgrid.net", - "profileType"=> "INDIVIDUAL", - "firstName"=> "Stan", - "middleName"=> "QA", - "lastName"=> "Fung", - "dateOfBirth"=> "1980-01-01", - "phoneNumber"=> "647-90531", - "addressLine1"=> "abc", - "city"=> "vancouver", - "gender"=> "MALE", - "stateProvince"=> "AZ", - "country"=> "US", - "postalCode"=> "12345", - "language"=> "en", - "mobileNumber"=> "605-555-1323", - "timeZone"=> "MST", - "programToken"=> $programToken, - "governmentId"=> "987654321", - "verificationStatus"=>"NOT_REQUIRED", - "businessStakeholderVerificationStatus"=>"VERIFIED", - "letterOfAuthorizationStatus"=>"VERIFIED", - "governmentIdType"=>"NATIONAL_ID_CARD" - )); - // Run test - if (!$this->includeIntegrationTest) { - $this->markTestSkipped('This test is skipped.'); - } - $newStatusTransition = $hyperwallet->createUser($user); - var_dump('--------New user------',$user); - $this->assertNotNull($newStatusTransition); - $this->assertEquals('NOT_REQUIRED', $newStatusTransition->getVerificationStatus()); - } } From fcbea811dfe0cfc42cce116f30ffe1960642d596 Mon Sep 17 00:00:00 2001 From: Rajendran Rathinasabapathy Date: Wed, 18 Nov 2020 00:32:41 +0530 Subject: [PATCH 5/6] Deleted .DS_store --- .DS_Store | Bin 8196 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index dd9b8311795289521d65a2ef1ab3b8deec880a95..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8196 zcmeHMTWl0n82-Puv~vQ;DRSv7mac4|6vgu1&k(23L8vNO8{ zd|4BXFJi=KOf)euydmG@8P0dcI?^Fe8DYEd+cegY90|9dgdv{#an24peW#FBF5m zFmTM_TxFY-D^>pBOyCqe|EOK`8HIRb+3MyEo9^x0_TcW!)#Z1rkc}&am~brH3!D>< zT^yNptYB(9>*sCHa=eqHWyg1Nu08B!r|rht--NijW^L1QGhyB}=USLz$doZw$~mV> zPH-liV||M$j#<3&!v#ytV#&7+5qeTBrunGy^c8JxEyD=St!<_l_W3DfHVSO-5Muao z$Fro*OHd2%+A7QuH=DCvX$hUyy*=5aOi zp{ySa&e$HW>SLZhe7Y91-!R6Nx7V_GRjG8F-tUlxRJv1-q+xKR>)g93)|u#I)A8KQVzDOn_3zL8BVxU_Oe^%xRjb#h+B&vw-`RU( zCl~D9ts)AQqool_W=;~}=FQWg+HEtjPBd53@(3%=K5Z!3$OavqOl&Y%DKeCbnb??U zHCWEFCiIHU369JfvQ`Ig5nTq$Q!dfo`$e~40n0k=-647m)~T%5-d!Rs)K5&39&b!! zgdtH)eO0yhI$fkI^dWu1n){lr)A#fv{SHDsWT>|U)}a}j(29Go8SU7HZdTq7^dN)1 z=*NCm-w=jz6r&ht_2onLP2m)Z2vA}bR`4Wi@M$~~sqjU-gx7Fkf#wG0)TR-aZfdSP zRP@|}cakl03Y{Muk75S?Lky_1pG%Xv|L?8-{XYzfo0x%^f&V81sLKpx_VBY+JJr-( zJIVDiuBxcGipDU7n|U7sczoj@hTKnbsLDx4SkcH9E`R%nfcX3md5@dhn}I(8Z*g-^ From 210fb25877142daaff3843721eca793bcb8f0261 Mon Sep 17 00:00:00 2001 From: amylavarapu Date: Fri, 20 Nov 2020 13:30:02 -0800 Subject: [PATCH 6/6] Updated version in Changelog, readme, apiclient --- CHANGELOG.md | 3 +++ README.md | 2 +- src/Hyperwallet/Util/ApiClient.php | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) 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/Util/ApiClient.php b/src/Hyperwallet/Util/ApiClient.php index c5b5eb08..2580daef 100644 --- a/src/Hyperwallet/Util/ApiClient.php +++ b/src/Hyperwallet/Util/ApiClient.php @@ -23,7 +23,7 @@ class ApiClient { * * @var string */ - const VERSION = '1.7.0'; + const VERSION = '1.6.1'; /** * The Guzzle http client