Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Currently the following engines are included:
- KBS ([here](./src/Parser/Banking/Mt940/Engine/Kbs.php))
- ZETB ([here](./src/Parser/Banking/Mt940/Engine/Zetb.php))
- KONTIST ([here](./src/Parser/Banking/Mt940/Engine/Kontist.php))
- WISE ([here](./src/Parser/Banking/Mt940/Engine/Wise.php))
- a default `UNKNOWN`-engine ([here](./src/Parser/Banking/Mt940/Engine/Unknown.php))

### Custom engines
Expand Down
1 change: 1 addition & 0 deletions src/Parser/Banking/Mt940/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ abstract class Engine
1100 => Engine\Kbs::class,
1200 => Engine\Zetb::class,
1300 => Engine\Kontist::class,
1400 => Engine\Wise::class,
];

/**
Expand Down
109 changes: 109 additions & 0 deletions src/Parser/Banking/Mt940/Engine/Wise.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php

namespace Kingsquare\Parser\Banking\Mt940\Engine;

use Kingsquare\Banking\Transaction\Type;
use Kingsquare\Parser\Banking\Mt940\Engine;

class Wise extends Engine
{
/**
*
* {@inheritdoc}
* @see \Kingsquare\Parser\Banking\Mt940\Engine::parseStatementBank()
*/
protected function parseStatementBank()
{
return 'WISE';
}

/**
* uses field 25 to gather accoutnumber.
*
* @return string accountnumber
*/
protected function parseStatementAccount()
{
$results = [];
if (preg_match('/:25:([\d\.]+)*/', $this->getCurrentStatementData(), $results)
&& !empty($results[1])
) {
return $this->sanitizeAccount($results[1]);
}

// SEPA / IBAN
if (preg_match('/:25:([A-Z0-9]{8}[\d\.]+)*/', $this->getCurrentStatementData(), $results)
&& !empty($results[1])
) {
return $this->sanitizeAccount($results[1]);
}

return 'WISE';
}


/**
* uses the 61 field to determine amount/value of the transaction.
*
* @return float
*/
protected function parseTransactionPrice()
{
$results = [];
if (preg_match('/^:61:.*?[CD]([\d,\.]+)F/i', $this->getCurrentTransactionData(), $results)
&& !empty($results[1])
) {
return $this->sanitizePrice($results[1]);
}

return 0;
}

/**
* uses the 61 field to get the bank specific transaction code.
*
* @return string
*/
protected function parseTransactionCode()
{
$results = [];
if (preg_match('/^:61:.*?F(.{3}).*/', $this->getCurrentTransactionData(), $results)
&& !empty($results[1])
) {
return trim($results[1]);
}
return '';
}

/**
* @TODO WIP get this into the transaction somehow.. (possibly as a decorator over the transactions?)
* @return int
*/
protected function parseTransactionType()
{
static $map = [
'CHG' => Type::BANK_COSTS,
'MSC' => Type::BANK_INTEREST,
'TRF' => Type::TRANSFER,
'FEX' => Type::UNKNOWN,
];

$code = $this->parseTransactionCode();
if (array_key_exists($code, $map)) {
return $map[$code];
}
throw new \RuntimeException("Don't know code $code for this bank");
}

/**
*
* {@inheritdoc}
* @see \Kingsquare\Parser\Banking\Mt940\Engine::isApplicable()
*/
public static function isApplicable($string)
{
$firstline = strtok($string, "\r\n\t");

return strpos($firstline, 'F01TRWIGB2LAXXX0000000000') !== false;
}
}