1 | <?php |
||
2 | /** |
||
3 | * ListPaymentRequest.php |
||
4 | * Copyright (c) 2018 [email protected] |
||
5 | * |
||
6 | * This file is part of Firefly III. |
||
7 | * |
||
8 | * Firefly III is free software: you can redistribute it and/or modify |
||
9 | * it under the terms of the GNU General Public License as published by |
||
10 | * the Free Software Foundation, either version 3 of the License, or |
||
11 | * (at your option) any later version. |
||
12 | * |
||
13 | * Firefly III is distributed in the hope that it will be useful, |
||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
16 | * GNU General Public License for more details. |
||
17 | * |
||
18 | * You should have received a copy of the GNU General Public License |
||
19 | * along with Firefly III. If not, see <http://www.gnu.org/licenses/>. |
||
20 | */ |
||
21 | |||
22 | declare(strict_types=1); |
||
23 | |||
24 | namespace FireflyIII\Services\Bunq\Request; |
||
25 | |||
26 | use FireflyIII\Services\Bunq\Object\MonetaryAccountBank; |
||
27 | use FireflyIII\Services\Bunq\Object\Payment; |
||
28 | use FireflyIII\Services\Bunq\Token\SessionToken; |
||
29 | use Illuminate\Support\Collection; |
||
30 | |||
31 | |||
32 | /** |
||
33 | * Class ListPaymentRequest |
||
34 | */ |
||
35 | class ListPaymentRequest extends BunqRequest |
||
36 | { |
||
37 | |||
38 | /** @var MonetaryAccountBank */ |
||
39 | private $account; |
||
40 | /** @var Collection */ |
||
41 | private $payments; |
||
42 | /** @var SessionToken */ |
||
43 | private $sessionToken; |
||
44 | /** @var int */ |
||
45 | private $userId = 0; |
||
46 | |||
47 | /** |
||
48 | * TODO support pagination. |
||
0 ignored issues
–
show
Coding Style
Best Practice
introduced
by
Loading history...
|
|||
49 | * TODO impose limits on import. |
||
0 ignored issues
–
show
|
|||
50 | * |
||
51 | * @throws \FireflyIII\Exceptions\FireflyException |
||
52 | */ |
||
53 | public function call(): void |
||
54 | { |
||
55 | $break = false; |
||
56 | $this->payments = new Collection; |
||
57 | $uri = sprintf('user/%d/monetary-account/%d/payment', $this->userId, $this->account->getId()); |
||
58 | $headers = $this->getDefaultHeaders(); |
||
59 | $headers['X-Bunq-Client-Authentication'] = $this->sessionToken->getToken(); |
||
60 | while ($break === false) { |
||
61 | $response = $this->sendSignedBunqGet($uri, [], $headers); |
||
62 | $uri = str_replace('/v1/', '', $response['Pagination']['future_url']); |
||
63 | $break = true; |
||
64 | |||
65 | // create payment objects: |
||
66 | $raw = $this->getArrayFromResponse('Payment', $response); |
||
67 | foreach ($raw as $entry) { |
||
68 | $payment = new Payment($entry); |
||
69 | $this->payments->push($payment); |
||
70 | } |
||
71 | } |
||
72 | |||
73 | return; |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * @return Collection |
||
78 | */ |
||
79 | public function getPayments(): Collection |
||
80 | { |
||
81 | return $this->payments; |
||
82 | } |
||
83 | |||
84 | |||
85 | /** |
||
86 | * @param MonetaryAccountBank $account |
||
87 | */ |
||
88 | public function setAccount(MonetaryAccountBank $account): void |
||
89 | { |
||
90 | $this->account = $account; |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * @param SessionToken $sessionToken |
||
95 | */ |
||
96 | public function setSessionToken(SessionToken $sessionToken): void |
||
97 | { |
||
98 | $this->sessionToken = $sessionToken; |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * @param int $userId |
||
103 | */ |
||
104 | public function setUserId(int $userId): void |
||
105 | { |
||
106 | $this->userId = $userId; |
||
107 | } |
||
108 | } |
||
109 |