Skip to content

Commit

Permalink
Adjust eref information for the ING bank. (#57)
Browse files Browse the repository at this point in the history
This bank gives the payment information in both the /EREF/ field and the
/REMI/USTD// field.
  • Loading branch information
ccsenny authored May 31, 2024
1 parent 008d057 commit 7907ec4
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 24 deletions.
7 changes: 5 additions & 2 deletions lib/Jejik/MT940/Parser/Ing.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,11 @@ protected function code(array $lines): ?string
*/
protected function eref(array $lines): ?string
{
if (isset($this->codeWords($lines)[self::CODEWORD_EREF])) {
return $this->codeWords($lines)[self::CODEWORD_EREF];
if (isset($this->codeWords($lines)[self::CODEWORD_EREF]) || isset($this->codeWords($lines)[self::CODEWORD_REMI_USTD])) {
return sprintf('%s %s',
isset($this->codeWords($lines)[self::CODEWORD_EREF]) ? $this->codeWords($lines)[self::CODEWORD_EREF] : null,
isset($this->codeWords($lines)[self::CODEWORD_REMI_USTD]) ? $this->codeWords($lines)[self::CODEWORD_REMI_USTD] : null
);
}

return null;
Expand Down
30 changes: 30 additions & 0 deletions tests/Jejik/Tests/MT940/Fixture/document/ing-4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
0000 01INGBNL2AXXXX00001
0000 01INGBNL2AXXXX00001
940 00
:20:ING
:25:1234567
:28C:000
:60F:C100722EUR0,00
:61:100420D768,51NTRFPREF//31100900061605
/TRCD/00200/
:86:/PREF/SEPA-20230418220132-60947700-P1//REMI/USTD//TOTAAL 5 VZ/
:61:100723C105,20NTRFNONREF//31101100047720
/TRCD/00100/
:86:/CNTP/NL71ABNA0841238***/ABNANL2A/GREENFLUX ASSETS BV///REMI/USTD
//Nr. LNT22000057 / 21.2.2023Nr. LNT22000079 / 21.3.2023Nr. LNT22
000068 / 21.2.2023/
:61:100723C335,53NTRFEREF//31102000055044
/TRCD/00100/
:86:/EREF/SCT-1-BO230019-R1//CNTP/NL68RABO0106200***/RABONL2U/Lambrix
Elektrotechniek///REMI/USTD//110130590/
:61:100723C327,78NCMIPPM9455956//31103100006242
/TRCD/05001/
:86:/CNTP/NL21INGB0650141***//Rexel Holding Netherlands B.V.///REMI/U
STD//POOL-M NL21INGB0650141172 POOL-S NL30INGB0008693687 PPM94559
56 22/07/2010/
:62F:C230420EUR0,00
:64:C230420EUR0,00
:65:C230421EUR0,00
:65:C230422EUR0,00
:86:D000001C000003D768,51C768,51
-XXX
147 changes: 125 additions & 22 deletions tests/Jejik/Tests/MT940/Parser/IngTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

namespace Jejik\Tests\MT940\Parser;

use Jejik\MT940\Balance;
use Jejik\MT940\Exception\NoParserFoundException;
use Jejik\MT940\Parser\Ing;
use Jejik\MT940\Reader;
use PHPUnit\Framework\TestCase;

Expand All @@ -24,6 +27,7 @@
*/
class IngTest extends TestCase
{

/**
* @dataProvider statementsProvider
*
Expand All @@ -46,9 +50,9 @@ public function testStatement($statements)
*/
public function testBalance($statements)
{
/** @var \Jejik\MT940\Balance $balance */
/** @var Balance $balance */
$balance = $statements[0]->getOpeningBalance();
$this->assertInstanceOf(\Jejik\MT940\Balance::class, $balance);
$this->assertInstanceOf(Balance::class, $balance);
$this->assertEquals('2010-07-22 00:00:00', $balance->getDate()->format('Y-m-d H:i:s'));
$this->assertEquals('EUR', $balance->getCurrency());
$this->assertEquals(0.0, $balance->getAmount());
Expand All @@ -58,24 +62,49 @@ public function testBalance($statements)
* @dataProvider statementsProvider
*
* @param array $statements
* @param int|null $numberOfTransactions
* @param string|null $bookDate
* @param string|null $valueDate
* @param float|null $amount
* @param array|null $transactionsData
*/
public function testTransaction($statements)
public function testTransaction(
array $statements,
?int $numberOfTransactions,
?string $bookDate,
?string $valueDate,
?float $amount,
?array $transactionsData
): void
{
$transactions = $statements[0]->getTransactions();
$this->assertCount(7, $transactions);
$this->assertCount($numberOfTransactions, $transactions);

$this->assertEquals('2010-07-22 00:00:00', $transactions[0]->getBookDate()->format('Y-m-d H:i:s'));
$this->assertEquals(null, $transactions[0]->getValueDate());
$this->assertEquals(-25.03, $transactions[0]->getAmount());
$this->assertEquals($bookDate, $transactions[0]->getBookDate()->format('Y-m-d H:i:s'));
$this->assertEquals($valueDate, $transactions[0]->getValueDate());
$this->assertEquals($amount, $transactions[0]->getAmount());

$expected = "RC AFREKENING BETALINGSVERKEER\r\n"
. "BETREFT REKENING 4715589 PERIODE: 01-10-2010 / 31-12-2010\r\n"
. "ING Bank N.V. tarifering ING";
. "BETREFT REKENING 4715589 PERIODE: 01-10-2010 / 31-12-2010\r\n"
. "ING Bank N.V. tarifering ING";

if (!$transactionsData) {
$this->assertEquals($expected, $transactions[0]->getDescription());
}

$this->assertEquals($expected, $transactions[0]->getDescription());
if (null !== $transactions[1]->getContraAccount()) {
$this->assertEquals('0111111111', $transactions[1]->getContraAccount()->getNumber());
}

if ($transactionsData) {
for ($i = 0; $i < count($transactions); $i++) {
$transactionInformations = json_decode($transactionsData[$i], true);
foreach ($transactionInformations as $key => $value) {
$method = 'get' . $key;
$this->assertEquals($value, $transactions[$i]->$method());
}
}
}
}

/**
Expand All @@ -86,26 +115,100 @@ public function testTransaction($statements)
public function testBookDate($statements)
{
$transactions = $statements[0]->getTransactions();
if (null !== $transactions[6]->getValueDate()) {
$this->assertEquals('2010-07-22 00:00:00', $transactions[6]->getValueDate()->format('Y-m-d H:i:s'));
if (null !== $transactions[count($transactions)-1]->getValueDate()) {
$this->assertEquals('2010-07-22 00:00:00', $transactions[count($transactions)-1]->getValueDate()->format('Y-m-d H:i:s'));
}
$this->assertEquals('2010-07-23 00:00:00', $transactions[6]->getBookDate()->format('Y-m-d H:i:s'));
$this->assertEquals('2010-07-23 00:00:00', $transactions[count($transactions)-1]->getBookDate()->format('Y-m-d H:i:s'));
}

/**
* @dataProvider statementsProvider
* @throws \Jejik\MT940\Exception\NoParserFoundException
* @throws NoParserFoundException
*/
public function statementsProvider(): array
{
$reader = new Reader();
$reader->addParser('Ing', \Jejik\MT940\Parser\Ing::class);

return array(
array($reader->getStatements(file_get_contents(__DIR__ . '/../Fixture/document/ing-dos.txt'))),
array($reader->getStatements(file_get_contents(__DIR__ . '/../Fixture/document/ing-unix.txt'))),
array($reader->getStatements(file_get_contents(__DIR__ . '/../Fixture/document/ing-unix-2.txt'))),
array($reader->getStatements(file_get_contents(__DIR__ . '/../Fixture/document/ing-unix-3.txt'))),
);
return [
[
$reader->getStatements(file_get_contents(__DIR__ . '/../Fixture/document/ing-dos.txt')),
'number of transactions' => 7,
'bookDate' => '2010-07-22 00:00:00',
'valueDate' => null,
'amount' => -25.03,
[]
],
[
$reader->getStatements(file_get_contents(__DIR__ . '/../Fixture/document/ing-unix.txt')),
'number of transactions' => 7,
'bookDate' => '2010-07-22 00:00:00',
'valueDate' => null,
'amount' => -25.03,
[]
],
[
$reader->getStatements(file_get_contents(__DIR__ . '/../Fixture/document/ing-unix-2.txt')),
'number of transactions' => 7,
'bookDate' => '2010-07-22 00:00:00',
'valueDate' => null,
'amount' => -25.03,
[]
],
[
$reader->getStatements(file_get_contents(__DIR__ . '/../Fixture/document/ing-unix-3.txt')),
'number of transactions' => 7,
'bookDate' => '2010-07-22 00:00:00',
'valueDate' => null,
'amount' => -25.03,
[]
],
[
$reader->getStatements(file_get_contents(__DIR__ . '/../Fixture/document/ing-4.txt')),
'number of transactions' => 4,
'bookDate' => '2010-04-20 00:00:00',
'valueDate' => null,
'amount' => -768.51,
[
'{
"Code":"TRF",
"TransactionCode":"00200",
"TxText":"TOTAAL 5 VZ/",
"Eref":"TOTAAL 5 VZ/",
"Bic":null,
"Iban":null,
"AccountHolder":null,
"RawSubfieldsData":"/PREF/SEPA-20230418220132-60947700-P1//REMI/USTD//TOTAAL 5 VZ/"
}',
'{
"Code":"TRF",
"TransactionCode":"00100",
"TxText":"Nr. LNT22000057 / 21.2.2023Nr. LNT22000079 / 21.3.2023Nr. LNT22000068 / 21.2.2023/",
"Eref":"Nr. LNT22000057 / 21.2.2023Nr. LNT22000079 / 21.3.2023Nr. LNT22000068 / 21.2.2023/",
"Bic":"ABNANL2A",
"Iban":"NL71ABNA0841238***",
"AccountHolder":"GREENFLUX ASSETS BV",
"RawSubfieldsData":"/CNTP/NL71ABNA0841238***/ABNANL2A/GREENFLUX ASSETS BV///REMI/USTD//Nr. LNT22000057 / 21.2.2023Nr. LNT22000079 / 21.3.2023Nr. LNT22000068 / 21.2.2023/"
}',
'{
"Code":"TRF",
"TransactionCode":"00100",
"TxText":"110130590/",
"Eref":"SCT-1-BO230019-R1/ 110130590/",
"Bic":"RABONL2U",
"Iban":"NL68RABO0106200***",
"AccountHolder":"Lambrix Elektrotechniek",
"RawSubfieldsData":"/EREF/SCT-1-BO230019-R1//CNTP/NL68RABO0106200***/RABONL2U/Lambrix Elektrotechniek///REMI/USTD//110130590/"
}',
'{
"Code":"CMI",
"TransactionCode":"05001",
"TxText":"POOL-M NL21INGB0650141172 POOL-S NL30INGB0008693687 PPM9455956 22/07/2010/",
"Eref":"POOL-M NL21INGB0650141172 POOL-S NL30INGB0008693687 PPM9455956 22/07/2010/",
"Bic":null,
"Iban":"NL21INGB0650141***",
"AccountHolder":"Rexel Holding Netherlands B.V.",
"RawSubfieldsData":"/CNTP/NL21INGB0650141***//Rexel Holding Netherlands B.V.///REMI/USTD//POOL-M NL21INGB0650141172 POOL-S NL30INGB0008693687 PPM9455956 22/07/2010/"}',
]
],
];
}
}

0 comments on commit 7907ec4

Please sign in to comment.