Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integrations from chargecloud GmbH #53

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
operating-system: ['ubuntu-22.04']
php-versions: ['7.4', '8.0']
php-versions: ['7.4', '8.0', '8.1']

steps:
- uses: actions/checkout@v1
Expand Down
20 changes: 20 additions & 0 deletions LICENCE.chargecloud.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2023 Dominic Richter - chargecloud Gmbh (https://www.chargecloud.de)

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
"homepage": "https://www.jejik.com"
},
{
"name": "powercloud GmbH / Dominic Richter",
"email": "dominic.richter@power.cloud",
"homepage": "https://www.power.cloud"
"name": "Dominic Richter",
"homepage": "https://twitnic.de"
}
],
"require": {
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 @@ -422,7 +422,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 @@ -494,7 +494,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 @@ -736,4 +739,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;
}
}
48 changes: 48 additions & 0 deletions lib/Jejik/MT940/Parser/BayerischeLandesbank.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Jejik\MT940 library
*
* Copyright (c) 2023 Sennur Tas - chargecloud GmbH
* 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;

/**
* 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) 2023 Sennur Tas - chargecloud GmbH
* 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',
':20:01LGX08DLMWH5GWA',
];

Expand All @@ -52,7 +54,9 @@ public function getAllowedBLZ(): array
'70040041',
'66280053',
'28540034',
'25040066',
'50040000',
'16040000',
'25040066'
];
}
}
Loading