From ecf2ae5343297fb1137400c9ba2da8f4137f2103 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9line=20de=20Roland?= Date: Wed, 23 May 2018 12:01:15 +0200 Subject: [PATCH 1/2] PstlAdr field is optional is the Dbtr section for BankCreditTransfer transactions. I add a new 'EmptyPostalAddress' implementation which doesn't generate any DOMElement I test the constructor of BankCreditTransfer with an instance of this implementation I add a transaction of 1300 CHF in the CustomerCreditTransferTest, and check that the generated xml file is ever valid (the headers CtrlSum and NbOfTxs change in consequence) --- src/Z38/SwissPayment/EmptyPostalAddress.php | 25 +++++++++++ .../TransactionInformation/CreditTransfer.php | 4 +- .../Message/CustomerCreditTransferTest.php | 44 ++++++++++++------- .../BankCreditTransferTest.php | 18 ++++++++ 4 files changed, 74 insertions(+), 17 deletions(-) create mode 100644 src/Z38/SwissPayment/EmptyPostalAddress.php diff --git a/src/Z38/SwissPayment/EmptyPostalAddress.php b/src/Z38/SwissPayment/EmptyPostalAddress.php new file mode 100644 index 0000000..3c8e23d --- /dev/null +++ b/src/Z38/SwissPayment/EmptyPostalAddress.php @@ -0,0 +1,25 @@ +createElement('Cdtr'); $creditor->appendChild(Text::xml($doc, 'Nm', $this->creditorName)); - $creditor->appendChild($this->creditorAddress->asDom($doc)); + if (!is_null($this->creditorAddress->asDom($doc))) { + $creditor->appendChild($this->creditorAddress->asDom($doc)); + } return $creditor; } diff --git a/tests/Z38/SwissPayment/Tests/Message/CustomerCreditTransferTest.php b/tests/Z38/SwissPayment/Tests/Message/CustomerCreditTransferTest.php index 5ef7dbc..aa01d55 100644 --- a/tests/Z38/SwissPayment/Tests/Message/CustomerCreditTransferTest.php +++ b/tests/Z38/SwissPayment/Tests/Message/CustomerCreditTransferTest.php @@ -3,6 +3,7 @@ namespace Z38\SwissPayment\Tests\Message; use Z38\SwissPayment\BIC; +use Z38\SwissPayment\EmptyPostalAddress; use Z38\SwissPayment\FinancialInstitutionAddress; use Z38\SwissPayment\GeneralAccount; use Z38\SwissPayment\IBAN; @@ -74,7 +75,17 @@ protected function buildMessage() ); $transaction4->setPurpose(new PurposeCode('AIRB')); - $transaction5 = new SEPACreditTransfer( + $transaction5 = new BankCreditTransfer( + 'instr-005', + 'e2e-005', + new Money\CHF(130000), // CHF 1300.00 + 'Muster Transport AG', + new EmptyPostalAddress(), + new IBAN('CH51 0022 5225 9529 1301 C'), + new BIC('UBSWCHZH80A') + ); + + $transaction6 = new SEPACreditTransfer( 'instr-005', 'e2e-005', new Money\EUR(70000), // EUR 700.00 @@ -84,7 +95,7 @@ protected function buildMessage() new BIC('COBADEFFXXX') ); - $transaction6 = new ForeignCreditTransfer( + $transaction7 = new ForeignCreditTransfer( 'instr-006', 'e2e-006', new Money\GBP(6500), // GBP 65.00 @@ -94,7 +105,7 @@ protected function buildMessage() new BIC('NWBKGB2L') ); - $transaction7 = new ForeignCreditTransfer( + $transaction8 = new ForeignCreditTransfer( 'instr-007', 'e2e-007', new Money\KWD(300001), // KWD 300.001 @@ -104,7 +115,7 @@ protected function buildMessage() new FinancialInstitutionAddress('Caixa Economica Federal', new UnstructuredPostalAddress('Rua Sao Valentim, 620', '03446-040 Sao Paulo-SP', 'BR')) ); - $transaction8 = new ForeignCreditTransfer( + $transaction9 = new ForeignCreditTransfer( 'instr-008', 'e2e-008', new Money\GBP(4500), // GBP 45.00 @@ -113,9 +124,9 @@ protected function buildMessage() new GeneralAccount('123-4567890-78'), new FinancialInstitutionAddress('Belfius Bank', new UnstructuredPostalAddress('Pachecolaan 44', '1000 Brussel', 'BE')) ); - $transaction8->setIntermediaryAgent(new BIC('SWHQBEBB')); + $transaction9->setIntermediaryAgent(new BIC('SWHQBEBB')); - $transaction9 = new SEPACreditTransfer( + $transaction10 = new SEPACreditTransfer( 'instr-009', 'e2e-009', new Money\EUR(10000), // EUR 100.00 @@ -125,7 +136,7 @@ protected function buildMessage() new BIC('NOLADE21EMS') ); - $transaction10 = new ISRCreditTransfer( + $transaction11 = new ISRCreditTransfer( 'instr-010', 'e2e-010', new Money\CHF(20000), // CHF 200.00 @@ -133,19 +144,19 @@ protected function buildMessage() '210000000003139471430009017' ); - $transaction11 = new ISRCreditTransfer( + $transaction12 = new ISRCreditTransfer( 'instr-011', 'e2e-011', new Money\CHF(20000), // CHF 200.00 new ISRParticipant('01-95106-8'), '6019701803969733825' ); - $transaction11->setCreditorDetails( + $transaction12->setCreditorDetails( 'Fritz Bischof', new StructuredPostalAddress('Dorfstrasse', '17', '9911', 'Musterwald') ); - $transaction12 = new IS1CreditTransfer( + $transaction13 = new IS1CreditTransfer( 'instr-012', 'e2e-012', new Money\CHF(50000), // CHF 500.00 @@ -159,23 +170,24 @@ protected function buildMessage() $payment->addTransaction($transaction2); $payment->addTransaction($transaction3); $payment->addTransaction($transaction4); + $payment->addTransaction($transaction5); $payment2 = new PaymentInformation('payment-002', 'InnoMuster AG', new BIC('POFICHBEXXX'), new IBAN('CH6309000000250097798')); - $payment2->addTransaction($transaction5); $payment2->addTransaction($transaction6); $payment2->addTransaction($transaction7); $payment2->addTransaction($transaction8); + $payment2->addTransaction($transaction9); $payment3 = new SEPAPaymentInformation('payment-003', 'InnoMuster AG', new BIC('POFICHBEXXX'), new IBAN('CH6309000000250097798')); - $payment3->addTransaction($transaction9); + $payment3->addTransaction($transaction10); $payment4 = new PaymentInformation('payment-004', 'InnoMuster AG', new BIC('POFICHBEXXX'), new IBAN('CH6309000000250097798')); - $payment4->addTransaction($transaction10); $payment4->addTransaction($transaction11); + $payment4->addTransaction($transaction12); $payment5 = new PaymentInformation('payment-005', 'InnoMuster AG', new BIC('POFICHBEXXX'), new IBAN('CH6309000000250097798')); $payment5->setCategoryPurpose(new CategoryPurposeCode('SALA')); - $payment5->addTransaction($transaction12); + $payment5->addTransaction($transaction13); $message = new CustomerCreditTransfer('message-001', 'InnoMuster AG'); $message->addPayment($payment); @@ -197,10 +209,10 @@ public function testGroupHeader() $xpath->registerNamespace('pain001', self::SCHEMA); $nbOfTxs = $xpath->evaluate('string(//pain001:GrpHdr/pain001:NbOfTxs)'); - $this->assertEquals('12', $nbOfTxs); + $this->assertEquals('13', $nbOfTxs); $ctrlSum = $xpath->evaluate('string(//pain001:GrpHdr/pain001:CtrlSum)'); - $this->assertEquals('4210.001', $ctrlSum); + $this->assertEquals('5510.001', $ctrlSum); } public function testSchemaValidation() diff --git a/tests/Z38/SwissPayment/Tests/TransactionInformation/BankCreditTransferTest.php b/tests/Z38/SwissPayment/Tests/TransactionInformation/BankCreditTransferTest.php index cec6bcb..2654cca 100644 --- a/tests/Z38/SwissPayment/Tests/TransactionInformation/BankCreditTransferTest.php +++ b/tests/Z38/SwissPayment/Tests/TransactionInformation/BankCreditTransferTest.php @@ -3,6 +3,7 @@ namespace Z38\SwissPayment\Tests\TransactionInformation; use Z38\SwissPayment\BIC; +use Z38\SwissPayment\EmptyPostalAddress; use Z38\SwissPayment\IBAN; use Z38\SwissPayment\Money; use Z38\SwissPayment\StructuredPostalAddress; @@ -49,4 +50,21 @@ public function testInvalidAmount() new BIC('PSETPD2SZZZ') ); } + + /** + * @covers ::__construct + * @throws \InvalidArgumentException + */ + public function testWithoutPostalAddress() + { + $transfer = new BankCreditTransfer( + 'id000', + 'name', + new Money\CHF(100), + 'name', + new EmptyPostalAddress(), + new IBAN('CH31 8123 9000 0012 4568 9'), + new BIC('PSETPD2SZZZ') + ); + } } From 87ed4f6b4dee42bf175ac3432f6f09e8e95610f5 Mon Sep 17 00:00:00 2001 From: z38 Date: Mon, 16 Jul 2018 14:50:52 +0200 Subject: [PATCH 2/2] Use null to express no address --- src/Z38/SwissPayment/EmptyPostalAddress.php | 25 ---------- .../BankCreditTransfer.php | 3 +- .../TransactionInformation/CreditTransfer.php | 16 +++---- .../ForeignCreditTransfer.php | 3 +- .../IS1CreditTransfer.php | 3 +- .../IS2CreditTransfer.php | 3 +- .../SEPACreditTransfer.php | 3 +- .../Message/CustomerCreditTransferTest.php | 46 +++++++------------ .../BankCreditTransferTest.php | 18 -------- 9 files changed, 30 insertions(+), 90 deletions(-) delete mode 100644 src/Z38/SwissPayment/EmptyPostalAddress.php diff --git a/src/Z38/SwissPayment/EmptyPostalAddress.php b/src/Z38/SwissPayment/EmptyPostalAddress.php deleted file mode 100644 index 3c8e23d..0000000 --- a/src/Z38/SwissPayment/EmptyPostalAddress.php +++ /dev/null @@ -1,25 +0,0 @@ -instructionId = Text::assertIdentifier($instructionId); $this->endToEndId = Text::assertIdentifier($endToEndId); @@ -199,7 +199,7 @@ protected function buildCreditor(\DOMDocument $doc) { $creditor = $doc->createElement('Cdtr'); $creditor->appendChild(Text::xml($doc, 'Nm', $this->creditorName)); - if (!is_null($this->creditorAddress->asDom($doc))) { + if ($this->creditorAddress !== null) { $creditor->appendChild($this->creditorAddress->asDom($doc)); } diff --git a/src/Z38/SwissPayment/TransactionInformation/ForeignCreditTransfer.php b/src/Z38/SwissPayment/TransactionInformation/ForeignCreditTransfer.php index aa7bd45..661bb48 100644 --- a/src/Z38/SwissPayment/TransactionInformation/ForeignCreditTransfer.php +++ b/src/Z38/SwissPayment/TransactionInformation/ForeignCreditTransfer.php @@ -9,7 +9,6 @@ use Z38\SwissPayment\FinancialInstitutionInterface; use Z38\SwissPayment\Money\Money; use Z38\SwissPayment\PaymentInformation\PaymentInformation; -use Z38\SwissPayment\PostalAddressInterface; /** * ForeignCreditTransfer contains all the information about a foreign (type 6) transaction. @@ -37,7 +36,7 @@ class ForeignCreditTransfer extends CreditTransfer * @param AccountInterface $creditorAccount Account of the creditor * @param BIC|FinancialInstitutionAddress $creditorAgent BIC or address of the creditor's financial institution */ - public function __construct($instructionId, $endToEndId, Money $amount, $creditorName, PostalAddressInterface $creditorAddress, AccountInterface $creditorAccount, FinancialInstitutionInterface $creditorAgent) + public function __construct($instructionId, $endToEndId, Money $amount, $creditorName, $creditorAddress, AccountInterface $creditorAccount, FinancialInstitutionInterface $creditorAgent) { parent::__construct($instructionId, $endToEndId, $amount, $creditorName, $creditorAddress); diff --git a/src/Z38/SwissPayment/TransactionInformation/IS1CreditTransfer.php b/src/Z38/SwissPayment/TransactionInformation/IS1CreditTransfer.php index 9b01563..c5daa12 100644 --- a/src/Z38/SwissPayment/TransactionInformation/IS1CreditTransfer.php +++ b/src/Z38/SwissPayment/TransactionInformation/IS1CreditTransfer.php @@ -7,7 +7,6 @@ use Z38\SwissPayment\Money; use Z38\SwissPayment\PaymentInformation\PaymentInformation; use Z38\SwissPayment\PostalAccount; -use Z38\SwissPayment\PostalAddressInterface; /** * IS1CreditTransfer contains all the information about a IS 1-stage (type 2.1) transaction. @@ -26,7 +25,7 @@ class IS1CreditTransfer extends CreditTransfer * * @throws \InvalidArgumentException When the amount is not in EUR or CHF. */ - public function __construct($instructionId, $endToEndId, Money\Money $amount, $creditorName, PostalAddressInterface $creditorAddress, PostalAccount $creditorAccount) + public function __construct($instructionId, $endToEndId, Money\Money $amount, $creditorName, $creditorAddress, PostalAccount $creditorAccount) { if (!$amount instanceof Money\EUR && !$amount instanceof Money\CHF) { throw new InvalidArgumentException(sprintf( diff --git a/src/Z38/SwissPayment/TransactionInformation/IS2CreditTransfer.php b/src/Z38/SwissPayment/TransactionInformation/IS2CreditTransfer.php index a39e755..5c42e9f 100644 --- a/src/Z38/SwissPayment/TransactionInformation/IS2CreditTransfer.php +++ b/src/Z38/SwissPayment/TransactionInformation/IS2CreditTransfer.php @@ -8,7 +8,6 @@ use Z38\SwissPayment\Money; use Z38\SwissPayment\PaymentInformation\PaymentInformation; use Z38\SwissPayment\PostalAccount; -use Z38\SwissPayment\PostalAddressInterface; use Z38\SwissPayment\Text; /** @@ -40,7 +39,7 @@ class IS2CreditTransfer extends CreditTransfer * * @throws \InvalidArgumentException When the amount is not in EUR or CHF. */ - public function __construct($instructionId, $endToEndId, Money\Money $amount, $creditorName, PostalAddressInterface $creditorAddress, IBAN $creditorIBAN, $creditorAgentName, PostalAccount $creditorAgentPostal) + public function __construct($instructionId, $endToEndId, Money\Money $amount, $creditorName, $creditorAddress, IBAN $creditorIBAN, $creditorAgentName, PostalAccount $creditorAgentPostal) { if (!$amount instanceof Money\EUR && !$amount instanceof Money\CHF) { throw new InvalidArgumentException(sprintf( diff --git a/src/Z38/SwissPayment/TransactionInformation/SEPACreditTransfer.php b/src/Z38/SwissPayment/TransactionInformation/SEPACreditTransfer.php index 98d00f8..2d282a3 100644 --- a/src/Z38/SwissPayment/TransactionInformation/SEPACreditTransfer.php +++ b/src/Z38/SwissPayment/TransactionInformation/SEPACreditTransfer.php @@ -7,7 +7,6 @@ use Z38\SwissPayment\IBAN; use Z38\SwissPayment\Money; use Z38\SwissPayment\PaymentInformation\PaymentInformation; -use Z38\SwissPayment\PostalAddressInterface; /** * SEPACreditTransfer contains all the information about a foreign SEPA (type 5) transaction. @@ -30,7 +29,7 @@ class SEPACreditTransfer extends CreditTransfer * @param IBAN $creditorIBAN IBAN of the creditor * @param BIC|null $creditorAgentBIC BIC of the creditor's financial institution */ - public function __construct($instructionId, $endToEndId, Money\EUR $amount, $creditorName, PostalAddressInterface $creditorAddress, IBAN $creditorIBAN, BIC $creditorAgentBIC = null) + public function __construct($instructionId, $endToEndId, Money\EUR $amount, $creditorName, $creditorAddress, IBAN $creditorIBAN, BIC $creditorAgentBIC = null) { parent::__construct($instructionId, $endToEndId, $amount, $creditorName, $creditorAddress); diff --git a/tests/Z38/SwissPayment/Tests/Message/CustomerCreditTransferTest.php b/tests/Z38/SwissPayment/Tests/Message/CustomerCreditTransferTest.php index aa01d55..b8ebb82 100644 --- a/tests/Z38/SwissPayment/Tests/Message/CustomerCreditTransferTest.php +++ b/tests/Z38/SwissPayment/Tests/Message/CustomerCreditTransferTest.php @@ -3,7 +3,6 @@ namespace Z38\SwissPayment\Tests\Message; use Z38\SwissPayment\BIC; -use Z38\SwissPayment\EmptyPostalAddress; use Z38\SwissPayment\FinancialInstitutionAddress; use Z38\SwissPayment\GeneralAccount; use Z38\SwissPayment\IBAN; @@ -69,23 +68,13 @@ protected function buildMessage() 'e2e-004', new Money\CHF(30000), // CHF 300.00 'Muster Transport AG', - new StructuredPostalAddress('Wiesenweg', '14b', '8058', 'Zürich-Flughafen'), + null, $iban4, IID::fromIBAN($iban4) ); $transaction4->setPurpose(new PurposeCode('AIRB')); - $transaction5 = new BankCreditTransfer( - 'instr-005', - 'e2e-005', - new Money\CHF(130000), // CHF 1300.00 - 'Muster Transport AG', - new EmptyPostalAddress(), - new IBAN('CH51 0022 5225 9529 1301 C'), - new BIC('UBSWCHZH80A') - ); - - $transaction6 = new SEPACreditTransfer( + $transaction5 = new SEPACreditTransfer( 'instr-005', 'e2e-005', new Money\EUR(70000), // EUR 700.00 @@ -95,7 +84,7 @@ protected function buildMessage() new BIC('COBADEFFXXX') ); - $transaction7 = new ForeignCreditTransfer( + $transaction6 = new ForeignCreditTransfer( 'instr-006', 'e2e-006', new Money\GBP(6500), // GBP 65.00 @@ -105,7 +94,7 @@ protected function buildMessage() new BIC('NWBKGB2L') ); - $transaction8 = new ForeignCreditTransfer( + $transaction7 = new ForeignCreditTransfer( 'instr-007', 'e2e-007', new Money\KWD(300001), // KWD 300.001 @@ -115,7 +104,7 @@ protected function buildMessage() new FinancialInstitutionAddress('Caixa Economica Federal', new UnstructuredPostalAddress('Rua Sao Valentim, 620', '03446-040 Sao Paulo-SP', 'BR')) ); - $transaction9 = new ForeignCreditTransfer( + $transaction8 = new ForeignCreditTransfer( 'instr-008', 'e2e-008', new Money\GBP(4500), // GBP 45.00 @@ -124,9 +113,9 @@ protected function buildMessage() new GeneralAccount('123-4567890-78'), new FinancialInstitutionAddress('Belfius Bank', new UnstructuredPostalAddress('Pachecolaan 44', '1000 Brussel', 'BE')) ); - $transaction9->setIntermediaryAgent(new BIC('SWHQBEBB')); + $transaction8->setIntermediaryAgent(new BIC('SWHQBEBB')); - $transaction10 = new SEPACreditTransfer( + $transaction9 = new SEPACreditTransfer( 'instr-009', 'e2e-009', new Money\EUR(10000), // EUR 100.00 @@ -136,7 +125,7 @@ protected function buildMessage() new BIC('NOLADE21EMS') ); - $transaction11 = new ISRCreditTransfer( + $transaction10 = new ISRCreditTransfer( 'instr-010', 'e2e-010', new Money\CHF(20000), // CHF 200.00 @@ -144,19 +133,19 @@ protected function buildMessage() '210000000003139471430009017' ); - $transaction12 = new ISRCreditTransfer( + $transaction11 = new ISRCreditTransfer( 'instr-011', 'e2e-011', new Money\CHF(20000), // CHF 200.00 new ISRParticipant('01-95106-8'), '6019701803969733825' ); - $transaction12->setCreditorDetails( + $transaction11->setCreditorDetails( 'Fritz Bischof', new StructuredPostalAddress('Dorfstrasse', '17', '9911', 'Musterwald') ); - $transaction13 = new IS1CreditTransfer( + $transaction12 = new IS1CreditTransfer( 'instr-012', 'e2e-012', new Money\CHF(50000), // CHF 500.00 @@ -170,24 +159,23 @@ protected function buildMessage() $payment->addTransaction($transaction2); $payment->addTransaction($transaction3); $payment->addTransaction($transaction4); - $payment->addTransaction($transaction5); $payment2 = new PaymentInformation('payment-002', 'InnoMuster AG', new BIC('POFICHBEXXX'), new IBAN('CH6309000000250097798')); + $payment2->addTransaction($transaction5); $payment2->addTransaction($transaction6); $payment2->addTransaction($transaction7); $payment2->addTransaction($transaction8); - $payment2->addTransaction($transaction9); $payment3 = new SEPAPaymentInformation('payment-003', 'InnoMuster AG', new BIC('POFICHBEXXX'), new IBAN('CH6309000000250097798')); - $payment3->addTransaction($transaction10); + $payment3->addTransaction($transaction9); $payment4 = new PaymentInformation('payment-004', 'InnoMuster AG', new BIC('POFICHBEXXX'), new IBAN('CH6309000000250097798')); + $payment4->addTransaction($transaction10); $payment4->addTransaction($transaction11); - $payment4->addTransaction($transaction12); $payment5 = new PaymentInformation('payment-005', 'InnoMuster AG', new BIC('POFICHBEXXX'), new IBAN('CH6309000000250097798')); $payment5->setCategoryPurpose(new CategoryPurposeCode('SALA')); - $payment5->addTransaction($transaction13); + $payment5->addTransaction($transaction12); $message = new CustomerCreditTransfer('message-001', 'InnoMuster AG'); $message->addPayment($payment); @@ -209,10 +197,10 @@ public function testGroupHeader() $xpath->registerNamespace('pain001', self::SCHEMA); $nbOfTxs = $xpath->evaluate('string(//pain001:GrpHdr/pain001:NbOfTxs)'); - $this->assertEquals('13', $nbOfTxs); + $this->assertEquals('12', $nbOfTxs); $ctrlSum = $xpath->evaluate('string(//pain001:GrpHdr/pain001:CtrlSum)'); - $this->assertEquals('5510.001', $ctrlSum); + $this->assertEquals('4210.001', $ctrlSum); } public function testSchemaValidation() diff --git a/tests/Z38/SwissPayment/Tests/TransactionInformation/BankCreditTransferTest.php b/tests/Z38/SwissPayment/Tests/TransactionInformation/BankCreditTransferTest.php index 2654cca..cec6bcb 100644 --- a/tests/Z38/SwissPayment/Tests/TransactionInformation/BankCreditTransferTest.php +++ b/tests/Z38/SwissPayment/Tests/TransactionInformation/BankCreditTransferTest.php @@ -3,7 +3,6 @@ namespace Z38\SwissPayment\Tests\TransactionInformation; use Z38\SwissPayment\BIC; -use Z38\SwissPayment\EmptyPostalAddress; use Z38\SwissPayment\IBAN; use Z38\SwissPayment\Money; use Z38\SwissPayment\StructuredPostalAddress; @@ -50,21 +49,4 @@ public function testInvalidAmount() new BIC('PSETPD2SZZZ') ); } - - /** - * @covers ::__construct - * @throws \InvalidArgumentException - */ - public function testWithoutPostalAddress() - { - $transfer = new BankCreditTransfer( - 'id000', - 'name', - new Money\CHF(100), - 'name', - new EmptyPostalAddress(), - new IBAN('CH31 8123 9000 0012 4568 9'), - new BIC('PSETPD2SZZZ') - ); - } }