1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Monobank\Request; |
6
|
|
|
|
7
|
|
|
use GuzzleHttp\Psr7\Request; |
8
|
|
|
use Monobank\Response\ClientInfoResponse; |
9
|
|
|
use Monobank\Response\StatementResponse; |
10
|
|
|
|
11
|
|
|
final class Personal extends AbstractRequest |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @throws \Monobank\Exception\InvalidAccountException |
15
|
|
|
* @throws \Monobank\Exception\InternalErrorException |
16
|
|
|
* @throws \Monobank\Exception\MonobankException |
17
|
|
|
* @throws \Monobank\Exception\TooManyRequestsException |
18
|
|
|
* @throws \Monobank\Exception\UnknownTokenException |
19
|
|
|
*/ |
20
|
|
|
public function getClientInfo(): ClientInfoResponse |
21
|
|
|
{ |
22
|
|
|
$httpResponse = $this->makeRequest(new Request('GET', '/personal/client-info')); |
23
|
|
|
|
24
|
|
|
return ClientInfoResponse::fromResponse($httpResponse); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @throws \Monobank\Exception\InvalidAccountException |
29
|
|
|
* @throws \Monobank\Exception\InternalErrorException |
30
|
|
|
* @throws \Monobank\Exception\MonobankException |
31
|
|
|
* @throws \Monobank\Exception\TooManyRequestsException |
32
|
|
|
* @throws \Monobank\Exception\UnknownTokenException |
33
|
|
|
* @throws \Monobank\Exception\InvalidAccountException |
34
|
|
|
*/ |
35
|
|
|
public function getStatement(string $account, \DateTime $from, \DateTime $to = null): StatementResponse |
36
|
|
|
{ |
37
|
|
|
$httpResponse = $this->makeRequest( |
38
|
|
|
new Request( |
39
|
|
|
'GET', |
40
|
|
|
sprintf('/personal/statement/%s/%s/%s', $account, $from->getTimestamp(), $to ? $to->getTimestamp() : '') |
41
|
|
|
) |
42
|
|
|
); |
43
|
|
|
|
44
|
|
|
return StatementResponse::fromResponse($httpResponse); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @throws \Monobank\Exception\InternalErrorException |
49
|
|
|
* @throws \Monobank\Exception\MonobankException |
50
|
|
|
* @throws \Monobank\Exception\TooManyRequestsException |
51
|
|
|
* @throws \Monobank\Exception\UnknownTokenException |
52
|
|
|
*/ |
53
|
|
|
public function setWebhook(string $url): bool |
54
|
|
|
{ |
55
|
|
|
$httpResponse = $this->makeRequest( |
56
|
|
|
new Request( |
57
|
|
|
'POST', |
58
|
|
|
'/personal/webhook', |
59
|
|
|
['Content-type' => 'application/json'], |
60
|
|
|
json_encode(['webHookUrl' => $url]) |
61
|
|
|
) |
62
|
|
|
); |
63
|
|
|
|
64
|
|
|
return ($httpResponse['status'] ?? null) === 'ok'; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @throws \Monobank\Exception\InternalErrorException |
69
|
|
|
* @throws \Monobank\Exception\MonobankException |
70
|
|
|
* @throws \Monobank\Exception\TooManyRequestsException |
71
|
|
|
* @throws \Monobank\Exception\UnknownTokenException |
72
|
|
|
*/ |
73
|
|
|
public function deleteWebhook(): bool |
74
|
|
|
{ |
75
|
|
|
return $this->setWebhook(''); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|