diff --git a/hasPreviousPage b/hasPreviousPage new file mode 100644 index 00000000..e69de29b diff --git a/src/Hyperwallet/Hyperwallet.php b/src/Hyperwallet/Hyperwallet.php index 43f70f34..e189f141 100644 --- a/src/Hyperwallet/Hyperwallet.php +++ b/src/Hyperwallet/Hyperwallet.php @@ -66,16 +66,17 @@ class Hyperwallet { * @param string|null $programToken The program token that is used for some API calls * @param string $server The API server to connect to * @param string $encryptionData Encryption data to initialize ApiClient with encryption enabled + * @param array $clientOptions Guzzle Client Options * * @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); } //-------------------------------------- @@ -1501,9 +1502,11 @@ public function listBalancesForUser($userToken, $options = array()) { } $body = $this->client->doGet('/rest/v4/users/{user-token}/balances', array('user-token' => $userToken), $options); - return new ListResponse($body, function ($entry) { + $listResponse = new ListResponse($body, function ($entry) { return new Balance($entry); }); + call_user_func(array($listResponse, 'unsetLinksAttribute')); + return $listResponse; } /** @@ -1528,9 +1531,11 @@ public function listBalancesForPrepaidCard($userToken, $prepaidCardToken, $optio 'user-token' => $userToken, 'prepaid-card-token' => $prepaidCardToken ), $options); - return new ListResponse($body, function ($entry) { + $listResponse = new ListResponse($body, function ($entry) { return new Balance($entry); }); + call_user_func(array($listResponse, 'unsetLinksAttribute')); + return $listResponse; } /** @@ -1555,9 +1560,11 @@ public function listBalancesForAccount($programToken, $accountToken, $options = 'program-token' => $programToken, 'account-token' => $accountToken ), $options); - return new ListResponse($body, function ($entry) { + $listResponse = new ListResponse($body, function ($entry) { return new Balance($entry); }); + call_user_func(array($listResponse, 'unsetLinksAttribute')); + return $listResponse; } //-------------------------------------- @@ -1996,7 +2003,7 @@ public function updateVerificationStatus($userToken, $verificationStatus){ throw new HyperwalletArgumentException('verificationStatus is required!'); } $user = new User(array('verificationStatus'=> $verificationStatus)); - $responseUser = $this->client->doPut('/rest/v3/users/{user-token}', array('user-token' => $userToken), $user, array()); + $responseUser = $this->client->doPut('/rest/v4/users/{user-token}', array('user-token' => $userToken), $user, array()); return new User($responseUser); } @@ -2016,7 +2023,7 @@ public function createUserStatusTransition($userToken, UserStatusTransition $tra if (empty($transition->getTransition())) { throw new HyperwalletArgumentException('userStatusTransition is required!'); } - $body = $this->client->doPost('/rest/v3/users/{user-token}/status-transitions', array( + $body = $this->client->doPost('/rest/v4/users/{user-token}/status-transitions', array( 'user-token' => $userToken), $transition, array()); return new UserStatusTransition($body); } @@ -2346,10 +2353,6 @@ public function uploadDocumentsForBusinessStakeholder($userToken, $businessToken return new BusinessStakeholder($body); } - //-------------------------------------- - // Business Stakeholders - //-------------------------------------- - /** * Create a Business Stakeholder * @@ -2371,6 +2374,7 @@ public function createBusinessStakeholder($userToken,$businessStakeholder) { * * @param Business Stakeholder $BusinessStakeholder The Business Stakeholder * @return BusinessStakeholder + * * @throws HyperwalletArgumentException * @throws HyperwalletApiException @@ -2394,6 +2398,7 @@ public function updateBusinessStakeholder($userToken, $businessToken, $businessS * * @throws HyperwalletApiException */ + public function listBusinessStakeholders($userToken , $options) { if (empty($userToken)) { throw new HyperwalletArgumentException('userToken is required!'); @@ -2411,4 +2416,25 @@ public function listBusinessStakeholders($userToken , $options) { return new BusinessStakeholder($entry); }); } + + /** + * List all Transfer Methods + * + * @param string $userToken The user token + * @param array $options The query parameters + * @return ListResponse of HyperwalletTransferMethod + */ + + public function listTransferMethods($userToken, $options = array()) { + if (empty($userToken)) { + throw new HyperwalletArgumentException('userToken is required!'); + } + + $body = $this->client->doGet('/rest/v4/users/{user-token}/transfer-methods', array( + 'user-token' => $userToken + ), $options); + return new ListResponse($body, function ($entry) { + return new TransferMethod($entry); + }); + } } diff --git a/src/Hyperwallet/Response/ListResponse.php b/src/Hyperwallet/Response/ListResponse.php index e9b33761..2c1b9076 100644 --- a/src/Hyperwallet/Response/ListResponse.php +++ b/src/Hyperwallet/Response/ListResponse.php @@ -191,4 +191,16 @@ public function offsetSet($offset, $value) { public function offsetUnset($offset) { unset($this->data[$offset]); } + + /** + * @external + * + * The links to unset. + * @method unsetLinksAttribute() + * @return void + * @description unsetting links attribute. + */ + public function unsetLinksAttribute(){ + unset($this->links); + } } diff --git a/tests/Hyperwallet/Tests/HyperwalletTest.php b/tests/Hyperwallet/Tests/HyperwalletTest.php index 7a6254fc..2dc35921 100644 --- a/tests/Hyperwallet/Tests/HyperwalletTest.php +++ b/tests/Hyperwallet/Tests/HyperwalletTest.php @@ -209,13 +209,34 @@ public function testUpdateUser_allParameters() { $client = new Hyperwallet('test-username', 'test-password'); $apiClientMock = $this->createAndInjectApiClientMock($client); $user = new User(array('token' => 'test-user-token')); + $user->setFirstName("test-first-name"); - \Phake::when($apiClientMock)->doPut('/rest/v4/users/{user-token}', array('user-token' => 'test-user-token'), $user, array())->thenReturn(array('success' => 'true')); + $user->setVerificationStatus(User::VERIFICATION_STATUS_VERIFIED); + $user->setBusinessStakeholderVerificationStatus(User::BUSINESSS_STAKEHOLDER_VERIFICATION_STATUS_VERIFIED); + $user->setLetterOfAuthorizationStatus(User::LETTER_OF_AUTHORIZATION_STATUS_VERIFIED); + $user->setGovernmentIdType(User::GOVERNMENT_ID_TYPE_NATIONAL_ID_CARD); + + $expectedResponse = array('success' => 'true','verificationStatus'=>User::VERIFICATION_STATUS_VERIFIED, + 'businessStakeholderVerificationStatus'=>User::BUSINESSS_STAKEHOLDER_VERIFICATION_STATUS_VERIFIED, + 'letterOfAuthorizationStatus'=>User::LETTER_OF_AUTHORIZATION_STATUS_VERIFIED, + 'governmentIdType'=>User::GOVERNMENT_ID_TYPE_NATIONAL_ID_CARD, + 'firstName'=>"test-first-name", + 'businessOperatingName'=>"test-business-operating-name", + 'timeZone'=>'test-time-zone'); + + \Phake::when($apiClientMock)->doPut('/rest/v4/users/{user-token}', array('user-token' => 'test-user-token'), $user, array())->thenReturn($expectedResponse); // Run test $newUser = $client->updateUser($user); $this->assertNotNull($newUser); - $this->assertEquals(array('success' => 'true'), $newUser->getProperties()); + $this->assertEquals(array('success' => 'true','verificationStatus'=>User::VERIFICATION_STATUS_VERIFIED, + 'businessStakeholderVerificationStatus'=>User::BUSINESSS_STAKEHOLDER_VERIFICATION_STATUS_VERIFIED, + 'letterOfAuthorizationStatus'=>User::LETTER_OF_AUTHORIZATION_STATUS_VERIFIED, + 'governmentIdType'=>User::GOVERNMENT_ID_TYPE_NATIONAL_ID_CARD, + 'firstName'=>"test-first-name", + 'businessOperatingName'=>"test-business-operating-name", + 'timeZone'=>'test-time-zone'), $newUser->getProperties()); + // Validate mock \Phake::verify($apiClientMock)->doPut('/rest/v4/users/{user-token}', array('user-token' => 'test-user-token'), $user, array()); @@ -283,7 +304,7 @@ public function testGetUserStatusTransition_noUserToken() { // Run test try { - $client->createUserStatusTransition('',$statusTransition); + $client->getUserStatusTransition('',$statusTransition); $this->fail('HyperwalletArgumentException expected'); } catch (HyperwalletArgumentException $e) { $this->assertEquals('userToken is required!', $e->getMessage()); @@ -310,7 +331,7 @@ public function testCreateUserStatusTransition_allParameters() { $statusTransition = new UserStatusTransition(); $statusTransition->setTransition(UserStatusTransition::TRANSITION_ACTIVATED); - \Phake::when($apiClientMock)->doPost('/rest/v3/users/{user-token}/status-transitions', array('user-token' => 'test-user-token'), $statusTransition, array())->thenReturn(array('success' => 'true')); + \Phake::when($apiClientMock)->doPost('/rest/v4/users/{user-token}/status-transitions', array('user-token' => 'test-user-token'), $statusTransition, array())->thenReturn(array('success' => 'true')); // Run test $newStatusTransition = $client->createUserStatusTransition('test-user-token', $statusTransition); @@ -318,7 +339,7 @@ public function testCreateUserStatusTransition_allParameters() { $this->assertEquals(array('success' => 'true'), $newStatusTransition->getProperties()); // Validate mock - \Phake::verify($apiClientMock)->doPost('/rest/v3/users/{user-token}/status-transitions', array('user-token' => 'test-user-token'), $statusTransition, array()); + \Phake::verify($apiClientMock)->doPost('/rest/v4/users/{user-token}/status-transitions', array('user-token' => 'test-user-token'), $statusTransition, array()); } public function testActivateUser() { @@ -327,7 +348,7 @@ public function testActivateUser() { $apiClientMock = $this->createAndInjectApiClientMock($client); $statusTransition = new UserStatusTransition(); $statusTransition->setTransition(UserStatusTransition::TRANSITION_ACTIVATED); - \Phake::when($apiClientMock)->doPost('/rest/v3/users/{user-token}/status-transitions', array('user-token' => 'test-user-token'), + \Phake::when($apiClientMock)->doPost('/rest/v4/users/{user-token}/status-transitions', array('user-token' => 'test-user-token'), $statusTransition, array())->thenReturn(array('success' => 'true')); // Run test $newStatusTransition = $client->activateUser('test-user-token'); @@ -335,7 +356,7 @@ public function testActivateUser() { $this->assertEquals(array('success' => 'true'), $newStatusTransition->getProperties()); // Validate mock - \Phake::verify($apiClientMock)->doPost('/rest/v3/users/{user-token}/status-transitions', array('user-token' => 'test-user-token'), + \Phake::verify($apiClientMock)->doPost('/rest/v4/users/{user-token}/status-transitions', array('user-token' => 'test-user-token'), $statusTransition, array()); } @@ -346,7 +367,7 @@ public function testDeactivateUser() { $statusTransition = new UserStatusTransition(); $statusTransition->setTransition(UserStatusTransition::TRANSITION_DE_ACTIVATED); - \Phake::when($apiClientMock)->doPost('/rest/v3/users/{user-token}/status-transitions', array('user-token' => 'test-user-token'), + \Phake::when($apiClientMock)->doPost('/rest/v4/users/{user-token}/status-transitions', array('user-token' => 'test-user-token'), $statusTransition, array())->thenReturn(array('success' => 'true')); // Run test $newStatusTransition = $client->deactivateUser('test-user-token'); @@ -354,7 +375,7 @@ public function testDeactivateUser() { $this->assertEquals(array('success' => 'true'), $newStatusTransition->getProperties()); // Validate mock - \Phake::verify($apiClientMock)->doPost('/rest/v3/users/{user-token}/status-transitions', array('user-token' => 'test-user-token'), + \Phake::verify($apiClientMock)->doPost('/rest/v4/users/{user-token}/status-transitions', array('user-token' => 'test-user-token'), $statusTransition, array()); } @@ -365,7 +386,7 @@ public function testLockUser() { $statusTransition = new UserStatusTransition(); $statusTransition->setTransition(UserStatusTransition::TRANSITION_LOCKED); - \Phake::when($apiClientMock)->doPost('/rest/v3/users/{user-token}/status-transitions', array('user-token' => 'test-user-token'), + \Phake::when($apiClientMock)->doPost('/rest/v4/users/{user-token}/status-transitions', array('user-token' => 'test-user-token'), $statusTransition, array())->thenReturn(array('success' => 'true')); // Run test $newStatusTransition = $client->lockUser('test-user-token'); @@ -373,7 +394,7 @@ public function testLockUser() { $this->assertEquals(array('success' => 'true'), $newStatusTransition->getProperties()); // Validate mock - \Phake::verify($apiClientMock)->doPost('/rest/v3/users/{user-token}/status-transitions', array('user-token' => 'test-user-token'), + \Phake::verify($apiClientMock)->doPost('/rest/v4/users/{user-token}/status-transitions', array('user-token' => 'test-user-token'), $statusTransition, array()); } @@ -384,7 +405,7 @@ public function testFreezeUser() { $statusTransition = new UserStatusTransition(); $statusTransition->setTransition(UserStatusTransition::TRANSITION_FROZEN); - \Phake::when($apiClientMock)->doPost('/rest/v3/users/{user-token}/status-transitions', array('user-token' => 'test-user-token'), + \Phake::when($apiClientMock)->doPost('/rest/v4/users/{user-token}/status-transitions', array('user-token' => 'test-user-token'), $statusTransition, array())->thenReturn(array('success' => 'true')); // Run test $newStatusTransition = $client->freezeUser('test-user-token'); @@ -392,7 +413,7 @@ public function testFreezeUser() { $this->assertEquals(array('success' => 'true'), $newStatusTransition->getProperties()); // Validate mock - \Phake::verify($apiClientMock)->doPost('/rest/v3/users/{user-token}/status-transitions', array('user-token' => 'test-user-token'), + \Phake::verify($apiClientMock)->doPost('/rest/v4/users/{user-token}/status-transitions', array('user-token' => 'test-user-token'), $statusTransition, array()); } @@ -403,7 +424,7 @@ public function testPreactivateUser() { $statusTransition = new UserStatusTransition(); $statusTransition->setTransition(UserStatusTransition::TRANSITION_PRE_ACTIVATED); - \Phake::when($apiClientMock)->doPost('/rest/v3/users/{user-token}/status-transitions', array('user-token' => 'test-user-token'), + \Phake::when($apiClientMock)->doPost('/rest/v4/users/{user-token}/status-transitions', array('user-token' => 'test-user-token'), $statusTransition, array())->thenReturn(array('success' => 'true')); // Run test $newStatusTransition = $client->preactivateUser('test-user-token'); @@ -411,7 +432,7 @@ public function testPreactivateUser() { $this->assertEquals(array('success' => 'true'), $newStatusTransition->getProperties()); // Validate mock - \Phake::verify($apiClientMock)->doPost('/rest/v3/users/{user-token}/status-transitions', array('user-token' => 'test-user-token'), + \Phake::verify($apiClientMock)->doPost('/rest/v4/users/{user-token}/status-transitions', array('user-token' => 'test-user-token'), $statusTransition, array()); } @@ -2997,7 +3018,6 @@ public function testListBalancesForUser_noParameters() { $this->assertEquals(1, $balanceList->getLimit()); $this->assertEquals(false, $balanceList->getHasNextPage()); $this->assertEquals(false, $balanceList->getHasPreviousPage()); - $this->assertEquals('links', $balanceList->getLinks()); // Validate mock \Phake::verify($apiClientMock)->doGet('/rest/v4/users/{user-token}/balances', array('user-token' => 'test-user-token'), array()); @@ -3017,7 +3037,6 @@ public function testListBalancesForUser_withParameters() { $this->assertEquals(1, $balanceList->getLimit()); $this->assertEquals(false, $balanceList->getHasNextPage()); $this->assertEquals(false, $balanceList->getHasPreviousPage()); - $this->assertEquals('links', $balanceList->getLinks()); $this->assertEquals(array('success' => 'true'), $balanceList[0]->getProperties()); @@ -3077,7 +3096,6 @@ public function testListBalancesForPrepaidCard_noParameters() { $this->assertEquals(1, $balanceList->getLimit()); $this->assertEquals(false, $balanceList->getHasNextPage()); $this->assertEquals(false, $balanceList->getHasPreviousPage()); - $this->assertEquals('links', $balanceList->getLinks()); // Validate mock \Phake::verify($apiClientMock)->doGet('/rest/v4/users/{user-token}/prepaid-cards/{prepaid-card-token}/balances', array('user-token' => 'test-user-token', 'prepaid-card-token' => 'test-prepaid-card-token'), array()); @@ -3097,7 +3115,6 @@ public function testListBalancesForPrepaidCard_withParameters() { $this->assertEquals(1, $balanceList->getLimit()); $this->assertEquals(false, $balanceList->getHasNextPage()); $this->assertEquals(false, $balanceList->getHasPreviousPage()); - $this->assertEquals('links', $balanceList->getLinks()); $this->assertEquals(array('success' => 'true'), $balanceList[0]->getProperties()); @@ -3145,7 +3162,6 @@ public function testListBalancesForAccount_noParameters() { $this->assertEquals(1, $balanceList->getLimit()); $this->assertEquals(false, $balanceList->getHasNextPage()); $this->assertEquals(false, $balanceList->getHasPreviousPage()); - $this->assertEquals('links', $balanceList->getLinks()); // Validate mock \Phake::verify($apiClientMock)->doGet('/rest/v4/programs/{program-token}/accounts/{account-token}/balances', array('program-token' => 'test-program-token', 'account-token' => 'test-account-token'), array()); @@ -3165,7 +3181,6 @@ public function testListBalancesForAccount_withParameters() { $this->assertEquals(1, $balanceList->getLimit()); $this->assertEquals(false, $balanceList->getHasNextPage()); $this->assertEquals(false, $balanceList->getHasPreviousPage()); - $this->assertEquals('links', $balanceList->getLinks()); $this->assertEquals(array('success' => 'true'), $balanceList[0]->getProperties()); @@ -4068,8 +4083,8 @@ public function testUpdateVerificationStatus_allParameters() { $client = new Hyperwallet('test-username', 'test-password'); $apiClientMock = $this->createAndInjectApiClientMock($client); $user = new user(array('verificationStatus'=> User::VERIFICATION_STATUS_REQUESTED)); - \Phake::when($apiClientMock)->doPut('/rest/v3/users/{user-token}', array('user-token' => 'test-user-token'), $user, array())->thenReturn(array("status"=> User::STATUS_PRE_ACTIVATED, 'verificationStatus'=> User::VERIFICATION_STATUS_REQUIRED)); - \Phake::when($apiClientMock)->doGet('/rest/v3/users/{user-token}', array('user-token' => 'test-user-token'), array())->thenReturn(array("status"=> User::STATUS_PRE_ACTIVATED, 'verificationStatus'=> User::VERIFICATION_STATUS_REQUIRED)); + \Phake::when($apiClientMock)->doPut('/rest/v4/users/{user-token}', array('user-token' => 'test-user-token'), $user, array())->thenReturn(array("status"=> User::STATUS_PRE_ACTIVATED, 'verificationStatus'=> User::VERIFICATION_STATUS_REQUIRED)); + \Phake::when($apiClientMock)->doGet('/rest/v4/users/{user-token}', array('user-token' => 'test-user-token'), array())->thenReturn(array("status"=> User::STATUS_PRE_ACTIVATED, 'verificationStatus'=> User::VERIFICATION_STATUS_REQUIRED)); // Run test try { @@ -4080,7 +4095,7 @@ public function testUpdateVerificationStatus_allParameters() { $this->assertNotNull($responseUser); $this->assertEquals('REQUIRED', $responseUser->getVerificationStatus()); // Validate mock - \Phake::verify($apiClientMock)->doPut('/rest/v3/users/{user-token}', array('user-token' => 'test-user-token'), $user, array()); + \Phake::verify($apiClientMock)->doPut('/rest/v4/users/{user-token}', array('user-token' => 'test-user-token'), $user, array()); } @@ -5006,4 +5021,63 @@ public function testuploadDocumentsForBusinessStakeholder() { // Validate mock \Phake::verify($apiClientMock)->putMultipartData('/rest/v4/users/{user-token}/business-stakeholders/{business-token}', array('user-token' => $userToken,'business-token' => $businessToken), $options); } + + //-------------------------------------- + // List Transfer Methods + //-------------------------------------- + + public function testListTransferMethods_noUserToken() { + // Setup + $client = new Hyperwallet('test-username', 'test-password'); + + // Run test + try { + $client->listTransferMethods(''); + $this->fail('HyperwalletArgumentException expected'); + } catch (HyperwalletArgumentException $e) { + $this->assertEquals('userToken is required!', $e->getMessage()); + } + } + + public function testListTransferMethods_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}/transfer-methods', array('user-token' => 'test-user-token'), array())->thenReturn(array('limit' => 1,'hasNextPage' => false ,'hasPreviousPage' => false,'links' => 'links', 'data' => array())); + + // Run test + $listTransferMethods = $client->listTransferMethods('test-user-token'); + $this->assertNotNull($listTransferMethods); + $this->assertCount(0, $listTransferMethods); + $this->assertEquals(1, $listTransferMethods->getLimit()); + $this->assertEquals(false, $listTransferMethods->getHasNextPage()); + $this->assertEquals(false, $listTransferMethods->getHasPreviousPage()); + $this->assertEquals('links', $listTransferMethods->getLinks()); + + // Validate mock + \Phake::verify($apiClientMock)->doGet('/rest/v4/users/{user-token}/transfer-methods', array('user-token' => 'test-user-token'), array()); + } + + public function testListTransferMethods_withParameters() { + // Setup + $client = new Hyperwallet('test-username', 'test-password', 'test-program-token'); + $apiClientMock = $this->createAndInjectApiClientMock($client); + + \Phake::when($apiClientMock)->doGet('/rest/v4/users/{user-token}/transfer-methods', array('user-token' => 'test-user-token'), array('type'=>TransferMethod::TYPE_PREPAID_CARD))->thenReturn(array('limit' => 1,'hasNextPage' => false ,'hasPreviousPage' => false,'links' => 'links', 'data' => array(array('success' => 'true')))); + + // Run test + $listTransferMethods = $client->listTransferMethods('test-user-token', array('type'=>TransferMethod::TYPE_PREPAID_CARD)); + $this->assertNotNull($listTransferMethods); + $this->assertCount(1, $listTransferMethods); + $this->assertEquals(1, $listTransferMethods->getLimit()); + $this->assertEquals(false, $listTransferMethods->getHasNextPage()); + $this->assertEquals(false, $listTransferMethods->getHasPreviousPage()); + $this->assertEquals('links', $listTransferMethods->getLinks()); + + $this->assertEquals(array('success' => 'true'), $listTransferMethods[0]->getProperties()); + + // 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)); + } } diff --git a/tests/Hyperwallet/Tests/Util/HyperwalletEncryptionTest.php b/tests/Hyperwallet/Tests/Util/HyperwalletEncryptionTest.php index bb4261d5..f92e4d36 100644 --- a/tests/Hyperwallet/Tests/Util/HyperwalletEncryptionTest.php +++ b/tests/Hyperwallet/Tests/Util/HyperwalletEncryptionTest.php @@ -1,5 +1,5 @@