Skip to content

Commit

Permalink
Parse transaction supplementary details for German banks (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
geekdevs authored Jul 28, 2021
1 parent b9e0f9f commit 76b215a
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/Jejik/MT940/Parser/AbstractParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ protected function transaction(array $lines): TransactionInterface
->setCode($this->code($lines))
->setRef($this->ref($lines))
->setBankRef($this->bankRef($lines))
->setSupplementaryDetails($this->supplementaryDetails($lines))
->setGVC($this->gvc($lines))
->setTxText($this->txText($lines))
->setPrimanota($this->primanota($lines))
Expand Down Expand Up @@ -582,6 +583,14 @@ protected function bankRef(array $lines): ?string
return null;
}

/**
* Parse supplementary details
*/
protected function supplementaryDetails(array $lines): ?string
{
return null;
}

/**
* Parse txText for provided transaction lines
*/
Expand Down
12 changes: 12 additions & 0 deletions lib/Jejik/MT940/Parser/GermanBank.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ protected function code(array $lines): ?string
return substr($match[5], 0, 3);
}

/**
* Parse supplementary details
*/
protected function supplementaryDetails(array $lines): ?string
{
$refLine = isset($lines[0]) ? $lines[0] : null;

$parts = preg_split("/\\r\\n|\\r|\\n/", $refLine, 2);

return isset($parts[1]) ? $parts[1] : null;
}

/**
* Parse ref for provided transaction lines
*/
Expand Down
24 changes: 24 additions & 0 deletions lib/Jejik/MT940/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ class Transaction implements TransactionInterface
*/
private $bankRef;

/**
* @var string
*/
private $supplementaryDetails;

/**
* @var string
*/
Expand Down Expand Up @@ -265,6 +270,25 @@ public function setBankRef(string $bankRef = null): TransactionInterface
return $this;
}

/**
* @return string|null
*/
public function getSupplementaryDetails(): ?string
{
return $this->supplementaryDetails;
}

/**
* @param string|null $supplementaryDetails
* @return TransactionInterface
*/
public function setSupplementaryDetails(?string $supplementaryDetails): TransactionInterface
{
$this->supplementaryDetails = $supplementaryDetails;

return $this;
}

/**
* Get GVC for this transaction
*/
Expand Down
10 changes: 10 additions & 0 deletions lib/Jejik/MT940/TransactionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ public function getBankRef(): ?string;
*/
public function setBankRef(string $bankRef = null): TransactionInterface;

/**
* Set supplementary details
*/
public function setSupplementaryDetails(?string $supplementaryDetails): TransactionInterface;

/**
* Get supplementary details
*/
public function getSupplementaryDetails(): ?string;

/**
* Get GVC for this transaction
*/
Expand Down
1 change: 1 addition & 0 deletions tests/Jejik/Tests/MT940/Parser/DeutscheBankTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public function testTransaction()
$this->assertNull($transactions[0]->getCode());
$this->assertEquals('KREF+', $transactions[0]->getRef());
$this->assertEquals('2016021783252833', $transactions[0]->getBankRef());
$this->assertEquals('/OCMT/EUR11,85//CHGS/EUR0,50/', $transactions[0]->getSupplementaryDetails());

$this->assertEquals('109', $transactions[0]->getGVC());
$this->assertEquals('SEPA-LASTSCHR. RETOURE CORE', $transactions[0]->getTxText());
Expand Down

0 comments on commit 76b215a

Please sign in to comment.