Skip to content

Commit fe1d9d3

Browse files
author
Peter Joseph Olamit
authored
Merge pull request #13 from akreisman-epam/get-client-token
Add Get Client Token endpoint
2 parents 9ea63bb + dc2bbdd commit fe1d9d3

File tree

5 files changed

+135
-0
lines changed

5 files changed

+135
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Changelog
44
0.2.0 (2018-10-19)
55
-------------------
66

7+
- Added ClientToken endpoint
78
- Added PayPal endpoint
89
- Added transfer endpoint
910
- Added Layer 7 encryption

src/Hyperwallet/Hyperwallet.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Hyperwallet\Model\TransferMethod;
2424
use Hyperwallet\Model\TransferMethodConfiguration;
2525
use Hyperwallet\Model\User;
26+
use Hyperwallet\Model\ClientToken;
2627
use Hyperwallet\Model\UserStatusTransition;
2728
use Hyperwallet\Model\WebhookNotification;
2829
use Hyperwallet\Response\ListResponse;
@@ -184,6 +185,28 @@ public function listUserStatusTransitions($userToken, array $options = array())
184185
});
185186
}
186187

188+
//--------------------------------------
189+
// Client Token
190+
//--------------------------------------
191+
192+
/**
193+
* Get client token
194+
*
195+
* @param $userToken The user token
196+
* @return ClientToken
197+
*
198+
* @throws HyperwalletApiException
199+
*/
200+
public function getClientToken($userToken) {
201+
if (empty($userToken)) {
202+
throw new HyperwalletArgumentException('userToken is required!');
203+
}
204+
$body = $this->client->doPost('/rest/v3/users/{user-token}/client-token', array(
205+
'user-token' => $userToken,
206+
), null, array());
207+
return new ClientToken($body);
208+
}
209+
187210
//--------------------------------------
188211
// Paper Checks
189212
//--------------------------------------
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
namespace Hyperwallet\Model;
3+
4+
/**
5+
* Represents a V3 Client Token
6+
*
7+
* @property string $value The client token value
8+
9+
*
10+
* @package Hyperwallet\Model
11+
*/
12+
13+
class ClientToken extends BaseModel {
14+
15+
/**
16+
* @internal
17+
*
18+
* Read only fields
19+
*
20+
* @var string[]
21+
*/
22+
private static $READ_ONLY_FIELDS = array('value');
23+
24+
/**
25+
* Creates a instance of ClientToken
26+
*
27+
* @param string[] $properties The default properties
28+
*/
29+
public function __construct(array $properties = array()) {
30+
parent::__construct(self::$READ_ONLY_FIELDS, $properties);
31+
}
32+
33+
/**
34+
* Get the client token value
35+
*
36+
* @return string
37+
*/
38+
public function getValue() {
39+
return $this->value;
40+
}
41+
42+
}

tests/Hyperwallet/Tests/HyperwalletTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,38 @@ public function testListUserStatusTransitions_withParameters() {
320320
\Phake::verify($apiClientMock)->doGet('/rest/v3/users/{user-token}/status-transitions', array('user-token' => 'test-user-token'), array('test' => 'value'));
321321
}
322322

323+
//--------------------------------------
324+
// Client Token
325+
//--------------------------------------
326+
327+
public function testGetClientToken_noUserToken() {
328+
// Setup
329+
$client = new Hyperwallet('test-username', 'test-password');
330+
331+
try {
332+
$client->getClientToken('');
333+
$this->fail('HyperwalletArgumentException expected');
334+
} catch (HyperwalletArgumentException $e) {
335+
$this->assertEquals('userToken is required!', $e->getMessage());
336+
}
337+
}
338+
339+
public function testGetClientToken_allParameters() {
340+
// Setup data
341+
$client = new Hyperwallet('test-username', 'test-password', 'test-program-token');
342+
$apiClientMock = $this->createAndInjectApiClientMock($client);
343+
344+
\Phake::when($apiClientMock)->doPost('/rest/v3/users/{user-token}/client-token', array('user-token' => 'test-user-token'), null, array())->thenReturn(array('value' => 'true'));
345+
346+
// Run test
347+
$clientToken = $client->getClientToken('test-user-token');
348+
$this->assertNotNull($clientToken);
349+
$this->assertEquals(array('value' => 'true'), $clientToken->getProperties());
350+
351+
// Validate mock
352+
\Phake::verify($apiClientMock)->doPost('/rest/v3/users/{user-token}/client-token', array('user-token' => 'test-user-token'), null, array());
353+
}
354+
323355
//--------------------------------------
324356
// Paper Checks
325357
//--------------------------------------
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
namespace Hyperwallet\Tests\Model;
3+
4+
class ClientTokenTest extends ModelTestCase {
5+
6+
protected function getModelName() {
7+
return 'ClientToken';
8+
}
9+
10+
/**
11+
* @dataProvider ignoredPropertiesProvider
12+
*
13+
* @param string $property The property to look for
14+
*/
15+
public function testGettersForIgnoredProperties($property) {
16+
$this->performGettersForIgnoredPropertiesTest($property);
17+
}
18+
19+
/**
20+
* @dataProvider propertiesProvider
21+
*
22+
* @param string $property The property to look for
23+
*/
24+
public function testGetterReturnValueIsSet($property) {
25+
$this->performGetterReturnValueIsSetTest($property);
26+
}
27+
28+
/**
29+
* @dataProvider propertiesProvider
30+
*
31+
* @param string $property The property to look for
32+
*/
33+
public function testGetterReturnValueIsNotSet($property) {
34+
$this->performGetterReturnValueIsNotSetTest($property);
35+
}
36+
37+
}

0 commit comments

Comments
 (0)