forked from bunqCommunity/bunqJSClient
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencrypted_endpoint.js
More file actions
45 lines (36 loc) · 1.44 KB
/
encrypted_endpoint.js
File metadata and controls
45 lines (36 loc) · 1.44 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
require("dotenv").config();
const setup = require("./common/setup");
setup()
.then(async BunqClient => {
const requestCvcCode = (userid, cardId, type = "GENERATED") => {
return BunqClient.api.cardCvc2.post(userid, cardId, type);
};
// get user info connected to this account
const users = await BunqClient.getUsers(true);
console.log("\nUsers: ", Object.keys(users).length, "\n");
// get the direct user object
const userInfo = users[Object.keys(users)[0]];
const cards = await BunqClient.api.card.list(userInfo.id);
console.log("\nCards: ", cards.length, "\n");
const masterCardTypes = ["MASTERCARD", "MASTERCARD_VIRTUAL"];
const masterCard = cards.find(card => {
const cardKey = Object.keys(card)[0];
const cardInfo = card[cardKey];
return masterCardTypes.includes(cardInfo.type);
});
if (!masterCard) {
console.log("No card found with type of:", masterCardTypes);
return;
}
const cardKey = Object.keys(masterCard)[0];
const masterCardInfo = masterCard[cardKey];
const cvcResult = await requestCvcCode(userInfo.id, masterCardInfo.id);
console.log(cvcResult);
})
.catch(error => {
console.log(error);
if (error.response) {
console.log(error.response.data);
}
})
.finally(() => process.exit());