Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new engine is added for Wise #93

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
108 changes: 108 additions & 0 deletions src/Parser/Banking/Mt940/Engine/Wise.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php

namespace Kingsquare\Parser\Banking\Mt940\Engine;

use Kingsquare\Parser\Banking\Mt940\Engine;

sevannerse marked this conversation as resolved.
Show resolved Hide resolved
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 = [
'FEX' => Type::BANK_TRANSFER,
sevannerse marked this conversation as resolved.
Show resolved Hide resolved
'CHG' => Type::BANK_COSTS,
'MSC' => Type::BANK_INTEREST,
'TRF' => 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;
}
}