Skip to content

Commit

Permalink
import features from chargecloud
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominic Richter committed Dec 19, 2023
1 parent fba9605 commit 62669c8
Show file tree
Hide file tree
Showing 30 changed files with 1,393 additions and 20 deletions.
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
"homepage": "http://www.jejik.com"
},
{
"name": "powercloud GmbH / Dominic Richter",
"email": "[email protected]",
"homepage": "https://www.power.cloud"
"name": "Dominic Richter",
"homepage": "https://twitnic.de"
}
],
"require": {
"php": ">=7.2.0||^8.0"
"php": ">=7.1.0||^8.0"
},
"require-dev": {
"phpunit/phpunit": "^8",
Expand Down
69 changes: 69 additions & 0 deletions lib/Jejik/MT940/Parser/AbnAmro.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,73 @@ public function getAllowedBLZ(): array
{
return [];
}

/**
* For this bank, the gvc is in line :61:
*
* @param array $lines
* @return string|null
*/
protected function gvc(array $lines): ?string
{
// get :61: line -- it is first in provided array [:61:,:86:,....]
$codeLine = isset($lines[0]) ? $lines[0] : null;

// assure code line
if ($codeLine == null) {
return null;
}

// match it
preg_match('#(\d{6})(\d{4})?(R?(?:C|D))([0-9,]{1,15})N(\d{3})([a-zA-Z0-9]+)#', $codeLine, $match);

// assure match
if (!isset($match[5])) {
return null;
}

// return
return substr($match[5], 0, 3);
}

/** Get raw data of :86:
*
* @param array $lines
* @return string|string[]|null
*/
protected function rawSubfieldsData(array $lines)
{
$subflieldline = isset($lines[1]) ? $lines[1] : null;
$multiUseLine = $this->removeNewLinesFromLine($subflieldline);

return $multiUseLine;
}

/**
* @param array $lines
* @return string|null
*/
protected function kref(array $lines): ?string
{
// get :86: line -- it is second in provided array [:61:,:86:,....]
$krefLine = isset($lines[1]) ? $lines[1] : null;

/** @var string $krefLine */
preg_match("#(\/PREF\/)+([a-zA-ZöäüÖÄÜß0-9\-\+\.\_\s]+)?(\/NRTX\/)?(:62)?#", $this->removeNewLinesFromLine($krefLine), $match);

if (!isset($match[2])) {
return null;
}

return $match[2];
}

/**
* @param string $stringLine
* @return string
*/
private function removeNewLinesFromLine(string $stringLine): string
{
return str_replace(["\n", "\r", "\r\n"], '', $stringLine);
}
}
34 changes: 32 additions & 2 deletions lib/Jejik/MT940/Parser/AbstractParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ protected function transaction(array $lines): TransactionInterface

// Parse the amount
$amount = (float)str_replace(',', '.', $match[4]);
if (in_array($match[3], array('D', 'DR','RC','RCR'))) {
if (in_array($match[3], array('D', 'DR','RC','RCR','RDR'))) {
$amount *= -1;
}

Expand Down Expand Up @@ -497,7 +497,10 @@ protected function transaction(array $lines): TransactionInterface
->setOamt($this->oamt($lines))
->setAbwa($this->abwa($lines))
->setAbwe($this->abwe($lines))
->setDescription($this->description($description));
->setDescription($this->description($description))
->setRawSubfieldsData($this->rawSubfieldsData($lines))
->setCodeWords($this->codeWords($lines))
->setTransactionCode($this->transactionCode($lines));

return $transaction;
}
Expand Down Expand Up @@ -739,4 +742,31 @@ protected function abwe(array $lines): ?string
{
return null;
}

/**
* @param array $lines
* @return null
*/
protected function rawSubfieldsData(array $lines)
{
return null;
}

/**
* @param array $lines
* @return null
*/
protected function codeWords(array $lines)
{
return null;
}

/**
* @param array $lines
* @return null
*/
protected function transactionCode(array $lines)
{
return null;
}
}
35 changes: 35 additions & 0 deletions lib/Jejik/MT940/Parser/BayerischeLandesbank.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php declare(strict_types=1);

