Skip to content

Commit

Permalink
moved the parsing of type and simplified the parsing method
Browse files Browse the repository at this point in the history
  • Loading branch information
fruitl00p committed Mar 18, 2019
1 parent b04cdd9 commit fa84ac9
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 89 deletions.
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
<?php

namespace Kingsquare\Banking\Transaction;

namespace Kingsquare\Objects;


use ValueObjects\Enum\Enum;

class TransactionType extends Enum
class Type
{
const TRANSFER = 10;
const SEPA_TRANSFER = 11;
const SAVINGS_TRANSFER = 12;


const SEPA_DIRECTDEBIT = 20;

// Codes indicating transfers by the bank.
const BANK_COSTS = 30;
const BANK_INTEREST = 31;



const ATM_WITHDRAWAL = 40;


const PAYMENT_TERMINAL = 50;
const UNKNOWN = 99;


}
48 changes: 19 additions & 29 deletions src/Parser/Banking/Mt940/Engine/Knab.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Kingsquare\Parser\Banking\Mt940\Engine;

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

/**
* Knab parser for Kingsquare mt940 package.
Expand Down Expand Up @@ -152,38 +152,28 @@ public static function isApplicable($string)
return strpos($firstline, 'F01KNABNL2HAXXX0000000000') !== false;
}

/**
* @return int
*/
protected function parseTransactionType()
{
static $map = [
541 => Type::SEPA_TRANSFER,
544 => Type::SEPA_TRANSFER,
547 => Type::SEPA_TRANSFER,
64 => Type::SEPA_DIRECTDEBIT,
93 => Type::BANK_COSTS,
13 => Type::PAYMENT_TERMINAL,
30 => Type::PAYMENT_TERMINAL,
'MSC' => Type::BANK_INTEREST,
'TRF' => Type::UNKNOWN,
];

$code = $this->parseTransactionCode();
switch ($code) {
case 541:
case 544:
case 547:
$result = TransactionType::get(TransactionType::SEPA_TRANSFER);
break;
case 64:
$result = TransactionType::get(TransactionType::SEPA_DIRECTDEBIT);
break;
case 93:
$result = TransactionType::get(TransactionType::BANK_COSTS);
break;
case 13:
case 30:
$result = TransactionType::get(TransactionType::PAYMENT_TERMINAL);
break;
case "MSC":
$result = TransactionType::get(TransactionType::BANK_INTEREST);
break;
case "TRF":
$result = TransactionType::get(TransactionType::UNKNOWN);
break;
default:
var_dump($code);
var_dump($this->getCurrentTransactionData()); die();
throw new \RuntimeException("Don't know code $code for RABOBANK");
if (array_key_exists($code, $map)) {
return $map[$code];
}

return $result;
throw new \RuntimeException("Don't know code $code for this bank");
}

}
77 changes: 30 additions & 47 deletions src/Parser/Banking/Mt940/Engine/Rabo.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Kingsquare\Parser\Banking\Mt940\Engine;

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

/**
* @author Kingsquare ([email protected])
Expand Down Expand Up @@ -159,58 +160,40 @@ public static function isApplicable($string)
return strpos(strtok($string, "\r\n\t"), ':940:') !== false;
}

/**
* @return int
*/
protected function parseTransactionType()
{
static $map = [
102 => Type::SEPA_TRANSFER, // "Betaalopdracht IDEAL"
541 => Type::SEPA_TRANSFER,
544 => Type::SEPA_TRANSFER,
547 => Type::SEPA_TRANSFER,
504 => Type::SAVINGS_TRANSFER,
691 => Type::SAVINGS_TRANSFER,
64 => Type::SEPA_DIRECTDEBIT,
93 => Type::BANK_COSTS,
12 => Type::PAYMENT_TERMINAL,
13 => Type::PAYMENT_TERMINAL,
30 => Type::PAYMENT_TERMINAL,
29 => Type::ATM_WITHDRAWAL,
31 => Type::ATM_WITHDRAWAL,
79 => Type::UNKNOWN,
'MSC' => Type::BANK_INTEREST,
];

$code = $this->parseTransactionCode();
switch ($code) {
case 541:
case 544:
case 102: // "Betaalopdracht IDEAL"
case 547:
$result = TransactionType::get(TransactionType::SEPA_TRANSFER);
break;

case 504:
case 691:
$result = TransactionType::get(TransactionType::SAVINGS_TRANSFER);
break;
case 64:
$result = TransactionType::get(TransactionType::SEPA_DIRECTDEBIT);
break;
case 93:
$result = TransactionType::get(TransactionType::BANK_COSTS);
break;
case 13:
case 12:
case 30:
$result = TransactionType::get(TransactionType::PAYMENT_TERMINAL);
break;
case 29:
case 31:
$result = TransactionType::get(TransactionType::ATM_WITHDRAWAL);
break;
case "MSC":
$result = TransactionType::get(TransactionType::BANK_INTEREST);
break;
case 404: // "Buitenland transactie credit"
if (stripos($this->getCurrentTransactionData(), 'eurobetaling') !== false) {
$result = TransactionType::get(TransactionType::SEPA_TRANSFER);
} else {
$result = TransactionType::get(TransactionType::TRANSFER);
}

break;
case 79: // "Acceptgiro Mobiel Bankieren"
$result = TransactionType::get(TransactionType::UNKNOWN);
break;

default:
var_dump($code);
var_dump($this->getCurrentTransactionData()); die();
throw new \RuntimeException("Don't know code $code for RABOBANK");
if ($code === 404) {
return (stripos($this->getCurrentTransactionData(),
'eurobetaling') !== false) ? Type::SEPA_TRANSFER : Type::TRANSFER;
}

if (array_key_exists($code, $map)) {
return $map[$code];
}

return $result;
throw new \RuntimeException("Don't know code $code for this bank");
}

}

0 comments on commit fa84ac9

Please sign in to comment.