|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Z38\SwissPayment\TransactionInformation; |
|
4
|
|
|
|
|
5
|
|
|
use Z38\SwissPayment\BC; |
|
6
|
|
|
use Z38\SwissPayment\BIC; |
|
7
|
|
|
use Z38\SwissPayment\FinancialInstitutionInterface; |
|
8
|
|
|
use Z38\SwissPayment\IBAN; |
|
9
|
|
|
use Z38\SwissPayment\Money; |
|
10
|
|
|
use Z38\SwissPayment\PostalAddressInterface; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* BankCreditTransfer contains all the information about a type 3 transaction. |
|
14
|
|
|
*/ |
|
15
|
|
|
class BankCreditTransfer extends CreditTransfer |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var IBAN |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $creditorIBAN; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var FinancialInstitutionInterface |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $creditorAgent; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* {@inheritdoc} |
|
29
|
|
|
* |
|
30
|
|
|
* @param IBAN $creditorIBAN IBAN of the creditor |
|
31
|
|
|
* @param BC|BIC $creditorAgent BC or BIC of the creditor's financial institution |
|
32
|
|
|
*/ |
|
33
|
3 |
|
public function __construct($instructionId, $endToEndId, Money\CHF $amount, $creditorName, PostalAddressInterface $creditorAddress, IBAN $creditorIBAN, FinancialInstitutionInterface $creditorAgent) |
|
34
|
|
|
{ |
|
35
|
3 |
|
parent::__construct($instructionId, $endToEndId, $amount, $creditorName, $creditorAddress); |
|
36
|
|
|
|
|
37
|
3 |
|
if (!$creditorAgent instanceof BC && !$creditorAgent instanceof BIC) { |
|
38
|
1 |
|
throw new \InvalidArgumentException('The creditor agent must be an instance of BC or BIC.'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
2 |
|
$this->creditorIBAN = $creditorIBAN; |
|
42
|
2 |
|
$this->creditorAgent = $creditorAgent; |
|
43
|
2 |
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* {@inheritdoc} |
|
47
|
|
|
*/ |
|
48
|
2 |
|
public function asDom(\DOMDocument $doc) |
|
49
|
|
|
{ |
|
50
|
2 |
|
$root = $this->buildHeader($doc, null); |
|
51
|
|
|
|
|
52
|
2 |
|
$creditorAgent = $doc->createElement('CdtrAgt'); |
|
53
|
2 |
|
$creditorAgent->appendChild($this->creditorAgent->asDom($doc)); |
|
54
|
2 |
|
$root->appendChild($creditorAgent); |
|
55
|
|
|
|
|
56
|
2 |
|
$root->appendChild($this->buildCreditor($doc)); |
|
57
|
|
|
|
|
58
|
2 |
|
$creditorAccount = $doc->createElement('CdtrAcct'); |
|
59
|
2 |
|
$creditorAccountId = $doc->createElement('Id'); |
|
60
|
2 |
|
$creditorAccountId->appendChild($doc->createElement('IBAN', $this->creditorIBAN->normalize())); |
|
61
|
2 |
|
$creditorAccount->appendChild($creditorAccountId); |
|
62
|
2 |
|
$root->appendChild($creditorAccount); |
|
63
|
|
|
|
|
64
|
2 |
|
if ($this->hasRemittanceInformation()) { |
|
65
|
|
|
$root->appendChild($this->buildRemittanceInformation($doc)); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
2 |
|
return $root; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|