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