@@ -29,8 +29,7 @@ public function __construct()
29
29
'timeout ' => 60 ,
30
30
'cookies ' => true ,
31
31
'headers ' => [
32
- 'User-Agent ' => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.1 Safari/537.36 "
33
- ]
32
+ 'User-Agent ' => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.1 Safari/537.36 " ]
34
33
));
35
34
36
35
$ this ->client ->setClient ($ this ->guzzleClient );
@@ -75,12 +74,15 @@ public function login($username, $password)
75
74
76
75
$ bal = $ balance ->count () ? $ balance ->text () : 0 ;
77
76
$ avl = $ available ->count () ? $ available ->text () : 0 ;
77
+ $ bsb = $ this ->processNumbersOnly ($ bsb ->count () ? $ bsb ->text () : '' );
78
+ $ accountNumber = $ this ->processNumbersOnly ($ accountNumber ->count () ? $ accountNumber ->text () : '' );
79
+ $ fullAccountNumber = $ bsb . $ accountNumber ;
78
80
79
- $ accountList [] = [
81
+ $ accountList [$ fullAccountNumber ] = [
80
82
'nickname ' => $ name ->text (),
81
83
'url ' => $ name ->attr ('href ' ),
82
- 'bsb ' => $ bsb-> count () ? $ bsb -> text () : '' ,
83
- 'accountNum ' => $ accountNumber-> count () ? $ accountNumber -> text () : '' ,
84
+ 'bsb ' => $ bsb ,
85
+ 'accountNum ' => $ accountNumber ,
84
86
'balance ' => $ this ->processCurrency ($ bal ),
85
87
'available ' => $ this ->processCurrency ($ avl )
86
88
];
@@ -95,8 +97,7 @@ public function login($username, $password)
95
97
96
98
public function getTransactions ($ account , $ from , $ to )
97
99
{
98
- $ link = sprintf ("%s%s " , self ::BASE_URL , $ account ['url ' ]);
99
- $ crawler = $ this ->client ->request ('GET ' , $ link );
100
+ $ crawler = $ this ->getAccountPage ($ account );
100
101
101
102
$ form = $ crawler ->filter ('#aspnetForm ' );
102
103
@@ -110,6 +111,9 @@ public function getTransactions($account, $from, $to)
110
111
$ field = $ this ->createField ('input ' , '__EVENTTARGET ' , 'ctl00$BodyPlaceHolder$lbSearch ' );
111
112
$ form ->set ($ field );
112
113
114
+ $ field = $ this ->createField ('input ' , '__EVENTARGUMENT ' , '' );
115
+ $ form ->set ($ field );
116
+
113
117
$ field = $ this ->createField ('input ' , 'ctl00$ctl00 ' , 'ctl00$BodyPlaceHolder$updatePanelSearch|ctl00$BodyPlaceHolder$lbSearch ' );
114
118
$ form ->set ($ field );
115
119
@@ -132,8 +136,44 @@ public function getTransactions($account, $from, $to)
132
136
$ form ->set ($ field );
133
137
134
138
$ crawler = $ this ->client ->submit ($ form );
135
- $ html = $ crawler ->html ();
136
139
140
+ return $ this ->filterTransactions ($ crawler );
141
+ }
142
+
143
+ public function setTimezone ($ timezone )
144
+ {
145
+ $ this ->timezone = $ timezone ;
146
+ }
147
+
148
+ private function processNumbersOnly ($ value )
149
+ {
150
+ return preg_replace ('$[^0-9]$ ' , '' , $ value );
151
+ }
152
+
153
+ private function processCurrency ($ amount )
154
+ {
155
+ $ value = preg_replace ('$[^0-9.]$ ' , '' , $ amount );
156
+
157
+ if (strstr ($ amount , 'DR ' )) {
158
+ $ value = -$ value ;
159
+ }
160
+
161
+ return $ value ;
162
+ }
163
+
164
+ private function createField ($ type , $ name , $ value )
165
+ {
166
+ $ domdocument = new \DOMDocument ;
167
+ $ ff = $ domdocument ->createElement ($ type );
168
+ $ ff ->setAttribute ('name ' , $ name );
169
+ $ ff ->setAttribute ('value ' , $ value );
170
+ $ formfield = new InputFormField ($ ff );
171
+
172
+ return $ formfield ;
173
+ }
174
+
175
+ public function filterTransactions ($ crawler )
176
+ {
137
177
$ pattern = '
138
178
/
139
179
\{ # { character
@@ -145,10 +185,10 @@ public function getTransactions($account, $from, $to)
145
185
\} # } character
146
186
/x
147
187
' ;
188
+ $ html = $ crawler ->html ();
148
189
149
- $ extracted = preg_match_all ($ pattern , $ html , $ matches );
190
+ preg_match_all ($ pattern , $ html , $ matches );
150
191
151
- $ transactions = [];
152
192
foreach ($ matches [0 ] as $ _temp ) {
153
193
if (strstr ($ _temp , '{"Transactions" ' )) {
154
194
$ transactions = json_decode ($ _temp );
@@ -171,35 +211,15 @@ public function getTransactions($account, $from, $to)
171
211
'receiptnumber ' => $ transaction ->ReceiptNumber ->Text ,
172
212
];
173
213
}
174
- }
175
-
176
- return $ transactionList ;
177
- }
178
-
179
- public function setTimezone ($ timezone )
180
- {
181
- $ this ->timezone = $ timezone ;
182
- }
183
-
184
- private function processCurrency ($ amount )
185
- {
186
- $ value = preg_replace ('$[^0-9.]$ ' , '' , $ amount );
187
214
188
- if (strstr ($ amount , 'DR ' )) {
189
- $ value = -$ value ;
190
215
}
191
216
192
- return $ value ;
217
+ return $ transactionList ;
193
218
}
194
219
195
- private function createField ( $ type , $ name , $ value )
220
+ private function getAccountPage ( $ account )
196
221
{
197
- $ domdocument = new \DOMDocument ;
198
- $ ff = $ domdocument ->createElement ($ type );
199
- $ ff ->setAttribute ('name ' , $ name );
200
- $ ff ->setAttribute ('value ' , $ value );
201
- $ formfield = new InputFormField ($ ff );
202
-
203
- return $ formfield ;
222
+ $ link = sprintf ("%s%s " , self ::BASE_URL , $ account ['url ' ]);
223
+ return $ this ->client ->request ('GET ' , $ link );
204
224
}
205
225
}
0 commit comments