Skip to content

Commit dc2bbdd

Browse files
committed
Add Get Client Token endpoint
1 parent 3e6c240 commit dc2bbdd

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
@@ -318,6 +318,38 @@ public function testListUserStatusTransitions_withParameters() {
318318
\Phake::verify($apiClientMock)->doGet('/rest/v3/users/{user-token}/status-transitions', array('user-token' => 'test-user-token'), array('test' => 'value'));
319319
}
320320

321+
//--------------------------------------
322+
// Client Token
323+
//--------------------------------------
324+
325+
public function testGetClientToken_noUserToken() {
326+
// Setup
327+
$client = new Hyperwallet('test-username', 'test-password');
328+
329+
try {
330+
$client->getClientToken('');
331+
$this->fail('HyperwalletArgumentException expected');
332+
} catch (HyperwalletArgumentException $e) {
333+
$this->assertEquals('userToken is required!', $e->getMessage());
334+
}
335+
}
336+
337+
public function testGetClientToken_allParameters() {
338+
// Setup data
339+
$client = new Hyperwallet('test-username', 'test-password', 'test-program-token');
340+
$apiClientMock = $this->createAndInjectApiClientMock($client);
341+
342+
\Phake::when($apiClientMock)->doPost('/rest/v3/users/{user-token}/client-token', array('user-token' => 'test-user-token'), null, array())->thenReturn(array('value' => 'true'));
343+
344+
// Run test
345+
$clientToken = $client->getClientToken('test-user-token');
346+
$this->assertNotNull($clientToken);
347+
$this->assertEquals(array('value' => 'true'), $clientToken->getProperties());
348+
349+
// Validate mock
350+
\Phake::verify($apiClientMock)->doPost('/rest/v3/users/{user-token}/client-token', array('user-token' => 'test-user-token'), null, array());
351+
}
352+
321353
//--------------------------------------
322354
// Paper Checks
323355
//--------------------------------------
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)