1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Z38\SwissPayment\TransactionInformation; |
4
|
|
|
|
5
|
|
|
use DOMDocument; |
6
|
|
|
use Z38\SwissPayment\Money; |
7
|
|
|
use Z38\SwissPayment\PaymentInformation\PaymentInformation; |
8
|
|
|
use Z38\SwissPayment\PostalAccount; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* ISRCreditTransfer contains all the information about a ISR (type 1) transaction. |
12
|
|
|
*/ |
13
|
|
|
class ISRCreditTransfer extends CreditTransfer |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var PostalAccount |
17
|
|
|
*/ |
18
|
|
|
protected $creditorAccount; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $creditorReference; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
* |
28
|
|
|
* @param PostalAccount $creditorAccount Postal account of the creditor |
29
|
|
|
* @param string $creditorReference Creditor reference information from remittance information |
30
|
|
|
* |
31
|
|
|
* @throws \InvalidArgumentException. An InvalidArgumentException is thrown if amount is not EUR or CHF |
32
|
|
|
*/ |
33
|
2 |
|
public function __construct($instructionId, $endToEndId, Money\Money $amount, PostalAccount $creditorAccount, $creditorReference) |
34
|
|
|
{ |
35
|
2 |
|
if (false === $amount instanceof Money\EUR && false === $amount instanceof Money\CHF) { |
36
|
|
|
throw new \InvalidArgumentException(sprintf( |
37
|
|
|
'Amount must be an instance of Z38\SwissPayment\Money\EUR or Z38\SwissPayment\Money\CHF. Instance of %s given.', |
38
|
|
|
get_class($amount) |
39
|
|
|
)); |
40
|
|
|
} |
41
|
|
|
|
42
|
2 |
|
$this->instructionId = (string) $instructionId; |
43
|
2 |
|
$this->endToEndId = (string) $endToEndId; |
44
|
2 |
|
$this->amount = $amount; |
45
|
2 |
|
$this->creditorAccount = $creditorAccount; |
46
|
2 |
|
$this->creditorReference = $creditorReference; |
47
|
2 |
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritdoc} |
51
|
|
|
*/ |
52
|
2 |
|
public function asDom(DOMDocument $doc, PaymentInformation $paymentInformation) |
53
|
|
|
{ |
54
|
2 |
|
$root = $this->buildHeader($doc, $paymentInformation, 'CH01'); |
55
|
|
|
|
56
|
2 |
|
$creditorAccount = $doc->createElement('CdtrAcct'); |
57
|
2 |
|
$creditorAccount->appendChild($this->creditorAccount->asDom($doc)); |
58
|
2 |
|
$root->appendChild($creditorAccount); |
59
|
2 |
|
$root->appendChild($this->buildRemittanceInformation($doc)); |
60
|
|
|
|
61
|
2 |
|
return $root; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Builds a DOM node of the Remittance Information field |
66
|
|
|
* |
67
|
|
|
* @param \DOMDocument $doc |
68
|
|
|
* |
69
|
|
|
* @return \DOMNode The built DOM node |
70
|
|
|
* |
71
|
|
|
* @throws \LogicException When no remittance information is set |
72
|
|
|
*/ |
73
|
2 |
|
protected function buildRemittanceInformation(\DOMDocument $doc) |
74
|
|
|
{ |
75
|
2 |
|
if ($this->creditorReference) { |
76
|
2 |
|
$remittanceInformation = $doc->createElement('RmtInf'); |
77
|
|
|
|
78
|
2 |
|
$structured = $doc->createElement('Strd'); |
79
|
2 |
|
$remittanceInformation->appendChild($structured); |
80
|
|
|
|
81
|
2 |
|
$creditorReferenceInformation = $doc->createElement('CdtrRefInf'); |
82
|
2 |
|
$structured->appendChild($creditorReferenceInformation); |
83
|
|
|
|
84
|
2 |
|
$creditorReferenceInformation->appendChild($doc->createElement('Ref', $this->creditorReference)); |
85
|
|
|
|
86
|
2 |
|
return $remittanceInformation; |
87
|
|
|
} else { |
88
|
|
|
throw new \LogicException('Can not build node without data.'); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|