1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kingsquare\Parser\Banking\Mt940\Engine; |
4
|
|
|
|
5
|
|
|
use Kingsquare\Banking\Transaction\Type; |
6
|
|
|
use Kingsquare\Parser\Banking\Mt940\Engine; |
7
|
|
|
|
8
|
|
|
class Wise extends Engine |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* |
12
|
|
|
* {@inheritdoc} |
13
|
|
|
* @see \Kingsquare\Parser\Banking\Mt940\Engine::parseStatementBank() |
14
|
|
|
*/ |
15
|
|
|
protected function parseStatementBank() |
16
|
|
|
{ |
17
|
|
|
return 'WISE'; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* uses field 25 to gather accoutnumber. |
22
|
|
|
* |
23
|
|
|
* @return string accountnumber |
24
|
|
|
*/ |
25
|
|
|
protected function parseStatementAccount() |
26
|
|
|
{ |
27
|
|
|
$results = []; |
28
|
|
|
if (preg_match('/:25:([\d\.]+)*/', $this->getCurrentStatementData(), $results) |
29
|
|
|
&& !empty($results[1]) |
30
|
|
|
) { |
31
|
|
|
return $this->sanitizeAccount($results[1]); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
// SEPA / IBAN |
35
|
|
|
if (preg_match('/:25:([A-Z0-9]{8}[\d\.]+)*/', $this->getCurrentStatementData(), $results) |
36
|
|
|
&& !empty($results[1]) |
37
|
|
|
) { |
38
|
|
|
return $this->sanitizeAccount($results[1]); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return 'WISE'; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* uses the 61 field to determine amount/value of the transaction. |
47
|
|
|
* |
48
|
|
|
* @return float |
49
|
|
|
*/ |
50
|
|
|
protected function parseTransactionPrice() |
51
|
|
|
{ |
52
|
|
|
$results = []; |
53
|
|
|
if (preg_match('/^:61:.*?[CD]([\d,\.]+)F/i', $this->getCurrentTransactionData(), $results) |
54
|
|
|
&& !empty($results[1]) |
55
|
|
|
) { |
56
|
|
|
return $this->sanitizePrice($results[1]); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return 0; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* uses the 61 field to get the bank specific transaction code. |
64
|
|
|
* |
65
|
|
|
* @return string |
66
|
|
|
*/ |
67
|
|
|
protected function parseTransactionCode() |
68
|
|
|
{ |
69
|
|
|
$results = []; |
70
|
|
|
if (preg_match('/^:61:.*?F(.{3}).*/', $this->getCurrentTransactionData(), $results) |
71
|
|
|
&& !empty($results[1]) |
72
|
|
|
) { |
73
|
|
|
return trim($results[1]); |
74
|
|
|
} |
75
|
|
|
return ''; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @TODO WIP get this into the transaction somehow.. (possibly as a decorator over the transactions?) |
80
|
|
|
* @return int |
81
|
|
|
*/ |
82
|
|
|
protected function parseTransactionType() |
83
|
|
|
{ |
84
|
|
|
static $map = [ |
85
|
|
|
'CHG' => Type::BANK_COSTS, |
86
|
|
|
'MSC' => Type::BANK_INTEREST, |
87
|
|
|
'TRF' => Type::TRANSFER, |
88
|
|
|
'FEX' => Type::UNKNOWN, |
89
|
|
|
]; |
90
|
|
|
|
91
|
|
|
$code = $this->parseTransactionCode(); |
92
|
|
|
if (array_key_exists($code, $map)) { |
93
|
|
|
return $map[$code]; |
94
|
|
|
} |
95
|
|
|
throw new \RuntimeException("Don't know code $code for this bank"); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* |
100
|
|
|
* {@inheritdoc} |
101
|
|
|
* @see \Kingsquare\Parser\Banking\Mt940\Engine::isApplicable() |
102
|
|
|
*/ |
103
|
|
|
public static function isApplicable($string) |
104
|
|
|
{ |
105
|
|
|
$firstline = strtok($string, "\r\n\t"); |
106
|
|
|
|
107
|
|
|
return strpos($firstline, 'F01TRWIGB2LAXXX0000000000') !== false; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|