-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIBBL.php
75 lines (63 loc) · 2.39 KB
/
IBBL.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
<?php
class IBBL
{
public static function parse($text)
{
if (stripos($text, 'Purchased') !== false) {
return self::purchase($text);
} elseif (stripos($text, 'Withdrawn') !== false) {
return self::withdraw($text);
} elseif (stripos($text, 'deposited') !== false) {
return self::deposit($text);
} elseif (stripos($text, 'transferred') !== false) {
return self::transfer($text);
} else {
return [null, 0, null];
}
}
private static function purchase($text)
{
$info = explode(PHP_EOL, strtoupper(trim($text)));
$amount = floatval(trim(str_replace(['PURCHASED', 'BDT'], '', $info[1])));
$merchant = trim(str_replace(['FROM', ', BD'], '', $info[2]));
return [Transaction::TYPE_PURCHASE, $amount, $merchant];
}
private static function withdraw($text)
{
$info = explode(PHP_EOL, strtoupper(trim($text)));
if (stripos($text, 'e-commerce') !== false) {
$amount = self::extractAmount($info[0]);
$merchant = 'E-COMMERCE';
} elseif (stripos($text, 'iTransfer') !== false) {
$amount = self::extractAmount($info[0]);
$merchant = 'i-TRANSFER';
} elseif (stripos($text, 'NPSB') !== false) {
$amount = self::extractAmount($info[0]);
$merchant = 'NPSB';
} else {
$amount = floatval(trim(str_replace(['WITHDRAWN', 'BDT'], '', $info[1])));
$merchant = trim(str_replace(['FROM', ':'], '', $info[2]));
}
return [Transaction::TYPE_WITHDRAW, $amount, $merchant];
}
private static function deposit($text)
{
$info = explode(PHP_EOL, strtoupper(trim($text)));
$amount = self::extractAmount($info[1]);
$merchant = stripos($info[1], 'Cheque') !== false ? 'CHEQUE' : 'CASH';
return [Transaction::TYPE_DEPOSIT, $amount, $merchant];
}
private static function transfer($text)
{
$info = explode(PHP_EOL, strtoupper(trim($text)));
$amount = self::extractAmount($info[0]);
$merchant = 'EXTERNAL';
return [Transaction::TYPE_TRANSFER, $amount, $merchant];
}
private static function extractAmount($text)
{
$val = trim(substr($text, 2, strpos($text, 'has') - 1));
$val = str_replace(',', '', $val);
return floatval($val);
}
}