-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved the parsing of type and simplified the parsing method
- Loading branch information
Showing
3 changed files
with
51 additions
and
89 deletions.
There are no files selected for viewing
15 changes: 2 additions & 13 deletions
15
src/Objects/TransactionType.php → src/Banking/Transaction/Type.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]) | ||
|
@@ -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"); | ||
} | ||
|
||
} |