-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathinvoices.js
38 lines (29 loc) · 1.14 KB
/
invoices.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
import * as readline from "node:readline/promises";
import { stdin as input, stdout as output } from "node:process";
import { auth, Client } from "../dist/index.module.js";
const rl = readline.createInterface({ input, output });
const authClient = new auth.OAuth2User({
client_id: process.env.CLIENT_ID,
client_secret: process.env.CLIENT_SECRET,
callback: "http://localhost:8080",
scopes: ["invoices:read", "account:read", "balance:read"],
token: {
access_token: undefined,
refresh_token: undefined,
expires_at: undefined,
}, // initialize with existing token
});
console.log(`Open the following URL and authenticate the app:`);
console.log(await authClient.generateAuthURL());
console.log("----\n");
const code = await rl.question("Code: (localhost:8080?code=[THIS CODE]: ");
rl.close();
await authClient.requestAccessToken(code);
console.log(authClient.token);
const client = new Client(authClient);
const response = await client.incomingInvoices();
console.log(JSON.stringify(response, null, 2));
if (response[0]) {
const invoice = await client.getInvoice(response[0].r_hash_str);
console.log(JSON.stringify(invoice, null, 2));
}