forked from z38/swiss-payment
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add BankCredit specializations for QR with reference and creditor reference * Add comments Co-authored-by: Sébastien Despont <[email protected]>
- Loading branch information
1 parent
24ded25
commit 4280e02
Showing
5 changed files
with
218 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
.php_cs | ||
.php_cs.cache | ||
|
||
*.phpunit.result.cache | ||
phpunit.xml | ||
|
||
/.idea/ | ||
composer.lock | ||
/vendor/ | ||
/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/Z38/SwissPayment/TransactionInformation/BankCreditTransferWithCreditorReference.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
namespace Z38\SwissPayment\TransactionInformation; | ||
|
||
use DOMDocument; | ||
use DOMElement; | ||
use InvalidArgumentException; | ||
use Z38\SwissPayment\FinancialInstitutionInterface; | ||
use Z38\SwissPayment\IBAN; | ||
use Z38\SwissPayment\Money; | ||
use Z38\SwissPayment\PostalAccount; | ||
|
||
/** | ||
* BankCreditTransfer contains all the information about a type 3 transaction | ||
* for a QR-Bill with Creditor Reference (SCOR) | ||
*/ | ||
class BankCreditTransferWithCreditorReference extends BankCreditTransfer | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $creditorReference; | ||
|
||
/** | ||
* BankCreditTransferWithQRR constructor. | ||
* @param $instructionId | ||
* @param $endToEndId | ||
* @param Money\Money $amount | ||
* @param $creditorName | ||
* @param $creditorAddress | ||
* @param IBAN $creditorIBAN IBAN of the creditor | ||
* @param FinancialInstitutionInterface $creditorAgent BIC or IID of the creditor's financial institution | ||
* @param string $creditorReference QR reference number (QRR) | ||
*/ | ||
public function __construct( | ||
$instructionId, | ||
$endToEndId, | ||
Money\Money $amount, | ||
$creditorName, | ||
$creditorAddress, | ||
IBAN $creditorIBAN, | ||
FinancialInstitutionInterface $creditorAgent, | ||
$creditorReference | ||
) { | ||
$cleanedCreditorReference = str_replace(' ', '', strtoupper($creditorReference)); | ||
if (!preg_match('/^RF/', $cleanedCreditorReference)) { | ||
throw new InvalidArgumentException('The creditor reference (SCOR) must starts with RF : ISO-11649'); | ||
} | ||
$this->creditorReference = $cleanedCreditorReference; | ||
|
||
if (preg_match('/^CH[0-9]{2}3/', $creditorIBAN->normalize())) { | ||
throw new InvalidArgumentException('The IBAN must not be a QR-IBAN'); | ||
} | ||
|
||
parent::__construct($instructionId, $endToEndId, $amount, $creditorName, $creditorAddress, $creditorIBAN, $creditorAgent); | ||
} | ||
|
||
/** | ||
* @param DOMDocument $doc | ||
* @param DOMElement $transaction | ||
*/ | ||
protected function appendRemittanceInformation(DOMDocument $doc, DOMElement $transaction) | ||
{ | ||
$remittanceInformation = $doc->createElement('RmtInf'); | ||
|
||
$structured = $doc->createElement('Strd'); | ||
$remittanceInformation->appendChild($structured); | ||
|
||
$creditorReferenceInformation = $doc->createElement('CdtrRefInf'); | ||
$structured->appendChild($creditorReferenceInformation); | ||
|
||
$codeOrProperty = $doc->createElement('CdOrPrtry'); | ||
$codeOrProperty->appendChild($doc->createElement('Cd', 'SCOR')); | ||
$type = $doc->createElement('Tp'); | ||
$type->appendChild($codeOrProperty); | ||
|
||
$creditorReferenceInformation->appendChild($type); | ||
$creditorReferenceInformation->appendChild($doc->createElement('Ref', $this->creditorReference)); | ||
|
||
if (!empty($this->remittanceInformation)) { | ||
$structured->appendChild($doc->createElement('AddtlRmtInf', $this->remittanceInformation)); | ||
} | ||
|
||
$transaction->appendChild($remittanceInformation); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
src/Z38/SwissPayment/TransactionInformation/BankCreditTransferWithQRR.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
namespace Z38\SwissPayment\TransactionInformation; | ||
|
||
use DOMDocument; | ||
use DOMElement; | ||
use InvalidArgumentException; | ||
use Z38\SwissPayment\FinancialInstitutionInterface; | ||
use Z38\SwissPayment\IBAN; | ||
use Z38\SwissPayment\Money; | ||
use Z38\SwissPayment\PostalAccount; | ||
|
||
/** | ||
* BankCreditTransfer contains all the information about a type 3 transaction | ||
* for a QR-Bill with QR reference (QRR) | ||
*/ | ||
class BankCreditTransferWithQRR extends BankCreditTransfer | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $creditorReference; | ||
|
||
/** | ||
* BankCreditTransferWithQRR constructor. | ||
* @param $instructionId | ||
* @param $endToEndId | ||
* @param Money\Money $amount | ||
* @param $creditorName | ||
* @param $creditorAddress | ||
* @param IBAN $creditorIBAN IBAN of the creditor | ||
* @param FinancialInstitutionInterface $creditorAgent BIC or IID of the creditor's financial institution | ||
* @param string $creditorReference QR reference number (QRR) | ||
*/ | ||
public function __construct( | ||
$instructionId, | ||
$endToEndId, | ||
Money\Money $amount, | ||
$creditorName, | ||
$creditorAddress, | ||
IBAN $creditorIBAN, | ||
FinancialInstitutionInterface $creditorAgent, | ||
$creditorReference | ||
) { | ||
if (!preg_match('/^[0-9]{1,27}$/', $creditorReference) || !PostalAccount::validateCheckDigit($creditorReference)) { | ||
throw new InvalidArgumentException('QR reference is invalid.'); | ||
} | ||
$this->creditorReference = $creditorReference; | ||
|
||
if (!preg_match('/^CH[0-9]{2}3/', $creditorIBAN->normalize())) { | ||
throw new InvalidArgumentException('The IBAN must be a QR-IBAN'); | ||
} | ||
|
||
parent::__construct($instructionId, $endToEndId, $amount, $creditorName, $creditorAddress, $creditorIBAN, $creditorAgent); | ||
} | ||
|
||
/** | ||
* @param DOMDocument $doc | ||
* @param DOMElement $transaction | ||
*/ | ||
protected function appendRemittanceInformation(DOMDocument $doc, DOMElement $transaction) | ||
{ | ||
$remittanceInformation = $doc->createElement('RmtInf'); | ||
|
||
$structured = $doc->createElement('Strd'); | ||
$remittanceInformation->appendChild($structured); | ||
|
||
$creditorReferenceInformation = $doc->createElement('CdtrRefInf'); | ||
$structured->appendChild($creditorReferenceInformation); | ||
|
||
$codeOrProperty = $doc->createElement('CdOrPrtry'); | ||
$codeOrProperty->appendChild($doc->createElement('Prtry', 'QRR')); | ||
$type = $doc->createElement('Tp'); | ||
$type->appendChild($codeOrProperty); | ||
|
||
$creditorReferenceInformation->appendChild($type); | ||
$creditorReferenceInformation->appendChild($doc->createElement('Ref', $this->creditorReference)); | ||
|
||
if (!empty($this->remittanceInformation)) { | ||
$structured->appendChild($doc->createElement('AddtlRmtInf', $this->remittanceInformation)); | ||
} | ||
|
||
$transaction->appendChild($remittanceInformation); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters