From 97e3d395ecbcf126dff0ad697a6f32c4399c569d Mon Sep 17 00:00:00 2001 From: saraswati Date: Wed, 11 Nov 2020 15:35:11 +0530 Subject: [PATCH 01/12] Added missed get and list TransferStatusTransition methods in PHP-V4 --- src/Hyperwallet/Hyperwallet.php | 48 +++++++++++++ tests/Hyperwallet/Tests/HyperwalletTest.php | 75 +++++++++++++++++++++ 2 files changed, 123 insertions(+) diff --git a/src/Hyperwallet/Hyperwallet.php b/src/Hyperwallet/Hyperwallet.php index e189f141..918beceb 100644 --- a/src/Hyperwallet/Hyperwallet.php +++ b/src/Hyperwallet/Hyperwallet.php @@ -560,6 +560,54 @@ public function createTransferStatusTransition($transferToken, TransferStatusTra return new TransferStatusTransition($body); } + /** + * Get a transfer status transition + * + * @param string $transferToken The transfer token + * @param string $statusTransitionToken The status transition token + * @return TransferStatusTransition + * + * @throws HyperwalletArgumentException + * @throws HyperwalletApiException + */ + public function getTransferStatusTransition($transferToken, $statusTransitionToken) { + if (empty($transferToken)) { + throw new HyperwalletArgumentException('transferToken is required!'); + } + if (empty($statusTransitionToken)) { + throw new HyperwalletArgumentException('statusTransitionToken is required!'); + } + + $body = $this->client->doGet('/rest/v4/transfers/{transfer-token}/status-transitions/{status-transition-token}', array( + 'transfer-token' => $transferToken, + 'status-transition-token' => $statusTransitionToken + ), array()); + return new TransferStatusTransition($body); + } + + /** + * List all transfer status transitions + * + * @param string $transferToken The transfer token + * @param array $options The query parameters + * @return ListResponse + * + * @throws HyperwalletArgumentException + * @throws HyperwalletApiException + */ + public function listTransferStatusTransitions($transferToken, array $options = array()) { + if (empty($transferToken)) { + throw new HyperwalletArgumentException('transfer token is required!'); + } + + $body = $this->client->doGet('/rest/v4/transfers/{transfer-token}/status-transitions', array( + 'transfer-token' => $transferToken + ), $options); + return new ListResponse($body, function ($entry) { + return new TransferStatusTransition($entry); + }); + } + //-------------------------------------- // PayPal Accounts //-------------------------------------- diff --git a/tests/Hyperwallet/Tests/HyperwalletTest.php b/tests/Hyperwallet/Tests/HyperwalletTest.php index 2dc35921..e87d9b1c 100644 --- a/tests/Hyperwallet/Tests/HyperwalletTest.php +++ b/tests/Hyperwallet/Tests/HyperwalletTest.php @@ -1149,6 +1149,81 @@ public function testCreateTransferStatusTransition_allParameters() { \Phake::verify($apiClientMock)->doPost('/rest/v4/transfers/{transfer-token}/status-transitions', array('transfer-token' => 'test-transfer-token'), $statusTransition, array()); } + public function testGetTransferStatusTransition_noTransferToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + + // Run test + try { + $client->getTransferStatusTransition('', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('transferToken is required!', $e->getMessage()); + } + } + + public function testGetTransferStatusTransition_noStatusTransitionToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + + // Run test + try { + $client->getTransferStatusTransition('test-transfer-token', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('statusTransitionToken is required!', $e->getMessage()); + } + } + + public function testGetTransferStatusTransition_allParameters() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + $apiClientMock = $this->createAndInjectApiClientMock($client); + + \Phake::when($apiClientMock)->doGet('/rest/v4/transfers/{transfer-token}/status-transitions/{status-transition-token}', array('transfer-token' => 'test-transfer-token', 'status-transition-token' => 'test-status-transition-token'), array())->thenReturn(array('success' => 'true')); + + // Run test + $statusTransition = $client->getTransferStatusTransition('test-transfer-token', 'test-status-transition-token'); + $this->assertNotNull($statusTransition); + $this->assertEquals(array('success' => 'true'), $statusTransition->getProperties()); + + // Validate mock + \Phake::verify($apiClientMock)->doGet('/rest/v4/transfers/{transfer-token}/status-transitions/{status-transition-token}', array('transfer-token' => 'test-transfer-token', 'status-transition-token' => 'test-status-transition-token'), array()); + } + + public function testListTransferStatusTransitions_noTransferToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + + // Run test + try { + $client->listTransferStatusTransitions(''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('transfer token is required!', $e->getMessage()); + } + } + + public function testListTransferStatusTransitions_withParameters() { + // Setup + $client = new Hyperwallet('test-username', 'test-password', 'test-program-token'); + $apiClientMock = $this->createAndInjectApiClientMock($client); + + \Phake::when($apiClientMock)->doGet('/rest/v4/transfers/{transfer-token}/status-transitions', array('transfer-token' => 'test-transfer-token'), array('test' => 'value'))->thenReturn(array('limit' => 1,'hasNextPage' => false ,'hasPreviousPage' => false,'links' => 'links', 'data' => array())); + + // Run test + $statusTransitionList = $client->listTransferStatusTransitions('test-transfer-token', array('test' => 'value')); + $this->assertNotNull($statusTransitionList); + $this->assertCount(0, $statusTransitionList); + $this->assertEquals(1, $statusTransitionList->getLimit()); + $this->assertEquals(false, $statusTransitionList->getHasNextPage()); + $this->assertEquals(false, $statusTransitionList->getHasPreviousPage()); + $this->assertEquals('links', $statusTransitionList->getLinks()); + + // Validate mock + \Phake::verify($apiClientMock)->doGet('/rest/v4/transfers/{transfer-token}/status-transitions', array('transfer-token' => 'test-transfer-token'), array('test' => 'value')); + } + //-------------------------------------- // PayPal Accounts //-------------------------------------- From fe7498930d312852b4a1772ed493a8a6a0d002a8 Mon Sep 17 00:00:00 2001 From: Rajendran Rathinasabapathy Date: Wed, 11 Nov 2020 17:24:02 +0530 Subject: [PATCH 02/12] Added V4 headers for sdk-type, sdk-version and sdk-contextId --- src/Hyperwallet/Util/ApiClient.php | 18 ++++- tests/Hyperwallet/Tests/HyperwalletTest.php | 65 +++++++++++++++++++ .../Hyperwallet/Tests/Util/ApiClientTest.php | 2 +- 3 files changed, 82 insertions(+), 3 deletions(-) diff --git a/src/Hyperwallet/Util/ApiClient.php b/src/Hyperwallet/Util/ApiClient.php index 8954d10f..b764dbe3 100644 --- a/src/Hyperwallet/Util/ApiClient.php +++ b/src/Hyperwallet/Util/ApiClient.php @@ -57,12 +57,15 @@ class ApiClient { public function __construct($username, $password, $server, $clientOptions = array(), $encryptionData = array()) { // 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'])) { @@ -216,4 +219,15 @@ private function checkResponseHeaderContentType($response) { public function putMultipartData($partialUrl, array $uriParams, array $options) { return $this->doRequest('PUT', $partialUrl, $uriParams, $options); } + + function uuid() + { + return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', + mt_rand(0, 0xffff), mt_rand(0, 0xffff), + mt_rand(0, 0xffff), + mt_rand(0, 0x0fff) | 0x4000, + mt_rand(0, 0x3fff) | 0x8000, + mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) + ); + } } diff --git a/tests/Hyperwallet/Tests/HyperwalletTest.php b/tests/Hyperwallet/Tests/HyperwalletTest.php index 2dc35921..025006d8 100644 --- a/tests/Hyperwallet/Tests/HyperwalletTest.php +++ b/tests/Hyperwallet/Tests/HyperwalletTest.php @@ -34,6 +34,8 @@ class HyperwalletTest extends \PHPUnit_Framework_TestCase { + private $includeIntegrationTest = true; + public function testConstructor_throwErrorIfUsernameIsEmpty() { try { new Hyperwallet('', 'test-password'); @@ -5080,4 +5082,67 @@ public function testListTransferMethods_withParameters() { // Validate mock \Phake::verify($apiClientMock)->doGet('/rest/v4/users/{user-token}/transfer-methods', array('user-token' => 'test-user-token'), array('type'=>TransferMethod::TYPE_PREPAID_CARD)); } + + //functional test + + 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('GET USER - 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"; + $hyperwallet = new \Hyperwallet\Hyperwallet($username, $password, $programToken, $server); + $user = new User(array( "clientUserId"=> "user1877270", + "email"=> "user1877270@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('-----CREATE USER-User details----',$user); + $this->assertNotNull($newStatusTransition); + $this->assertEquals('NOT_REQUIRED', $newStatusTransition->getVerificationStatus()); + } + } diff --git a/tests/Hyperwallet/Tests/Util/ApiClientTest.php b/tests/Hyperwallet/Tests/Util/ApiClientTest.php index 68feb627..2c890c80 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 7a5574080220a44975ff0d9338661be2368231d4 Mon Sep 17 00:00:00 2001 From: Rajendran Rathinasabapathy Date: Wed, 11 Nov 2020 17:28:13 +0530 Subject: [PATCH 03/12] Removed test cases after Adding V4 headers for sdk-type, sdk-version and sdk-contextId --- src/Hyperwallet/Util/ApiClient.php | 1 - tests/Hyperwallet/Tests/HyperwalletTest.php | 66 --------------------- 2 files changed, 67 deletions(-) diff --git a/src/Hyperwallet/Util/ApiClient.php b/src/Hyperwallet/Util/ApiClient.php index b764dbe3..ec09106e 100644 --- a/src/Hyperwallet/Util/ApiClient.php +++ b/src/Hyperwallet/Util/ApiClient.php @@ -57,7 +57,6 @@ class ApiClient { public function __construct($username, $password, $server, $clientOptions = array(), $encryptionData = array()) { // 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 025006d8..bb82e34e 100644 --- a/tests/Hyperwallet/Tests/HyperwalletTest.php +++ b/tests/Hyperwallet/Tests/HyperwalletTest.php @@ -33,9 +33,6 @@ use Hyperwallet\Util\ApiClient; class HyperwalletTest extends \PHPUnit_Framework_TestCase { - - private $includeIntegrationTest = true; - public function testConstructor_throwErrorIfUsernameIsEmpty() { try { new Hyperwallet('', 'test-password'); @@ -5082,67 +5079,4 @@ public function testListTransferMethods_withParameters() { // Validate mock \Phake::verify($apiClientMock)->doGet('/rest/v4/users/{user-token}/transfer-methods', array('user-token' => 'test-user-token'), array('type'=>TransferMethod::TYPE_PREPAID_CARD)); } - - //functional test - - 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('GET USER - 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"; - $hyperwallet = new \Hyperwallet\Hyperwallet($username, $password, $programToken, $server); - $user = new User(array( "clientUserId"=> "user1877270", - "email"=> "user1877270@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('-----CREATE USER-User details----',$user); - $this->assertNotNull($newStatusTransition); - $this->assertEquals('NOT_REQUIRED', $newStatusTransition->getVerificationStatus()); - } - } From 24f1e5cc500d2afa230761ae3d29f4c665576827 Mon Sep 17 00:00:00 2001 From: Rajendran Rathinasabapathy Date: Wed, 11 Nov 2020 17:39:56 +0530 Subject: [PATCH 04/12] modified uuid method to private after Adding V4 headers for sdk-type, sdk-version and sdk-contextId --- src/Hyperwallet/Util/ApiClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Hyperwallet/Util/ApiClient.php b/src/Hyperwallet/Util/ApiClient.php index ec09106e..d373fd62 100644 --- a/src/Hyperwallet/Util/ApiClient.php +++ b/src/Hyperwallet/Util/ApiClient.php @@ -219,7 +219,7 @@ public function putMultipartData($partialUrl, array $uriParams, array $options) return $this->doRequest('PUT', $partialUrl, $uriParams, $options); } - function uuid() + private function uuid() { return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff), From a2a72faa79843a4dc0a193e282a8dfafdc46fb20 Mon Sep 17 00:00:00 2001 From: Rajendran Rathinasabapathy Date: Wed, 11 Nov 2020 17:40:26 +0530 Subject: [PATCH 05/12] modified uuid method to private after Adding V4 headers for sdk-type, sdk-version and sdk-contextId --- tests/Hyperwallet/Tests/HyperwalletTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Hyperwallet/Tests/HyperwalletTest.php b/tests/Hyperwallet/Tests/HyperwalletTest.php index bb82e34e..2dc35921 100644 --- a/tests/Hyperwallet/Tests/HyperwalletTest.php +++ b/tests/Hyperwallet/Tests/HyperwalletTest.php @@ -33,6 +33,7 @@ use Hyperwallet\Util\ApiClient; class HyperwalletTest extends \PHPUnit_Framework_TestCase { + public function testConstructor_throwErrorIfUsernameIsEmpty() { try { new Hyperwallet('', 'test-password'); From dd4f5daa59b5024f07e714b29fb764d742d8bd78 Mon Sep 17 00:00:00 2001 From: Rajendran Rathinasabapathy Date: Wed, 11 Nov 2020 18:02:16 +0530 Subject: [PATCH 06/12] Updated version from 0.1.0 to 2.1.0 --- src/Hyperwallet/Util/ApiClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Hyperwallet/Util/ApiClient.php b/src/Hyperwallet/Util/ApiClient.php index d373fd62..163f4d83 100644 --- a/src/Hyperwallet/Util/ApiClient.php +++ b/src/Hyperwallet/Util/ApiClient.php @@ -22,7 +22,7 @@ class ApiClient { * * @var string */ - const VERSION = '0.1.0'; + const VERSION = '2.1.0'; /** * The Guzzle http client From 7fda7d5a5aada4e00876fc78f71f9b4ffcbec5d9 Mon Sep 17 00:00:00 2001 From: amylavarapu Date: Wed, 11 Nov 2020 11:51:48 -0800 Subject: [PATCH 07/12] modified comment --- src/Hyperwallet/Hyperwallet.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Hyperwallet/Hyperwallet.php b/src/Hyperwallet/Hyperwallet.php index e189f141..8e609735 100644 --- a/src/Hyperwallet/Hyperwallet.php +++ b/src/Hyperwallet/Hyperwallet.php @@ -2029,7 +2029,7 @@ public function createUserStatusTransition($userToken, UserStatusTransition $tra } /** - * Activate an User + * Activate a User * * @param string $userToken The user token * @return UserStatusTransition From df3043946aeace128a8e9972edd9980b1be68418 Mon Sep 17 00:00:00 2001 From: saraswati Date: Thu, 12 Nov 2020 11:12:54 +0530 Subject: [PATCH 08/12] Changed hhvm version from 3.18 to 3.24 in .yml file --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index efae4f2d..4d7a3c9b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ php: - '5.6' - '7.0' - '7.3' -- hhvm-3.18 +- hhvm-3.24 cache: directories: - $HOME/.composer/cache From 4268ab643c7ad848694b1db5fa7190dff5caff42 Mon Sep 17 00:00:00 2001 From: Rajendran Rathinasabapathy Date: Fri, 13 Nov 2020 13:28:34 +0530 Subject: [PATCH 09/12] Created HyperwalletUUID utility to generate UUID --- src/Hyperwallet/Util/ApiClient.php | 23 +++++----- src/Hyperwallet/Util/HyperwalletUUID.php | 57 ++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 src/Hyperwallet/Util/HyperwalletUUID.php diff --git a/src/Hyperwallet/Util/ApiClient.php b/src/Hyperwallet/Util/ApiClient.php index 163f4d83..3d67a687 100644 --- a/src/Hyperwallet/Util/ApiClient.php +++ b/src/Hyperwallet/Util/ApiClient.php @@ -9,6 +9,8 @@ use Hyperwallet\Model\BaseModel; use Hyperwallet\Response\ErrorResponse; use Hyperwallet\Util\HyperwalletEncryption; +use Hyperwallet\Util\HyperwalletUUID; + /** * The internal API client @@ -38,6 +40,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,6 +64,7 @@ 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, @@ -64,7 +74,7 @@ public function __construct($username, $password, $server, $clientOptions = arra 'Accept' => 'application/json', 'x-sdk-version' => self::VERSION, 'x-sdk-type' => 'PHP', - 'x-sdk-contextId' => $this->uuid()) + 'x-sdk-contextId' => $this->uuid) ), $clientOptions)); if (!empty($encryptionData) && isset($encryptionData['clientPrivateKeySetLocation']) && isset($encryptionData['hyperwalletKeySetLocation'])) { @@ -218,15 +228,4 @@ private function checkResponseHeaderContentType($response) { public function putMultipartData($partialUrl, array $uriParams, array $options) { return $this->doRequest('PUT', $partialUrl, $uriParams, $options); } - - private function uuid() - { - return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', - mt_rand(0, 0xffff), mt_rand(0, 0xffff), - mt_rand(0, 0xffff), - mt_rand(0, 0x0fff) | 0x4000, - mt_rand(0, 0x3fff) | 0x8000, - mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) - ); - } } 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 @@ + Date: Fri, 13 Nov 2020 14:04:34 +0530 Subject: [PATCH 10/12] Added unit test class for HyperWalletUUID --- tests/Hyperwallet/Tests/HyperwalletTest.php | 1 + .../Tests/Util/HyperwalletUUIDTest.php | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 tests/Hyperwallet/Tests/Util/HyperwalletUUIDTest.php diff --git a/tests/Hyperwallet/Tests/HyperwalletTest.php b/tests/Hyperwallet/Tests/HyperwalletTest.php index 2dc35921..84b868d7 100644 --- a/tests/Hyperwallet/Tests/HyperwalletTest.php +++ b/tests/Hyperwallet/Tests/HyperwalletTest.php @@ -31,6 +31,7 @@ use Hyperwallet\Model\VenmoAccountStatusTransition; use Hyperwallet\Response\ErrorResponse; use Hyperwallet\Util\ApiClient; +use Hyperwallet\Util\HyperwalletUUID; class HyperwalletTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Hyperwallet/Tests/Util/HyperwalletUUIDTest.php b/tests/Hyperwallet/Tests/Util/HyperwalletUUIDTest.php new file mode 100644 index 00000000..8241efe8 --- /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); + } +} From f6a12bff3a5b881661dbcdcff45601a44bcd1d02 Mon Sep 17 00:00:00 2001 From: saraswati Date: Fri, 13 Nov 2020 15:50:19 +0530 Subject: [PATCH 11/12] Added Business Stakeholder related methods to PHP-V4 --- src/Hyperwallet/Hyperwallet.php | 125 +++++++++ .../BusinessStakeholderStatusTransition.php | 25 ++ tests/Hyperwallet/Tests/HyperwalletTest.php | 255 ++++++++++++++++++ 3 files changed, 405 insertions(+) create mode 100644 src/Hyperwallet/Model/BusinessStakeholderStatusTransition.php diff --git a/src/Hyperwallet/Hyperwallet.php b/src/Hyperwallet/Hyperwallet.php index 918beceb..c410faeb 100644 --- a/src/Hyperwallet/Hyperwallet.php +++ b/src/Hyperwallet/Hyperwallet.php @@ -11,6 +11,7 @@ use Hyperwallet\Model\BankCard; use Hyperwallet\Model\BankCardStatusTransition; use Hyperwallet\Model\BusinessStakeholder; +use Hyperwallet\Model\BusinessStakeholderStatusTransition; use Hyperwallet\Model\IProgramAware; use Hyperwallet\Model\PaperCheck; use Hyperwallet\Model\PaperCheckStatusTransition; @@ -2465,6 +2466,130 @@ public function listBusinessStakeholders($userToken , $options) { }); } + /** + * Create a Business Stakeholder status transition + * + * @param string $userToken The user token + * @param string $businessToken The Business Token + * @param BusinessStakeholderStatusTransition $transition The status transition + * @return BusinessStakeholderStatusTransition + * + * @throws HyperwalletArgumentException + * @throws HyperwalletApiException + */ + public function createBusinessStakeholderStatusTransition($userToken, $businessToken, BusinessStakeholderStatusTransition $transition) { + if (empty($userToken)) { + throw new HyperwalletArgumentException('userToken is required!'); + } + if (empty($businessToken)) { + throw new HyperwalletArgumentException('businessToken is required!'); + } + + $body = $this->client->doPost('/rest/v4/users/{user-token}/business-stakeholders/{business-token}/status-transitions', array( + 'user-token' => $userToken, + 'business-token' => $businessToken + ), $transition, array()); + return new BusinessStakeholderStatusTransition($body); + } + + /** + * activate a Business Stakeholder + * + * @param string $userToken The user token + * @param string $businessToken The Business Token + * @return BusinessStakeholderStatusTransition + * + * @throws HyperwalletArgumentException + * @throws HyperwalletApiException + */ + public function activateBusinessStakeholder($userToken, $businessToken) { + $transition = new BusinessStakeholderStatusTransition(); + $transition->setTransition(BusinessStakeholderStatusTransition::TRANSITION_ACTIVATED); + + return $this->createBusinessStakeholderStatusTransition($userToken, $businessToken, $transition); + } + + /** + * Deactivate a Business Stakeholder + * + * @param string $userToken The user token + * @param string $businessToken The Business Token + * @return BusinessStakeholderStatusTransition + * + * @throws HyperwalletArgumentException + * @throws HyperwalletApiException + */ + public function deactivateBusinessStakeholder($userToken, $businessToken) { + $transition = new BusinessStakeholderStatusTransition(); + $transition->setTransition(BusinessStakeholderStatusTransition::TRANSITION_DE_ACTIVATED); + + return $this->createBusinessStakeholderStatusTransition($userToken, $businessToken, $transition); + } + + /** + * Get a Business Stakeholder status transition + * + * @param string $userToken The user token + * @param string $businessToken The Business Token + * @param string $statusTransitionToken The status transition token + * @return BusinessStakeholderStatusTransition + * + * @throws HyperwalletArgumentException + * @throws HyperwalletApiException + */ + public function getBusinessStakeholderStatusTransition($userToken, $businessToken, $statusTransitionToken) { + if (empty($userToken)) { + throw new HyperwalletArgumentException('userToken is required!'); + } + if (empty($businessToken)) { + throw new HyperwalletArgumentException('businessToken is required!'); + } + if (empty($statusTransitionToken)) { + throw new HyperwalletArgumentException('statusTransitionToken is required!'); + } + + $body = $this->client->doGet('/rest/v4/users/{user-token}/business-stakeholders/{business-token}/status-transitions/{status-transition-token}', array( + 'user-token' => $userToken, + 'business-token' => $businessToken, + 'status-transition-token' => $statusTransitionToken + ), array()); + return new BusinessStakeholderStatusTransition($body); + } + + /** + * List all Business Stakeholder status transitions + * + * @param string $userToken The user token + * @param string $businessToken The Business Token + * @param array $options The query parameters + * @return ListResponse + * + * @throws HyperwalletArgumentException + * @throws HyperwalletApiException + */ + public function listBusinessStakeholderStatusTransitions($userToken, $businessToken, array $options = array()) { + if (empty($userToken)) { + throw new HyperwalletArgumentException('userToken is required!'); + } + if (empty($businessToken)) { + throw new HyperwalletArgumentException('businessToken is required!'); + } + if (!empty($options)) { + $filteredArr = array_diff_key($options, array_flip(StatusTransition::FILTERS_ARRAY())); + if (!empty($filteredArr)) { + throw new HyperwalletArgumentException('Invalid filter'); + } + } + + $body = $this->client->doGet('/rest/v4/users/{user-token}/business-stakeholders/{business-token}/status-transitions', array( + 'user-token' => $userToken, + 'business-token' => $businessToken + ), $options); + return new ListResponse($body, function ($entry) { + return new BusinessStakeholderStatusTransition($entry); + }); + } + /** * List all Transfer Methods * diff --git a/src/Hyperwallet/Model/BusinessStakeholderStatusTransition.php b/src/Hyperwallet/Model/BusinessStakeholderStatusTransition.php new file mode 100644 index 00000000..2276a397 --- /dev/null +++ b/src/Hyperwallet/Model/BusinessStakeholderStatusTransition.php @@ -0,0 +1,25 @@ +createBusinessStakeholderStatusTransition('', '', $statusTransition); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('userToken is required!', $e->getMessage()); + } + } + + public function testCreateBusinessStakeholderStatusTransition_noBusinessToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + $statusTransition = new BusinessStakeholderStatusTransition(); + + try { + $client->createBusinessStakeholderStatusTransition('test-user-token', '', $statusTransition); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('businessToken is required!', $e->getMessage()); + } + } + + public function testCreateBusinessStakeholderStatusTransition_allParameters() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + $apiClientMock = $this->createAndInjectApiClientMock($client); + $statusTransition = new BusinessStakeholderStatusTransition(array('transition' => 'test')); + + \Phake::when($apiClientMock)->doPost('/rest/v4/users/{user-token}/business-stakeholders/{business-token}/status-transitions', array('user-token' => 'test-user-token', 'business-token' => 'test-business-token'), $statusTransition, array())->thenReturn(array('success' => 'true')); + + // Run test + $newStatusTransition = $client->createBusinessStakeholderStatusTransition('test-user-token', 'test-business-token', $statusTransition); + $this->assertNotNull($newStatusTransition); + $this->assertEquals(array('success' => 'true'), $newStatusTransition->getProperties()); + + // Validate mock + \Phake::verify($apiClientMock)->doPost('/rest/v4/users/{user-token}/business-stakeholders/{business-token}/status-transitions', array('user-token' => 'test-user-token', 'business-token' => 'test-business-token'), $statusTransition, array()); + } + + public function testActivateBusinessStakeholder_noUserToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password', 'test-program-token'); + + // Run test + try { + $client->activateBusinessStakeholder('', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('userToken is required!', $e->getMessage()); + } + } + + public function testActivateBusinessStakeholder_noBusinessToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password', 'test-program-token'); + + // Run test + try { + $client->activateBusinessStakeholder('test-user-token', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('businessToken is required!', $e->getMessage()); + } + } + + public function testActivateBusinessStakeholder_allParameters() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + $apiClientMock = $this->createAndInjectApiClientMock($client); + + $statusTransition = new BusinessStakeholderStatusTransition(); + $statusTransition->setTransition(BusinessStakeholderStatusTransition::TRANSITION_ACTIVATED); + + \Phake::when($apiClientMock)->doPost('/rest/v4/users/{user-token}/business-stakeholders/{business-token}/status-transitions', array('user-token' => 'test-user-token', 'business-token' => 'test-business-token'), $statusTransition, array())->thenReturn(array('success' => 'true')); + + // Run test + $newStatusTransition = $client->activateBusinessStakeholder('test-user-token', 'test-business-token'); + $this->assertNotNull($newStatusTransition); + $this->assertEquals(array('success' => 'true'), $newStatusTransition->getProperties()); + + // Validate mock + \Phake::verify($apiClientMock)->doPost('/rest/v4/users/{user-token}/business-stakeholders/{business-token}/status-transitions', array('user-token' => 'test-user-token', 'business-token' => 'test-business-token'), $statusTransition, array()); + } + + public function testDeactivateBusinessStakeholder_noUserToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password', 'test-program-token'); + + // Run test + try { + $client->deactivateBusinessStakeholder('', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('userToken is required!', $e->getMessage()); + } + } + + public function testDeactivateBusinessStakeholder_noBusinessToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password', 'test-program-token'); + + // Run test + try { + $client->deactivateBusinessStakeholder('test-user-token', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('businessToken is required!', $e->getMessage()); + } + } + + public function testDeactivateBusinessStakeholder_allParameters() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + $apiClientMock = $this->createAndInjectApiClientMock($client); + + $statusTransition = new BusinessStakeholderStatusTransition(); + $statusTransition->setTransition(BusinessStakeholderStatusTransition::TRANSITION_DE_ACTIVATED); + + \Phake::when($apiClientMock)->doPost('/rest/v4/users/{user-token}/business-stakeholders/{business-token}/status-transitions', array('user-token' => 'test-user-token', 'business-token' => 'test-business-token'), $statusTransition, array())->thenReturn(array('success' => 'true')); + + // Run test + $newStatusTransition = $client->deactivateBusinessStakeholder('test-user-token', 'test-business-token'); + $this->assertNotNull($newStatusTransition); + $this->assertEquals(array('success' => 'true'), $newStatusTransition->getProperties()); + + // Validate mock + \Phake::verify($apiClientMock)->doPost('/rest/v4/users/{user-token}/business-stakeholders/{business-token}/status-transitions', array('user-token' => 'test-user-token', 'business-token' => 'test-business-token'), $statusTransition, array()); + } + + public function testGetBusinessStakeholderStatusTransition_noUserToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + + // Run test + try { + $client->getBusinessStakeholderStatusTransition('', '', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('userToken is required!', $e->getMessage()); + } + } + + public function testGetBusinessStakeholderStatusTransition_noBusinessToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + + // Run test + try { + $client->getBusinessStakeholderStatusTransition('test-user-token', '', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('businessToken is required!', $e->getMessage()); + } + } + + public function testGetBusinessStakeholderStatusTransition_noStatusTransitionToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + + // Run test + try { + $client->getBusinessStakeholderStatusTransition('test-user-token', 'test-business-token', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('statusTransitionToken is required!', $e->getMessage()); + } + } + + public function testGetBusinessStakeholderStatusTransition_allParameters() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + $apiClientMock = $this->createAndInjectApiClientMock($client); + + \Phake::when($apiClientMock)->doGet('/rest/v4/users/{user-token}/business-stakeholders/{business-token}/status-transitions/{status-transition-token}', array('user-token' => 'test-user-token', 'business-token' => 'test-business-token', 'status-transition-token' => 'test-status-transition-token'), array())->thenReturn(array('success' => 'true')); + + // Run test + $statusTransition = $client->getBusinessStakeholderStatusTransition('test-user-token', 'test-business-token', 'test-status-transition-token'); + $this->assertNotNull($statusTransition); + $this->assertEquals(array('success' => 'true'), $statusTransition->getProperties()); + + // Validate mock + \Phake::verify($apiClientMock)->doGet('/rest/v4/users/{user-token}/business-stakeholders/{business-token}/status-transitions/{status-transition-token}', array('user-token' => "test-user-token", 'business-token' => 'test-business-token', 'status-transition-token' => 'test-status-transition-token'), array()); + } + + public function testListBusinessStakeholderStatusTransition_noUserToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + + // Run test + try { + $client->listBusinessStakeholderStatusTransitions('', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('userToken is required!', $e->getMessage()); + } + } + + public function testListBusinessStakeholderStatusTransitions_noBusinessToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + + // Run test + try { + $client->listBusinessStakeholderStatusTransitions('test-user-token', ''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('businessToken is required!', $e->getMessage()); + } + } + + public function testListBusinessStakeholderStatusTransitions_noParameters() { + // Setup + $client = new Hyperwallet('test-username', 'test-password', 'test-program-token'); + $apiClientMock = $this->createAndInjectApiClientMock($client); + + \Phake::when($apiClientMock)->doGet('/rest/v4/users/{user-token}/business-stakeholders/{business-token}/status-transitions', array('user-token' => 'test-user-token', 'business-token' => 'test-business-token'), array())->thenReturn(array('limit' => 1,'hasNextPage' => false ,'hasPreviousPage' => false,'links' => 'links', 'data' => array())); + + // Run test + $statusTransitionList = $client->listBusinessStakeholderStatusTransitions('test-user-token', 'test-business-token'); + $this->assertNotNull($statusTransitionList); + $this->assertCount(0, $statusTransitionList); + $this->assertEquals(1, $statusTransitionList->getLimit()); + $this->assertEquals(false, $statusTransitionList->getHasNextPage()); + $this->assertEquals(false, $statusTransitionList->getHasPreviousPage()); + $this->assertEquals('links', $statusTransitionList->getLinks()); + + // Validate mock + \Phake::verify($apiClientMock)->doGet('/rest/v4/users/{user-token}/business-stakeholders/{business-token}/status-transitions', array('user-token' => 'test-user-token', 'business-token' => 'test-business-token'), array()); + } + + public function testListBusinessStakeholderStatusTransitions_allParameters() { + // Setup + $client = new Hyperwallet('test-username', 'test-password', 'test-program-token'); + $apiClientMock = $this->createAndInjectApiClientMock($client); + + \Phake::when($apiClientMock)->doGet('/rest/v4/users/{user-token}/business-stakeholders/{business-token}/status-transitions', array('user-token' => 'test-user-token', 'business-token' => 'test-business-token'), array('transition' => PayPalAccountStatusTransition::TRANSITION_DE_ACTIVATED))->thenReturn(array('limit' => 1,'hasNextPage' => false ,'hasPreviousPage' => false,'links' => 'links', 'data' => array(array('success' => 'true')))); + + // Run test + $statusTransitionList = $client->listBusinessStakeholderStatusTransitions('test-user-token', 'test-business-token', array('transition' => PayPalAccountStatusTransition::TRANSITION_DE_ACTIVATED)); + $this->assertNotNull($statusTransitionList); + $this->assertCount(1, $statusTransitionList); + $this->assertEquals(1, $statusTransitionList->getLimit()); + $this->assertEquals(false, $statusTransitionList->getHasNextPage()); + $this->assertEquals(false, $statusTransitionList->getHasPreviousPage()); + $this->assertEquals('links', $statusTransitionList->getLinks()); + + // Validate mock + \Phake::verify($apiClientMock)->doGet('/rest/v4/users/{user-token}/business-stakeholders/{business-token}/status-transitions', array('user-token' => 'test-user-token', 'business-token' => 'test-business-token'), array('transition' => PayPalAccountStatusTransition::TRANSITION_DE_ACTIVATED)); + } + public function testuploadDocumentsForBusinessStakeholder_withoutUserToken() { // Setup $client = new Hyperwallet('test-username', 'test-password'); From ed94f933e3a8f76f1cd078ff3964e1e00343ece7 Mon Sep 17 00:00:00 2001 From: amylavarapu Date: Fri, 13 Nov 2020 16:36:45 -0800 Subject: [PATCH 12/12] Updated changelog and ReadME --- CHANGELOG.md | 7 +++++++ README.md | 1 - 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2558c6c..2cc0858a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ ChangeLog ========= + +2.1.0 +------------------- +- Added header data to the requests (user-agent, sdk version etc) +- Added Business Stakeholders status transitions +- Added Transfer status transitions - get, list + 2.0.0 ------------------- - Updated the methods to point to V4 Rest APIs diff --git a/README.md b/README.md index b25b21aa..7137460a 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,6 @@ Installation $ composer require hyperwallet/sdk ``` - Documentation -------------