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
|
|
|
public function __construct($instructionId, $endToEndId, Money\Money $amount, ISRParticipant $creditorAccount, $creditorReference) |
36
|
|
|
{ |
37
|
|
|
if (!$amount instanceof Money\EUR && !$amount instanceof Money\CHF) { |
38
|
|
|
throw new InvalidArgumentException(sprintf( |
39
|
|
|
'The amount must be an instance of Z38\SwissPayment\Money\EUR or Z38\SwissPayment\Money\CHF (instance of %s given).', |
40
|
|
|
get_class($amount) |
41
|
|
|
)); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$this->instructionId = (string) $instructionId; |
45
|
|
|
$this->endToEndId = (string) $endToEndId; |
46
|
|
|
$this->amount = $amount; |
47
|
|
|
$this->creditorAccount = $creditorAccount; |
48
|
|
|
$this->creditorReference = (string) $creditorReference; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
|
|
public function setRemittanceInformation($remittanceInformation) |
55
|
|
|
{ |
56
|
|
|
throw new LogicException('ISR payments are not able to store unstructured remittance information.'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritdoc} |
61
|
|
|
*/ |
62
|
|
|
public function asDom(DOMDocument $doc, PaymentInformation $paymentInformation) |
63
|
|
|
{ |
64
|
|
|
$root = $this->buildHeader($doc, $paymentInformation, 'CH01'); |
65
|
|
|
|
66
|
|
|
$creditorAccount = $doc->createElement('CdtrAcct'); |
67
|
|
|
$creditorAccount->appendChild($this->creditorAccount->asDom($doc)); |
68
|
|
|
$root->appendChild($creditorAccount); |
69
|
|
|
|
70
|
|
|
$root->appendChild($this->buildRemittanceInformation($doc)); |
71
|
|
|
|
72
|
|
|
return $root; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* {@inheritdoc} |
77
|
|
|
*/ |
78
|
|
|
protected function buildRemittanceInformation(\DOMDocument $doc) |
79
|
|
|
{ |
80
|
|
|
$remittanceInformation = $doc->createElement('RmtInf'); |
81
|
|
|
|
82
|
|
|
$structured = $doc->createElement('Strd'); |
83
|
|
|
$remittanceInformation->appendChild($structured); |
84
|
|
|
|
85
|
|
|
$creditorReferenceInformation = $doc->createElement('CdtrRefInf'); |
86
|
|
|
$structured->appendChild($creditorReferenceInformation); |
87
|
|
|
|
88
|
|
|
$creditorReferenceInformation->appendChild($doc->createElement('Ref', $this->creditorReference)); |
89
|
|
|
|
90
|
|
|
return $remittanceInformation; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* {@inheritdoc} |
95
|
|
|
*/ |
96
|
|
|
protected function hasRemittanceInformation() |
97
|
|
|
{ |
98
|
|
|
return true; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|