1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Z38\SwissPayment\TransactionInformation; |
4
|
|
|
|
5
|
|
|
use DOMDocument; |
6
|
|
|
use Z38\SwissPayment\AccountInterface; |
7
|
|
|
use Z38\SwissPayment\BIC; |
8
|
|
|
use Z38\SwissPayment\FinancialInstitutionAddress; |
9
|
|
|
use Z38\SwissPayment\FinancialInstitutionInterface; |
10
|
|
|
use Z38\SwissPayment\Money\Money; |
11
|
|
|
use Z38\SwissPayment\PaymentInformation\PaymentInformation; |
12
|
|
|
use Z38\SwissPayment\PostalAddressInterface; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* ForeignCreditTransfer contains all the information about a foreign (type 6) transaction. |
16
|
|
|
*/ |
17
|
|
|
class ForeignCreditTransfer extends CreditTransfer |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var AccountInterface |
21
|
|
|
*/ |
22
|
|
|
protected $creditorAccount; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var BIC|FinancialInstitutionAddress |
26
|
|
|
*/ |
27
|
|
|
protected $creditorAgent; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var BIC |
31
|
|
|
*/ |
32
|
|
|
protected $intermediaryAgent; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* {@inheritdoc} |
36
|
|
|
* |
37
|
|
|
* @param AccountInterface $creditorAccount Account of the creditor |
38
|
|
|
* @param BIC|FinancialInstitutionAddress $creditorAgent BIC or address of the creditor's financial institution |
39
|
|
|
*/ |
40
|
3 |
|
public function __construct($instructionId, $endToEndId, Money $amount, $creditorName, PostalAddressInterface $creditorAddress, AccountInterface $creditorAccount, FinancialInstitutionInterface $creditorAgent) |
41
|
|
|
{ |
42
|
3 |
|
parent::__construct($instructionId, $endToEndId, $amount, $creditorName, $creditorAddress); |
43
|
|
|
|
44
|
3 |
|
if (!$creditorAgent instanceof BIC && !$creditorAgent instanceof FinancialInstitutionAddress) { |
45
|
1 |
|
throw new \InvalidArgumentException('The creditor agent must be an instance of BIC or FinancialInstitutionAddress.'); |
46
|
|
|
} |
47
|
|
|
|
48
|
2 |
|
$this->creditorAccount = $creditorAccount; |
49
|
2 |
|
$this->creditorAgent = $creditorAgent; |
50
|
2 |
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Set the intermediary agent of the transaction. |
54
|
|
|
* |
55
|
|
|
* @param BIC $intermediaryAgent BIC of the intmediary agent |
56
|
|
|
*/ |
57
|
2 |
|
public function setIntermediaryAgent(BIC $intermediaryAgent) |
58
|
|
|
{ |
59
|
2 |
|
$this->intermediaryAgent = $intermediaryAgent; |
60
|
2 |
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* {@inheritdoc} |
64
|
|
|
*/ |
65
|
2 |
|
public function asDom(DOMDocument $doc, PaymentInformation $paymentInformation) |
66
|
|
|
{ |
67
|
2 |
|
$root = $this->buildHeader($doc, $paymentInformation); |
68
|
|
|
|
69
|
2 |
|
if ($this->intermediaryAgent !== null) { |
70
|
2 |
|
$intermediaryAgent = $doc->createElement('IntrmyAgt1'); |
71
|
2 |
|
$intermediaryAgent->appendChild($this->intermediaryAgent->asDom($doc)); |
72
|
2 |
|
$root->appendChild($intermediaryAgent); |
73
|
2 |
|
} |
74
|
|
|
|
75
|
2 |
|
$creditorAgent = $doc->createElement('CdtrAgt'); |
76
|
2 |
|
$creditorAgent->appendChild($this->creditorAgent->asDom($doc)); |
77
|
2 |
|
$root->appendChild($creditorAgent); |
78
|
|
|
|
79
|
2 |
|
$root->appendChild($this->buildCreditor($doc)); |
80
|
|
|
|
81
|
2 |
|
$creditorAccount = $doc->createElement('CdtrAcct'); |
82
|
2 |
|
$creditorAccount->appendChild($this->creditorAccount->asDom($doc)); |
83
|
2 |
|
$root->appendChild($creditorAccount); |
84
|
|
|
|
85
|
2 |
|
$this->appendPurpose($doc, $root); |
86
|
|
|
|
87
|
2 |
|
$this->appendRemittanceInformation($doc, $root); |
88
|
|
|
|
89
|
2 |
|
return $root; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|