1
|
|
|
<?php declare(strict_types = 1); |
2
|
|
|
|
3
|
|
|
namespace Link0\Bunq\Domain; |
4
|
|
|
|
5
|
|
|
use DateTimeImmutable; |
6
|
|
|
use DateTimeInterface; |
7
|
|
|
use DateTimeZone; |
8
|
|
|
use Money\Currency; |
9
|
|
|
use Money\Money; |
10
|
|
|
|
11
|
|
|
final class MonetaryAccountBank |
12
|
|
|
{ |
13
|
|
|
const STATUS_ACTIVE = 'ACTIVE'; |
14
|
|
|
const STATUS_CANCELLED = 'CANCELLED'; |
15
|
|
|
const STATUS_PENDING_REOPEN = 'PENDING_REOPEN'; |
16
|
|
|
|
17
|
|
|
const SUBSTATUS_REDEMPTION_VOLUNTARY = 'REDEMPTION_VOLUNTARY'; |
18
|
|
|
const SUBSTATUS_NONE = 'NONE'; |
19
|
|
|
const REASON_OTHER = 'OTHER'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var Id |
23
|
|
|
*/ |
24
|
|
|
private $id; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
private $description; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var DateTimeInterface |
33
|
|
|
*/ |
34
|
|
|
private $created; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var DateTimeInterface |
38
|
|
|
*/ |
39
|
|
|
private $updated; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var Id |
43
|
|
|
*/ |
44
|
|
|
private $userId; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var Alias[] |
48
|
|
|
*/ |
49
|
|
|
private $alias; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var Currency |
53
|
|
|
*/ |
54
|
|
|
private $currency; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var Money |
58
|
|
|
*/ |
59
|
|
|
private $balance; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var Money |
63
|
|
|
*/ |
64
|
|
|
private $dailyLimit; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @var Money |
68
|
|
|
*/ |
69
|
|
|
private $dailySpent; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @var NotificationFilter[] |
73
|
|
|
*/ |
74
|
|
|
private $notificationFilters; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Private constructor |
78
|
|
|
*/ |
79
|
|
|
private function __construct(array $monetaryBankAccount) |
80
|
|
|
{ |
81
|
|
|
$timezone = new DateTimeZone('UTC'); |
82
|
|
|
|
83
|
|
|
$this->id = Id::fromInteger(intval($monetaryBankAccount['id'])); |
84
|
|
|
$this->description = $monetaryBankAccount['description']; |
85
|
|
|
$this->created = new DateTimeImmutable($monetaryBankAccount['created'], $timezone); |
86
|
|
|
$this->updated = new DateTimeImmutable($monetaryBankAccount['updated'], $timezone); |
87
|
|
|
$this->userId = Id::fromInteger($monetaryBankAccount['user_id']); |
88
|
|
|
|
89
|
|
|
foreach ($monetaryBankAccount['alias'] as $aliasInfo) { |
90
|
|
|
$this->alias[] = new Alias( |
91
|
|
|
$aliasInfo['type'], |
92
|
|
|
$aliasInfo['value'], |
93
|
|
|
$aliasInfo['name'] |
94
|
|
|
); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
$this->currency = new Currency($monetaryBankAccount['balance']['currency']); |
98
|
|
|
$this->balance = new Money($monetaryBankAccount['balance']['value'] * 100, $this->currency); |
99
|
|
|
$this->dailyLimit = new Money($monetaryBankAccount['daily_limit']['value'] * 100, $this->currency); |
100
|
|
|
$this->dailySpent = new Money($monetaryBankAccount['daily_spent']['value'] * 100, $this->currency); |
101
|
|
|
|
102
|
|
|
foreach ($monetaryBankAccount['notification_filters'] as $notificationFilter) { |
103
|
|
|
$this->notificationFilters[] = NotificationFilter::fromArray($notificationFilter); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param array $monetaryBankAccount |
109
|
|
|
* @return MonetaryAccountBank |
110
|
|
|
*/ |
111
|
|
|
public static function fromArray(array $monetaryBankAccount) |
112
|
|
|
{ |
113
|
|
|
return new self($monetaryBankAccount); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @return Id |
118
|
|
|
*/ |
119
|
|
|
public function id(): Id |
120
|
|
|
{ |
121
|
|
|
return $this->id; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @return string |
126
|
|
|
*/ |
127
|
|
|
public function description(): string |
128
|
|
|
{ |
129
|
|
|
return $this->description; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @return DateTimeInterface |
134
|
|
|
*/ |
135
|
|
|
public function created(): DateTimeInterface |
136
|
|
|
{ |
137
|
|
|
return $this->created; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @return DateTimeInterface |
142
|
|
|
*/ |
143
|
|
|
public function updated(): DateTimeInterface |
144
|
|
|
{ |
145
|
|
|
return $this->updated; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @return Alias[] |
150
|
|
|
*/ |
151
|
|
|
public function alias(): array |
152
|
|
|
{ |
153
|
|
|
return $this->alias; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @return Money |
158
|
|
|
*/ |
159
|
|
|
public function balance(): Money |
160
|
|
|
{ |
161
|
|
|
return $this->balance; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @return Id |
166
|
|
|
*/ |
167
|
|
|
public function userId(): Id |
168
|
|
|
{ |
169
|
|
|
return $this->userId; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @return NotificationFilter[] |
174
|
|
|
*/ |
175
|
|
|
public function notificationFilters() |
176
|
|
|
{ |
177
|
|
|
return $this->notificationFilters; |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|