1 | <?php |
||
13 | abstract class CreditTransfer |
||
14 | { |
||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $instructionId; |
||
19 | |||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $endToEndId; |
||
24 | |||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $creditorName; |
||
29 | |||
30 | /** |
||
31 | * @var PostalAddressInterface|null |
||
32 | */ |
||
33 | protected $creditorAddress; |
||
34 | |||
35 | /** |
||
36 | * @var Money |
||
37 | */ |
||
38 | protected $amount; |
||
39 | |||
40 | /** |
||
41 | * @var string|null |
||
42 | */ |
||
43 | protected $localInstrument; |
||
44 | |||
45 | /** |
||
46 | * @var string|null |
||
47 | */ |
||
48 | protected $serviceLevel; |
||
49 | |||
50 | /** |
||
51 | * @var PurposeCode|null |
||
52 | */ |
||
53 | protected $purpose; |
||
54 | |||
55 | /** |
||
56 | * @var string|null |
||
57 | */ |
||
58 | protected $remittanceInformation; |
||
59 | |||
60 | /** |
||
61 | * Constructor |
||
62 | * |
||
63 | * @param string $instructionId Identifier of the instruction (should be unique within the message) |
||
64 | * @param string $endToEndId End-To-End Identifier of the instruction (passed unchanged along the complete processing chain) |
||
65 | * @param Money $amount Amount of money to be transferred |
||
66 | * @param string $creditorName Name of the creditor |
||
67 | * @param PostalAddressInterface|null $creditorAddress Address of the creditor |
||
68 | * |
||
69 | * @throws \InvalidArgumentException When any of the inputs contain invalid characters or are too long. |
||
70 | */ |
||
71 | 3 | public function __construct($instructionId, $endToEndId, Money $amount, $creditorName, PostalAddressInterface $creditorAddress = null) |
|
72 | { |
||
73 | 3 | $this->instructionId = Text::assertIdentifier($instructionId); |
|
74 | 3 | $this->endToEndId = Text::assertIdentifier($endToEndId); |
|
75 | 3 | $this->amount = $amount; |
|
76 | 3 | $this->creditorName = Text::assert($creditorName, 70); |
|
77 | 3 | $this->creditorAddress = $creditorAddress; |
|
78 | 3 | } |
|
79 | |||
80 | /** |
||
81 | * Gets the local instrument |
||
82 | * |
||
83 | * @return string|null The local instrument |
||
84 | */ |
||
85 | 2 | public function getLocalInstrument() |
|
86 | { |
||
87 | 2 | return $this->localInstrument; |
|
88 | } |
||
89 | |||
90 | /** |
||
91 | * Gets the service level |
||
92 | * |
||
93 | * @return string|null The service level |
||
94 | */ |
||
95 | 2 | public function getServiceLevel() |
|
96 | { |
||
97 | 2 | return $this->serviceLevel; |
|
98 | } |
||
99 | |||
100 | /** |
||
101 | * Sets the purpose of the payment |
||
102 | * |
||
103 | * @param PurposeCode $purpose The purpose |
||
104 | * |
||
105 | * @return CreditTransfer This credit transfer |
||
106 | */ |
||
107 | 3 | public function setPurpose(PurposeCode $purpose) |
|
108 | { |
||
109 | 3 | $this->purpose = $purpose; |
|
110 | |||
111 | 3 | return $this; |
|
112 | } |
||
113 | |||
114 | /** |
||
115 | * Sets the unstructured remittance information |
||
116 | * |
||
117 | * @param string|null $remittanceInformation |
||
118 | * |
||
119 | * @return CreditTransfer This credit transfer |
||
120 | * |
||
121 | * @throws \InvalidArgumentException When the information contains invalid characters or is too long. |
||
122 | */ |
||
123 | public function setRemittanceInformation($remittanceInformation) |
||
124 | { |
||
125 | $this->remittanceInformation = Text::assertOptional($remittanceInformation, 140); |
||
126 | |||
127 | return $this; |
||
128 | } |
||
129 | |||
130 | /** |
||
131 | * Gets the instructed amount of this transaction |
||
132 | * |
||
133 | * @return Money The instructed amount |
||
134 | */ |
||
135 | 2 | public function getAmount() |
|
136 | { |
||
137 | 2 | return $this->amount; |
|
138 | } |
||
139 | |||
140 | /** |
||
141 | * Builds a DOM tree of this transaction |
||
142 | * |
||
143 | * @param \DOMDocument $doc |
||
144 | * @param PaymentInformation $paymentInformation Information on B-level |
||
145 | * |
||
146 | * @return \DOMElement The built DOM tree |
||
147 | */ |
||
148 | abstract public function asDom(\DOMDocument $doc, PaymentInformation $paymentInformation); |
||
149 | |||
150 | /** |
||
151 | * Builds a DOM tree of this transaction and adds header nodes |
||
152 | * |
||
153 | * @param \DOMDocument $doc |
||
154 | * @param PaymentInformation $paymentInformation The corresponding B-level element |
||
155 | * |
||
156 | * @return \DOMNode The built DOM node |
||
157 | */ |
||
158 | 2 | protected function buildHeader(\DOMDocument $doc, PaymentInformation $paymentInformation) |
|
190 | |||
191 | /** |
||
192 | * Builds a DOM node of the Creditor field |
||
193 | * |
||
194 | * @param \DOMDocument $doc |
||
195 | * |
||
196 | * @return \DOMNode The built DOM node |
||
197 | */ |
||
198 | 2 | protected function buildCreditor(\DOMDocument $doc) |
|
208 | |||
209 | /** |
||
210 | * Appends the purpose to the transaction |
||
211 | * |
||
212 | * @param \DOMDocument $doc |
||
213 | * @param \DOMElement $transaction |
||
214 | */ |
||
215 | 2 | protected function appendPurpose(\DOMDocument $doc, \DOMElement $transaction) |
|
223 | |||
224 | /** |
||
225 | * Appends the remittance information to the transaction |
||
226 | * |
||
227 | * @param \DOMDocument $doc |
||
228 | * @param \DOMElement $transaction |
||
229 | */ |
||
230 | 2 | protected function appendRemittanceInformation(\DOMDocument $doc, \DOMElement $transaction) |
|
238 | } |
||
239 |