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