namespace Jejik\MT940\Parser;
/**
* Class BayerischeLandesbank
* @package Jejik\MT940\Parser
*/
class BayerischeLandesbank extends GermanBank
{
/**
* @return string[]
*/
public function getAllowedBLZ(): array
{
return ['70050000'];
}

/**
* @param string $text
* @return bool
*/
public function accept(string $text): bool
{
$allowedUniqueIdentifiers = [
':20:21766916',
];

$mt940Identifier = substr($text, 0, 12);
if (in_array($mt940Identifier, $allowedUniqueIdentifiers)) {
return true;
}

return $this->isBLZAllowed($text);
}
}
157 changes: 157 additions & 0 deletions lib/Jejik/MT940/Parser/Bil.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Jejik\MT940 library
*
* Copyright (c) 2012 Sander Marechal <s.marechal@jejik.com>
* Licensed under the MIT license
*
* For the full copyright and license information, please see the LICENSE
* file that was distributed with this source code.
*/

namespace Jejik\MT940\Parser;

/**
* Parser for Banque Internationale a Luxembourg
*
* Class Bil
* @package Jejik\MT940\Parser
*
*/
class Bil extends AbstractParser
{

/**
* @param string $text
* @return bool
*/
public function accept(string $text): bool
{
if (empty($text)) {
return false;
}
{
$allowedUniqueIdentifiers = [
':20:BILMT940',
];

$mt940Identifier = substr($text, 0, 12);
if (in_array($mt940Identifier, $allowedUniqueIdentifiers)) {
return true;
}

return $this->isBLZAllowed($text);
}
}

/**
* Get an array of allowed BLZ for this bank
*/
public function getAllowedBLZ(): array
{
return [];
}

/**
* @param array $lines
* @return string|null
*/
protected function gvc(array $lines): ?string
{
$gvcLine = $lines[1] ?? null;

if ($gvcLine == null) {
return null;
}

return substr($gvcLine, 0, 3);
}

/**
* Parse txText for provided transaction lines
*/
protected function txText(array $lines): ?string
{
$txTextLine = isset($lines[1]) ? $lines[1] : null;

if ($txTextLine === null) {
return null;
}

/** @var string $txTextLine */
preg_match('#\?00([a-zA-Z0-9\-\s\.]+)#', $this->removeNewLinesFromLine($txTextLine), $match);

if (!isset($match[1])) {
return null;
}

return $match[1];
}

/**
* Remove all new lines and carriage returns from provided input line
*/
private function removeNewLinesFromLine(string $stringLine): string
{
return str_replace(["\n", "\r", "\r\n"], '', $stringLine);
}

/** Get raw data of subfields ?20 - ?29
*
* @param array $lines
* @return string|string[]|null
*/
protected function rawSubfieldsData(array $lines)
{
$subflieldline = isset($lines[1]) ? $lines[1] : null;

$multiUseLine = $this->removeNewLinesFromLine($subflieldline);
preg_match('#(\?2[0-9][^?]+)+#', $multiUseLine, $match);

if (!isset($match[0])) {
return null;
}

return preg_replace('#(\?2[0-9])#', '', $match[0]);
}

/**
* Parse code for provided transaction lines
*/
protected function code(array $lines): ?string
{
$codeLine = isset($lines[0]) ? $lines[0] : null;

if ($codeLine == null) {
return null;
}
preg_match('#(\d{6})(\d{4})?(R?(?:C|D)R?)([0-9,]{1,15})N([a-zA-Z0-9]+)#', $codeLine, $match);

if (!isset($match[5])) {
return null;
}
return substr($match[5], 0, 3);
}

/**
* Parse ref for provided transaction lines
*/
protected function ref(array $lines): ?string
{

$refLine = isset($lines[0]) ? $lines[0] : null;

if ($refLine == null) {
return null;
}
preg_match('#(?:\d{10})?(R?(?:C|D)R?)(?:[\d,]{1,15})N(.){3}([A-Za-z0-9\.]+)#', $refLine, $match);
if (!isset($match[3])) {
return null;
}

return $match[3];
}
}
6 changes: 5 additions & 1 deletion lib/Jejik/MT940/Parser/Commerzbank.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public function accept(string $text): bool
$allowedUniqueIdentifiers = [
':20:012CIXCIA7V1OGWA',
':20:0157VSNLKBG9WGWA',
':20:B2NG0OPCF3PTM87C',
':20:B2NG0MGUR8GUXUW8'
];

// unique identifier check
Expand All @@ -49,7 +51,9 @@ public function getAllowedBLZ(): array
return [
'70040041',
'66280053',
'28540034'
'28540034',
'50040000',
'16040000'
];
}
}
Loading

0 comments on commit 62669c8

Please sign in to comment.