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