1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Z38\SwissPayment\TransactionInformation; |
4
|
|
|
|
5
|
|
|
use DOMDocument; |
6
|
|
|
use Z38\SwissPayment\IBAN; |
7
|
|
|
use Z38\SwissPayment\Money; |
8
|
|
|
use Z38\SwissPayment\PaymentInformation\PaymentInformation; |
9
|
|
|
use Z38\SwissPayment\PostalAccount; |
10
|
|
|
use Z38\SwissPayment\PostalAddressInterface; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* IS2CreditTransfer contains all the information about a IS 2-stage (type 2.2) transaction. |
14
|
|
|
*/ |
15
|
|
|
class IS2CreditTransfer extends CreditTransfer |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var IBAN |
19
|
|
|
*/ |
20
|
|
|
protected $creditorIBAN; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected $creditorAgentName; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var PostalAccount |
29
|
|
|
*/ |
30
|
|
|
protected $creditorAgentPostal; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
* |
35
|
|
|
* @param IBAN $creditorIBAN IBAN of the creditor |
36
|
|
|
* @param string $creditorAgentName Name of the creditor's financial institution |
37
|
|
|
* @param PostalAccount $creditorAgentPostal Postal account of the creditor's financial institution |
38
|
|
|
* |
39
|
|
|
* @throws \InvalidArgumentException. An InvalidArgumentException is thrown if amount is not EUR or CHF |
40
|
|
|
*/ |
41
|
3 |
|
public function __construct($instructionId, $endToEndId, Money\Money $amount, $creditorName, PostalAddressInterface $creditorAddress, IBAN $creditorIBAN, $creditorAgentName, PostalAccount $creditorAgentPostal) |
42
|
|
|
{ |
43
|
3 |
|
if (false === $amount instanceof Money\EUR && false === $amount instanceof Money\CHF) { |
44
|
1 |
|
throw new \InvalidArgumentException(sprintf( |
45
|
1 |
|
'Amount must be an instance of Z38\SwissPayment\Money\EUR or Z38\SwissPayment\Money\CHF. Instance of %s given.', |
46
|
1 |
|
get_class($amount) |
47
|
1 |
|
)); |
48
|
|
|
} |
49
|
|
|
|
50
|
2 |
|
parent::__construct($instructionId, $endToEndId, $amount, $creditorName, $creditorAddress); |
51
|
|
|
|
52
|
2 |
|
$this->creditorIBAN = $creditorIBAN; |
53
|
2 |
|
$this->creditorAgentName = (string) $creditorAgentName; |
54
|
2 |
|
$this->creditorAgentPostal = $creditorAgentPostal; |
55
|
2 |
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* {@inheritdoc} |
59
|
|
|
*/ |
60
|
2 |
|
public function asDom(DOMDocument $doc, PaymentInformation $paymentInformation) |
61
|
|
|
{ |
62
|
2 |
|
$root = $this->buildHeader($doc, $paymentInformation, 'CH03'); |
63
|
|
|
|
64
|
2 |
|
$creditorAgent = $doc->createElement('CdtrAgt'); |
65
|
2 |
|
$creditorAgentId = $doc->createElement('FinInstnId'); |
66
|
2 |
|
$creditorAgentId->appendChild($doc->createElement('Nm', $this->creditorAgentName)); |
67
|
2 |
|
$creditorAgentIdOther = $doc->createElement('Othr'); |
68
|
2 |
|
$creditorAgentIdOther->appendChild($doc->createElement('Id', $this->creditorAgentPostal->format())); |
69
|
2 |
|
$creditorAgentId->appendChild($creditorAgentIdOther); |
70
|
2 |
|
$creditorAgent->appendChild($creditorAgentId); |
71
|
2 |
|
$root->appendChild($creditorAgent); |
72
|
|
|
|
73
|
2 |
|
$root->appendChild($this->buildCreditor($doc)); |
74
|
|
|
|
75
|
2 |
|
$creditorAccount = $doc->createElement('CdtrAcct'); |
76
|
2 |
|
$creditorAccount->appendChild($this->creditorIBAN->asDom($doc)); |
77
|
2 |
|
$root->appendChild($creditorAccount); |
78
|
|
|
|
79
|
2 |
|
if ($this->hasRemittanceInformation()) { |
80
|
|
|
$root->appendChild($this->buildRemittanceInformation($doc)); |
81
|
|
|
} |
82
|
|
|
|
83
|
2 |
|
return $root; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|