Skip to content
Open
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
24 changes: 18 additions & 6 deletions lib/Fhp/Parser/MT940.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class MT940

const CD_CREDIT = 'credit';
const CD_DEBIT = 'debit';
const CD_CREDIT_CANCELLATION = 'credit_cancellation';
const CD_DEBIT_CANCELLATION = 'debit_cancellation';

/** @var string */
protected $rawData;
Expand Down Expand Up @@ -98,12 +100,22 @@ protected function parseToArray()
$trx = &$result[$this->soaDate]['transactions'];

preg_match('/^\d{6}(\d{4})?(C|D|RC|RD)([A-Z]{1})?([^N]+)N/', $transaction, $trxMatch);
if ($trxMatch[2] == 'C') {
$trx[count($trx)]['credit_debit'] = static::CD_CREDIT;
} elseif ($trxMatch[2] == 'D') {
$trx[count($trx)]['credit_debit'] = static::CD_DEBIT;
} else {
throw new MT940Exception('cd mark not found in: ' . $transaction);

switch($trxMatch[2]) {
case 'C':
$trx[count($trx)]['credit_debit'] = static::CD_CREDIT;
break;
case 'D':
$trx[count($trx)]['credit_debit'] = static::CD_DEBIT;
break;
case 'RC':
$trx[count($trx)]['credit_debit'] = static::CD_CREDIT_CANCELLATION;
break;
case 'RD':
$trx[count($trx)]['credit_debit'] = static::CD_DEBIT_CANCELLATION;
break;
default:
throw new MT940Exception('cd mark not found in: ' . $transaction);
}

$amount = $trxMatch[4];
Expand Down