Skip to content

Commit

Permalink
PstlAdr field is optional is the Dbtr section for BankCreditTransfer …
Browse files Browse the repository at this point in the history
…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)
  • Loading branch information
celinederoland-infomaniak committed May 23, 2018
1 parent 862fafa commit ecf2ae5
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 17 deletions.
25 changes: 25 additions & 0 deletions src/Z38/SwissPayment/EmptyPostalAddress.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Created by PhpStorm.
* User: celinederoland
* Date: 23.05.18
* Time: 11:40
*/

namespace Z38\SwissPayment;

class EmptyPostalAddress implements PostalAddressInterface {

/**
* Returns a XML representation of the address
*
* @param \DOMDocument $doc
*
* @return \DOMElement The built DOM element
*/
public function asDom(\DOMDocument $doc) {

return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ protected function buildCreditor(\DOMDocument $doc)
{
$creditor = $doc->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;
}
Expand Down
44 changes: 28 additions & 16 deletions tests/Z38/SwissPayment/Tests/Message/CustomerCreditTransferTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -125,27 +136,27 @@ protected function buildMessage()
new BIC('NOLADE21EMS')
);

$transaction10 = new ISRCreditTransfer(
$transaction11 = new ISRCreditTransfer(
'instr-010',
'e2e-010',
new Money\CHF(20000), // CHF 200.00
new ISRParticipant('01-1439-8'),
'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
Expand All @@ -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);
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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')
);
}
}

0 comments on commit ecf2ae5

Please sign in to comment.