Skip to content

Commit

Permalink
Use null to express no address
Browse files Browse the repository at this point in the history
  • Loading branch information
z38 committed Jul 16, 2018
1 parent ecf2ae5 commit 87ed4f6
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 90 deletions.
25 changes: 0 additions & 25 deletions src/Z38/SwissPayment/EmptyPostalAddress.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Z38\SwissPayment\IID;
use Z38\SwissPayment\Money;
use Z38\SwissPayment\PaymentInformation\PaymentInformation;
use Z38\SwissPayment\PostalAddressInterface;

/**
* BankCreditTransfer contains all the information about a type 3 transaction.
Expand All @@ -35,7 +34,7 @@ class BankCreditTransfer extends CreditTransfer
*
* @throws \InvalidArgumentException When the amount is not in EUR or CHF or when the creditor agent is not BIC or IID.
*/
public function __construct($instructionId, $endToEndId, Money\Money $amount, $creditorName, PostalAddressInterface $creditorAddress, IBAN $creditorIBAN, FinancialInstitutionInterface $creditorAgent)
public function __construct($instructionId, $endToEndId, Money\Money $amount, $creditorName, $creditorAddress, IBAN $creditorIBAN, FinancialInstitutionInterface $creditorAgent)
{
if (!$amount instanceof Money\EUR && !$amount instanceof Money\CHF) {
throw new InvalidArgumentException(sprintf(
Expand Down
16 changes: 8 additions & 8 deletions src/Z38/SwissPayment/TransactionInformation/CreditTransfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract class CreditTransfer
protected $creditorName;

/**
* @var PostalAddressInterface
* @var PostalAddressInterface|null
*/
protected $creditorAddress;

Expand Down Expand Up @@ -60,15 +60,15 @@ abstract class CreditTransfer
/**
* Constructor
*
* @param string $instructionId Identifier of the instruction (should be unique within the message)
* @param string $endToEndId End-To-End Identifier of the instruction (passed unchanged along the complete processing chain)
* @param Money $amount Amount of money to be transferred
* @param string $creditorName Name of the creditor
* @param PostalAddressInterface $creditorAddress Address of the creditor
* @param string $instructionId Identifier of the instruction (should be unique within the message)
* @param string $endToEndId End-To-End Identifier of the instruction (passed unchanged along the complete processing chain)
* @param Money $amount Amount of money to be transferred
* @param string $creditorName Name of the creditor
* @param PostalAddressInterface|null $creditorAddress Address of the creditor
*
* @throws \InvalidArgumentException When any of the inputs contain invalid characters or are too long.
*/
public function __construct($instructionId, $endToEndId, Money $amount, $creditorName, PostalAddressInterface $creditorAddress)
public function __construct($instructionId, $endToEndId, Money $amount, $creditorName, PostalAddressInterface $creditorAddress = null)
{
$this->instructionId = Text::assertIdentifier($instructionId);
$this->endToEndId = Text::assertIdentifier($endToEndId);
Expand Down Expand Up @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);

Expand Down
46 changes: 17 additions & 29 deletions tests/Z38/SwissPayment/Tests/Message/CustomerCreditTransferTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -136,27 +125,27 @@ protected function buildMessage()
new BIC('NOLADE21EMS')
);

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

0 comments on commit 87ed4f6

Please sign in to comment.