forked from bunqCommunity/bunqJSClient
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.js
More file actions
49 lines (39 loc) · 1.65 KB
/
basic.js
File metadata and controls
49 lines (39 loc) · 1.65 KB
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
require("dotenv").config();
const setup = require("./common/setup");
setup()
.then(async BunqClient => {
const getMonetaryAccounts = async userid => {
return BunqClient.api.monetaryAccount.list(userid);
};
const getPayments = async (userid, monetaryaccountid) => {
return BunqClient.api.payment.list(userid, monetaryaccountid);
};
// get user info connected to this account
const users = await BunqClient.getUsers(true);
// get the direct user object
const userInfo = users[Object.keys(users)[0]];
console.log("\nUsers: ", Object.keys(users).length);
// get accounts list
const accounts = await getMonetaryAccounts(userInfo.id);
console.log("\nAccounts: ", accounts.length);
// filter on the status to get a list of the active accounts
const activeAccounts = accounts.filter(account => {
// get the account type for this account
const accountType = Object.keys(account)[0];
return account[accountType].status === "ACTIVE";
});
if (activeAccounts.length > 0) {
const accountType = Object.keys(activeAccounts[0])[0];
// get all payments for the first monetary account
const payments = await getPayments(userInfo.id, activeAccounts[0][accountType].id);
// log payments to console
console.log("\nPayments: ", payments.length, "\n");
}
})
.catch(error => {
console.log(error);
if (error.response) {
console.log(error.response.data);
}
})
.finally(() => process.exit());