forked from fruitl00p/php-mt940
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIng.php
139 lines (123 loc) · 3.86 KB
/
Ing.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
namespace Kingsquare\Parser\Banking\Mt940\Engine;
use Kingsquare\Parser\Banking\Mt940\Engine;
/**
* @author Kingsquare (source@kingsquare.nl)
* @license http://opensource.org/licenses/MIT MIT
*/
class Ing extends Engine
{
/**
* returns the name of the bank.
*
* @return string
*/
protected function parseStatementBank()
{
return 'ING';
}
/**
* Overloaded: Added simple IBAN transaction handling.
*
* {@inheritdoc}
*/
protected function parseTransactionAccount()
{
$account = parent::parseTransactionAccount();
if ($account !== '') {
return $account;
}
// IBAN
$transactionData = str_replace('Europese Incasso, doorlopend ', '', $this->getCurrentTransactionData());
$transactionData = preg_replace('![\r\n]+!', '', $transactionData);
if (preg_match('#/CNTP/(.*?)/#', $transactionData, $results)) {
$account = trim($results[1]);
if (!empty($account)) {
return $this->sanitizeAccount($account);
}
}
if (preg_match('#:86:([A-Z]{2}[\d]{2}[A-Z]{4}[\d]+?) [A-Z]{6}[A-Z0-9]{0,4} #', $transactionData, $results)) {
$account = trim($results[1]);
if (!empty($account)) {
return $this->sanitizeAccount($account);
}
}
return '';
}
/**
* Overloaded: Added simple IBAN transaction handling.
*
* {@inheritdoc}
*/
protected function parseTransactionAccountName()
{
$name = parent::parseTransactionAccountName();
if ($name !== '') {
return $name;
}
// IBAN
$transactionData = str_replace('Europese Incasso, doorlopend ', '', $this->getCurrentTransactionData());
$transactionData = preg_replace('![\r\n]+!', '', $transactionData);
if (preg_match('#/CNTP/[^/]*/[^/]*/(.*?)/#', $transactionData, $results)) {
$name = trim($results[1]);
if (!empty($name)) {
return $this->sanitizeAccountName($name);
}
}
if (preg_match('#:86:.*? [^ ]+ (.*)#', $transactionData, $results) !== 1) {
return '';
}
return $this->parseNameFromTransactionData($results[1]);
}
/**
* @param $transactionData
*
* @return string
*/
private function parseNameFromTransactionData($transactionData)
{
if (preg_match('#(.*) (Not-Provided|NOTPROVIDED)#', $transactionData, $results) === 1) {
$name = trim($results[1]);
if (!empty($name)) {
return $this->sanitizeAccountName($name);
}
}
if (preg_match('#\D+#', $transactionData, $results)) {
$name = trim($results[0]);
if (!empty($name)) {
return $this->sanitizeAccountName($name);
}
}
return '';
}
/**
* Overloaded: ING encapsulates the description with /REMI/ for SEPA.
*
* {@inheritdoc}
*/
protected function sanitizeDescription($string)
{
$description = parent::sanitizeDescription($string);
if (strpos($description, '/REMI/USTD//') !== false
&& preg_match('#/REMI/USTD//(.*?)/#s', $description, $results) && !empty($results[1])
) {
return $results[1];
}
if (strpos($description, '/REMI/STRD/CUR/') !== false
&& preg_match('#/REMI/STRD/CUR/(.*?)/#s', $description, $results) && !empty($results[1])
) {
return $results[1];
}
return $description;
}
/**
* Overloaded: Is applicable if first line has INGB.
*
* {@inheritdoc}
*/
public static function isApplicable($string)
{
$firstline = strtok($string, "\r\n\t");
return strpos($firstline, 'INGB') !== false;
}
}