Skip to content

Commit

Permalink
Merge remote-tracking branch 'Einenlum/feature/add-isr-credit-transfer'
Browse files Browse the repository at this point in the history
  • Loading branch information
z38 committed Aug 1, 2016
2 parents 6569706 + d6b10e7 commit 34216c3
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 4 deletions.
91 changes: 91 additions & 0 deletions src/Z38/SwissPayment/TransactionInformation/ISRCreditTransfer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

namespace Z38\SwissPayment\TransactionInformation;

use DOMDocument;
use Z38\SwissPayment\Money;
use Z38\SwissPayment\PaymentInformation\PaymentInformation;
use Z38\SwissPayment\PostalAccount;

/**
* ISRCreditTransfer contains all the information about a ISR (type 1) transaction.
*/
class ISRCreditTransfer extends CreditTransfer
{
/**
* @var PostalAccount
*/
protected $creditorAccount;

/**
* @var string
*/
protected $creditorReference;

/**
* {@inheritdoc}
*
* @param PostalAccount $creditorAccount Postal account of the creditor
* @param string $creditorReference Creditor reference information from remittance information
*
* @throws \InvalidArgumentException. An InvalidArgumentException is thrown if amount is not EUR or CHF
*/
public function __construct($instructionId, $endToEndId, Money\Money $amount, PostalAccount $creditorAccount, $creditorReference)
{
if (false === $amount instanceof Money\EUR && false === $amount instanceof Money\CHF) {
throw new \InvalidArgumentException(sprintf(
'Amount must be an instance of Z38\SwissPayment\Money\EUR or Z38\SwissPayment\Money\CHF. Instance of %s given.',
get_class($amount)
));
}

$this->instructionId = (string) $instructionId;
$this->endToEndId = (string) $endToEndId;
$this->amount = $amount;
$this->creditorAccount = $creditorAccount;
$this->creditorReference = $creditorReference;
}

/**
* {@inheritdoc}
*/
public function asDom(DOMDocument $doc, PaymentInformation $paymentInformation)
{
$root = $this->buildHeader($doc, $paymentInformation, 'CH01');

$creditorAccount = $doc->createElement('CdtrAcct');
$creditorAccount->appendChild($this->creditorAccount->asDom($doc));
$root->appendChild($creditorAccount);
$root->appendChild($this->buildRemittanceInformation($doc));

return $root;
}

/**
* Builds a DOM node of the Remittance Information field
*
* @param \DOMDocument $doc
*
* @return \DOMNode The built DOM node
*
* @throws \LogicException When no remittance information is set
*/
protected function buildRemittanceInformation(\DOMDocument $doc)
{
if ($this->creditorReference) {
$remittanceInformation = $doc->createElement('RmtInf');

$structured = $doc->createElement('Strd');
$remittanceInformation->appendChild($structured);

$creditorReferenceInformation = $doc->createElement('CdtrRefInf');
$structured->appendChild($creditorReferenceInformation);

$creditorReferenceInformation->appendChild($doc->createElement('Ref', $this->creditorReference));

return $remittanceInformation;
} else {
throw new \LogicException('Can not build node without data.');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Z38\SwissPayment\TransactionInformation\ForeignCreditTransfer;
use Z38\SwissPayment\TransactionInformation\IS1CreditTransfer;
use Z38\SwissPayment\TransactionInformation\IS2CreditTransfer;
use Z38\SwissPayment\TransactionInformation\ISRCreditTransfer;
use Z38\SwissPayment\TransactionInformation\SEPACreditTransfer;
use Z38\SwissPayment\UnstructuredPostalAddress;

Expand Down Expand Up @@ -110,9 +111,17 @@ protected function buildMessage()
);
$transaction8->setIntermediaryAgent(new BIC('SWHQBEBB'));

$transaction9 = new SEPACreditTransfer(
$transaction9 = new ISRCreditTransfer(
'instr-009',
'e2e-009',
new Money\CHF(20000), // CHF 200.00
new PostalAccount('80-5928-4'),
'210000000003139471430009017'
);

$transaction10 = new SEPACreditTransfer(
'instr-010',
'e2e-010',
new Money\EUR(10000), // EUR 100.00
'Bau Muster AG',
new UnstructuredPostalAddress('Musterallee 11', '10115 Berlin', 'DE'),
Expand All @@ -131,9 +140,10 @@ protected function buildMessage()
$payment2->addTransaction($transaction6);
$payment2->addTransaction($transaction7);
$payment2->addTransaction($transaction8);
$payment->addTransaction($transaction9);

$payment3 = new SEPAPaymentInformation('payment-003', 'InnoMuster AG', new BIC('POFICHBEXXX'), new IBAN('CH6309000000250097798'));
$payment3->addTransaction($transaction9);
$payment3->addTransaction($transaction10);

$message = new CustomerCreditTransfer('message-001', 'InnoMuster AG');
$message->addPayment($payment);
Expand All @@ -153,10 +163,10 @@ public function testGroupHeader()
$xpath->registerNamespace('pain001', self::NS_URI_ROOT.self::SCHEMA);

$nbOfTxs = $xpath->evaluate('string(//pain001:GrpHdr/pain001:NbOfTxs)');
$this->assertEquals('9', $nbOfTxs);
$this->assertEquals('10', $nbOfTxs);

$ctrlSum = $xpath->evaluate('string(//pain001:GrpHdr/pain001:CtrlSum)');
$this->assertEquals('3310.00', $ctrlSum);
$this->assertEquals('3510.00', $ctrlSum);
}

public function testSchemaValidation()
Expand Down

0 comments on commit 34216c3

Please sign in to comment.