Skip to content

Commit

Permalink
Merge pull request #52 from hyperwallet/feature/HW-67136-V4-Transfer-…
Browse files Browse the repository at this point in the history
…Methods

added list of transfer methods
  • Loading branch information
akalichety-hw committed Oct 21, 2020
2 parents 3b0fe91 + 6d67371 commit ab887b4
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/Hyperwallet/Hyperwallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -2339,10 +2339,6 @@ public function uploadDocumentsForBusinessStakeholder($userToken, $businessToken
return new BusinessStakeholder($body);
}

//--------------------------------------
// Business Stakeholders
//--------------------------------------

/**
* Create a Business Stakeholder
*
Expand All @@ -2364,6 +2360,7 @@ public function createBusinessStakeholder($userToken,$businessStakeholder) {
*
* @param Business Stakeholder $BusinessStakeholder The Business Stakeholder
* @return BusinessStakeholder
*
* @throws HyperwalletArgumentException
* @throws HyperwalletApiException
Expand All @@ -2387,6 +2384,7 @@ public function updateBusinessStakeholder($userToken, $businessToken, $businessS
*
* @throws HyperwalletApiException
*/

public function listBusinessStakeholders($userToken , $options) {
if (empty($userToken)) {
throw new HyperwalletArgumentException('userToken is required!');
Expand All @@ -2404,4 +2402,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);
});
}
}
58 changes: 58 additions & 0 deletions tests/Hyperwallet/Tests/HyperwalletTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4982,6 +4982,64 @@ 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));
}
}

0 comments on commit ab887b4

Please sign in to comment.