1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of byrokrat\autogiro. |
5
|
|
|
* |
6
|
|
|
* byrokrat\autogiro is free software: you can redistribute it and/or |
7
|
|
|
* modify it under the terms of the GNU General Public License as published |
8
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
9
|
|
|
* (at your option) any later version. |
10
|
|
|
* |
11
|
|
|
* byrokrat\autogiro is distributed in the hope that it will be useful, |
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14
|
|
|
* GNU General Public License for more details. |
15
|
|
|
* |
16
|
|
|
* You should have received a copy of the GNU General Public License |
17
|
|
|
* along with byrokrat\autogiro. If not, see <http://www.gnu.org/licenses/>. |
18
|
|
|
* |
19
|
|
|
* Copyright 2016-21 Hannes Forsgård |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
declare(strict_types=1); |
23
|
|
|
|
24
|
|
|
namespace byrokrat\autogiro\Writer; |
25
|
|
|
|
26
|
|
|
use byrokrat\autogiro\Intervals; |
27
|
|
|
use byrokrat\banking\AccountNumber; |
28
|
|
|
use byrokrat\id\IdInterface; |
29
|
|
|
use Money\Money; |
30
|
|
|
|
31
|
|
|
final class Writer implements WriterInterface |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* @var TreeBuilder Helper used when building trees |
35
|
|
|
*/ |
36
|
|
|
private $treeBuilder; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var PrintingVisitor Helper used when generating content |
40
|
|
|
*/ |
41
|
|
|
private $printer; |
42
|
|
|
|
43
|
|
|
public function __construct(TreeBuilder $treeBuilder, PrintingVisitor $printer) |
44
|
|
|
{ |
45
|
|
|
$this->treeBuilder = $treeBuilder; |
46
|
|
|
$this->printer = $printer; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function getContent(): string |
50
|
|
|
{ |
51
|
|
|
$tree = $this->treeBuilder->buildTree(); |
52
|
|
|
$output = new Output(); |
53
|
|
|
$this->printer->setOutput($output); |
54
|
|
|
$tree->accept($this->printer); |
55
|
|
|
|
56
|
|
|
return rtrim($output->getContent(), "\r\n"); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function reset(): void |
60
|
|
|
{ |
61
|
|
|
$this->treeBuilder->reset(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function addNewMandate(string $payerNr, AccountNumber $account, IdInterface $id): void |
65
|
|
|
{ |
66
|
|
|
$this->treeBuilder->addCreateMandateRequest($payerNr, $account, $id); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function deleteMandate(string $payerNr): void |
70
|
|
|
{ |
71
|
|
|
$this->treeBuilder->addDeleteMandateRequest($payerNr); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function acceptDigitalMandate(string $payerNr): void |
75
|
|
|
{ |
76
|
|
|
$this->treeBuilder->addAcceptDigitalMandateRequest($payerNr); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function rejectDigitalMandate(string $payerNr): void |
80
|
|
|
{ |
81
|
|
|
$this->treeBuilder->addRejectDigitalMandateRequest($payerNr); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function updateMandate(string $payerNr, string $newPayerNr): void |
85
|
|
|
{ |
86
|
|
|
$this->treeBuilder->addUpdateMandateRequest($payerNr, $newPayerNr); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function addPayment( |
90
|
|
|
string $payerNr, |
91
|
|
|
Money $amount, |
92
|
|
|
\DateTimeInterface $date, |
93
|
|
|
string $ref = '', |
94
|
|
|
string $interval = Intervals::INTERVAL_ONCE, |
95
|
|
|
int $repetitions = 0 |
96
|
|
|
): void { |
97
|
|
|
$this->treeBuilder->addIncomingPaymentRequest($payerNr, $amount, $date, $ref, $interval, $repetitions); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function addMonthlyPayment(string $payerNr, Money $amount, \DateTimeInterface $date, string $ref = ''): void |
101
|
|
|
{ |
102
|
|
|
$this->addPayment($payerNr, $amount, $date, $ref, Intervals::INTERVAL_MONTHLY_ON_DATE, 0); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function addImmediatePayment(string $payerNr, Money $amount, string $ref = ''): void |
106
|
|
|
{ |
107
|
|
|
$this->treeBuilder->addImmediateIncomingPaymentRequest($payerNr, $amount, $ref); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function addOutgoingPayment( |
111
|
|
|
string $payerNr, |
112
|
|
|
Money $amount, |
113
|
|
|
\DateTimeInterface $date, |
114
|
|
|
string $ref = '', |
115
|
|
|
string $interval = Intervals::INTERVAL_ONCE, |
116
|
|
|
int $repetitions = 0 |
117
|
|
|
): void { |
118
|
|
|
$this->treeBuilder->addOutgoingPaymentRequest($payerNr, $amount, $date, $ref, $interval, $repetitions); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function addImmediateOutgoingPayment(string $payerNr, Money $amount, string $ref = ''): void |
122
|
|
|
{ |
123
|
|
|
$this->treeBuilder->addImmediateOutgoingPaymentRequest($payerNr, $amount, $ref); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function deletePayments(string $payerNr): void |
127
|
|
|
{ |
128
|
|
|
$this->treeBuilder->addDeletePaymentRequest($payerNr); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|