diff --git a/README.md b/README.md index 01b0d51..5b71631 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/Parser/Banking/Mt940/Engine.php b/src/Parser/Banking/Mt940/Engine.php index c1405f1..00265d8 100644 --- a/src/Parser/Banking/Mt940/Engine.php +++ b/src/Parser/Banking/Mt940/Engine.php @@ -32,6 +32,7 @@ abstract class Engine 1100 => Engine\Kbs::class, 1200 => Engine\Zetb::class, 1300 => Engine\Kontist::class, + 1400 => Engine\Wise::class, ]; /** diff --git a/src/Parser/Banking/Mt940/Engine/Wise.php b/src/Parser/Banking/Mt940/Engine/Wise.php new file mode 100644 index 0000000..5b3785b --- /dev/null +++ b/src/Parser/Banking/Mt940/Engine/Wise.php @@ -0,0 +1,109 @@ +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; + } +}