|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Service\Hyperwallet; |
|
4
|
|
|
|
|
5
|
|
|
use Exception; |
|
6
|
|
|
use DateTime; |
|
7
|
|
|
use Hyperwallet\Exception\HyperwalletApiException; |
|
8
|
|
|
use Hyperwallet\Model\AuthenticationToken; |
|
9
|
|
|
use Hyperwallet\Model\User; |
|
10
|
|
|
use Hyperwallet\Response\ListResponse; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class UserService |
|
14
|
|
|
* @package App\Service\Hyperwallet |
|
15
|
|
|
*/ |
|
16
|
|
|
class UserService extends AbstractHyperwalletService |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @return ListResponse |
|
20
|
|
|
* |
|
21
|
|
|
* @throws HyperwalletApiException |
|
22
|
|
|
*/ |
|
23
|
|
|
public function list(): ListResponse |
|
24
|
|
|
{ |
|
25
|
|
|
return $this->client->listUsers([ |
|
26
|
|
|
'status' => ['ACTIVATED', 'PRE_ACTIVATED'], |
|
27
|
|
|
]); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param array $userParameters |
|
32
|
|
|
* @return User | Exception |
|
33
|
|
|
*/ |
|
34
|
|
|
public function create(array $userParameters) |
|
35
|
|
|
{ |
|
36
|
|
|
try { |
|
37
|
|
|
$user = new User($userParameters); |
|
38
|
|
|
return $this->client->createUser($user); |
|
39
|
|
|
} catch (Exception $exception) { |
|
40
|
|
|
return $exception; |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param array $userParameters |
|
46
|
|
|
* @return User | Exception |
|
47
|
|
|
*/ |
|
48
|
|
|
public function update(array $userParameters) |
|
49
|
|
|
{ |
|
50
|
|
|
try { |
|
51
|
|
|
$user = new User($userParameters); |
|
52
|
|
|
$user |
|
53
|
|
|
->setFirstName($userParameters['firstName']) |
|
54
|
|
|
->setLastName($userParameters['lastName']) |
|
55
|
|
|
->setEmail($userParameters['email']) |
|
56
|
|
|
->setDateOfBirth(new Datetime($userParameters['dateOfBirth'])) |
|
57
|
|
|
->setClientUserId($userParameters['clientUserId']) |
|
58
|
|
|
->setLanguage($userParameters['language']) |
|
59
|
|
|
; |
|
60
|
|
|
return $this->client->updateUser($user); |
|
61
|
|
|
} catch (Exception $exception) { |
|
62
|
|
|
return $exception; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param string $userToken |
|
68
|
|
|
* @return Exception|User |
|
69
|
|
|
*/ |
|
70
|
|
|
public function get(string $userToken) |
|
71
|
|
|
{ |
|
72
|
|
|
try { |
|
73
|
|
|
return $this->client->getUser($userToken); |
|
74
|
|
|
} catch (Exception $exception) { |
|
75
|
|
|
return $exception; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param string $userToken |
|
81
|
|
|
* @return Exception|ListResponse |
|
82
|
|
|
*/ |
|
83
|
|
|
public function listTransferMethods(string $userToken) |
|
84
|
|
|
{ |
|
85
|
|
|
try { |
|
86
|
|
|
return $this->client->listTransferMethods($userToken); |
|
87
|
|
|
} catch (Exception $exception) { |
|
88
|
|
|
return $exception; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @param string $userToken |
|
94
|
|
|
* @return Exception|ListResponse |
|
95
|
|
|
*/ |
|
96
|
|
|
public function listBalances(string $userToken) |
|
97
|
|
|
{ |
|
98
|
|
|
try { |
|
99
|
|
|
return $this->client->listBalancesForUser($userToken); |
|
100
|
|
|
} catch (Exception $exception) { |
|
101
|
|
|
return $exception; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @param string $userToken |
|
107
|
|
|
* @return Exception|AuthenticationToken |
|
108
|
|
|
*/ |
|
109
|
|
|
public function getAuthenticationToken(string $userToken) |
|
110
|
|
|
{ |
|
111
|
|
|
try { |
|
112
|
|
|
return $this->client->getAuthenticationToken($userToken); |
|
113
|
|
|
} catch (Exception $exception) { |
|
114
|
|
|
return $exception; |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|