-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApi.js
157 lines (142 loc) · 4.48 KB
/
Api.js
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import qs from 'qs';
import promisify from 'es6-promisify';
const parseString = promisify(require('xml2js').parseString);
const USERNAME = 'landonalder';
const PASSWORD = '';
const fetchGreatLakesId = async () => {
const loginResponse = await fetch(
'https://www.mygreatlakes.org/borrower/m/authentication/applogin',
{
method: 'POST',
headers: {
'Content-Type': 'application/json;charset=UTF-8',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36',
cookie: [
'TLTSID=2fe36009.5562f9953d6b4',
'JSESSIONID_oc_infoserv=0001FHSI28twJxuGfbYOCdwAnL3:19ia5a0s6',
'GLDCID=.mad',
],
},
body: JSON.stringify({
userId: USERNAME,
password: PASSWORD,
pin: '',
deviceId: '86FB6D13-5788-42BC-B360-DA168130757E|IPHONE',
}),
},
);
if (loginResponse.status === 200) {
const parsedResponse = await loginResponse.json();
return parsedResponse.greatLakesId;
}
return fetchGreatLakesId();
};
const updateGreatLakesRegistration = greatLakesId => (
fetch(
'https://www.mygreatlakes.org/borrower/m/notification/registrationUpdate',
{
method: 'POST',
headers: {
'Content-Type': 'application/json;charset=UTF-8',
},
body: JSON.stringify({
id: greatLakesId,
notificationTypes: ['PPMTREM', 'PPMTPOS'],
registrationType: 'REGISTER',
device: {
type: 'iOS',
appVersionNr: '22.0',
id: 'be48a348e72fea62e4112080e08a84a30817e8608d47b26dcc7a54b5df1dbdd1',
uuid: '86FB6D13-5788-42BC-B360-DA168130757E',
},
}),
},
)
);
const fetchGreatLakesBalance = async () => {
const balanceResponse = await fetch(
'https://www.mygreatlakes.org/borrower/m/accountData',
{
method: 'POST',
headers: {
'Content-Type': 'application/json;charset=UTF-8',
},
},
);
const parsedResponse = await balanceResponse.json();
return parsedResponse.summaries[0].totalBalance;
};
export const getGreatLakesBalance = async () => {
const greatLakesId = await fetchGreatLakesId();
await updateGreatLakesRegistration(greatLakesId);
return parseFloat(await fetchGreatLakesBalance());
};
const fetchMohelaSessionToken = async () => {
const sessionTokenResponse = await fetch(
'https://www.mohela.com/MobileWebServices/MobLoginService.asmx/CheckLoginAndDevice2',
{
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: qs.stringify({
LoginId: USERNAME,
Source: 'ios',
DeviceId: '5B3FB647-9D14-422E-8CA4-2189344BCEEF',
DevicePrint: '5B3FB647-9D14-422E-8CA4-2189344BCEEF',
}),
},
);
const sessionTokenRawXML = await sessionTokenResponse.text();
const sessionTokenJSON = await parseString(sessionTokenRawXML);
return sessionTokenJSON.LoginServiceResponse.SessionToken[0];
};
const loginToMohela = sessionToken => (
fetch(
'https://www.mohela.com/MobileWebServices/MobLoginService.asmx/CheckPassword2',
{
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: qs.stringify({
LoginId: USERNAME,
Source: 'ios',
DeviceId: '5B3FB647-9D14-422E-8CA4-2189344BCEEF',
DevicePrint: '5B3FB647-9D14-422E-8CA4-2189344BCEEF',
SessionToken: sessionToken,
AccountType: 'B',
PersonnelKey: -1,
Success: true,
InstalledApp: true,
MoreThanOneLoan: null,
CanPayOnline: null,
CanPayLineItem: null,
password: PASSWORD,
}),
},
)
);
const fetchMohelaBalance = async (sessionToken) => {
const balanceResponse = await fetch(
'https://www.mohela.com/MobileWebServices/MobAccountHomeService.asmx/GetAccountHomeDetails',
{
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: qs.stringify({
PersonnelKey: '6167931',
SessionToken: sessionToken,
}),
},
);
const balanceRawXML = await balanceResponse.text();
const balanceJSON = await parseString(balanceRawXML);
return balanceJSON.AccountHomeServiceResponse.TotalBalance[0];
};
export const getMohelaBalance = async () => {
const sessionToken = await fetchMohelaSessionToken();
await loginToMohela(sessionToken);
return parseFloat(await fetchMohelaBalance(sessionToken));
}