1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Z38\SwissPayment\TransactionInformation; |
4
|
|
|
|
5
|
|
|
use DOMDocument; |
6
|
|
|
use DOMElement; |
7
|
|
|
use InvalidArgumentException; |
8
|
|
|
use Z38\SwissPayment\FinancialInstitutionInterface; |
9
|
|
|
use Z38\SwissPayment\IBAN; |
10
|
|
|
use Z38\SwissPayment\Money; |
11
|
|
|
use Z38\SwissPayment\PostalAccount; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* BankCreditTransfer contains all the information about a type 3 transaction |
15
|
|
|
* for a QR-Bill with QR reference (QRR) |
16
|
|
|
*/ |
17
|
|
|
class BankCreditTransferWithQRR extends BankCreditTransfer |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $creditorReference; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* BankCreditTransferWithQRR constructor. |
26
|
|
|
* @param $instructionId |
27
|
|
|
* @param $endToEndId |
28
|
|
|
* @param Money\Money $amount |
29
|
|
|
* @param $creditorName |
30
|
|
|
* @param $creditorAddress |
31
|
|
|
* @param IBAN $creditorIBAN IBAN of the creditor |
32
|
|
|
* @param FinancialInstitutionInterface $creditorAgent BIC or IID of the creditor's financial institution |
33
|
|
|
* @param string $creditorReference QR reference number (QRR) |
34
|
|
|
*/ |
35
|
3 |
|
public function __construct( |
36
|
|
|
$instructionId, |
37
|
|
|
$endToEndId, |
38
|
|
|
Money\Money $amount, |
39
|
|
|
$creditorName, |
40
|
|
|
$creditorAddress, |
41
|
|
|
IBAN $creditorIBAN, |
42
|
|
|
FinancialInstitutionInterface $creditorAgent, |
43
|
|
|
$creditorReference |
44
|
|
|
) { |
45
|
3 |
|
if (!preg_match('/^[0-9]{1,27}$/', $creditorReference) || !PostalAccount::validateCheckDigit($creditorReference)) { |
46
|
|
|
throw new InvalidArgumentException('QR reference is invalid.'); |
47
|
|
|
} |
48
|
3 |
|
$this->creditorReference = $creditorReference; |
49
|
|
|
|
50
|
3 |
|
if (!preg_match('/^CH[0-9]{2}3/', $creditorIBAN->normalize())) { |
51
|
|
|
throw new InvalidArgumentException('The IBAN must be a QR-IBAN'); |
52
|
|
|
} |
53
|
|
|
|
54
|
3 |
|
parent::__construct($instructionId, $endToEndId, $amount, $creditorName, $creditorAddress, $creditorIBAN, $creditorAgent); |
55
|
3 |
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param DOMDocument $doc |
59
|
|
|
* @param DOMElement $transaction |
60
|
|
|
*/ |
61
|
2 |
|
protected function appendRemittanceInformation(DOMDocument $doc, DOMElement $transaction) |
62
|
|
|
{ |
63
|
2 |
|
$remittanceInformation = $doc->createElement('RmtInf'); |
64
|
|
|
|
65
|
2 |
|
$structured = $doc->createElement('Strd'); |
66
|
2 |
|
$remittanceInformation->appendChild($structured); |
67
|
|
|
|
68
|
2 |
|
$creditorReferenceInformation = $doc->createElement('CdtrRefInf'); |
69
|
2 |
|
$structured->appendChild($creditorReferenceInformation); |
70
|
|
|
|
71
|
2 |
|
$codeOrProperty = $doc->createElement('CdOrPrtry'); |
72
|
2 |
|
$codeOrProperty->appendChild($doc->createElement('Prtry', 'QRR')); |
73
|
2 |
|
$type = $doc->createElement('Tp'); |
74
|
2 |
|
$type->appendChild($codeOrProperty); |
75
|
|
|
|
76
|
2 |
|
$creditorReferenceInformation->appendChild($type); |
77
|
2 |
|
$creditorReferenceInformation->appendChild($doc->createElement('Ref', $this->creditorReference)); |
78
|
|
|
|
79
|
2 |
|
if (!empty($this->remittanceInformation)) { |
80
|
2 |
|
$structured->appendChild($doc->createElement('AddtlRmtInf', $this->remittanceInformation)); |
81
|
2 |
|
} |
82
|
|
|
|
83
|
2 |
|
$transaction->appendChild($remittanceInformation); |
84
|
2 |
|
} |
85
|
|
|
} |
86
|
|
|
|