Skip to content

Instantly share code, notes, and snippets.

@basst85
Last active June 19, 2018 20:27
Show Gist options
  • Save basst85/65cb49f4717ecd9d2e03a1073972a48f to your computer and use it in GitHub Desktop.
Save basst85/65cb49f4717ecd9d2e03a1073972a48f to your computer and use it in GitHub Desktop.
Use BunqJSClient with NodeJS
const BunqJSClient = require('@bunq-community/bunq-js-client').default;
const JSONStore = require('json-store');
const LocalStorage = JSONStore(__dirname+'\\storage.json');
BunqClient = new BunqJSClient(LocalStorage);
const ENCRYPTION_KEY = "3c7a4d431a846ed33a3bb1b1fa9b5c26";
const API_KEY = "sandbox_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
const DEVICE_NAME = "NodeTest";
const ENVIRONMENT = "SANDBOX"; // OR you can use PRODUCTION
const PERMITTED_IPS = []; // empty array if you're not sure
async function setup() {
// run the bunq application with our API key
await BunqClient.run(API_KEY, PERMITTED_IPS, ENVIRONMENT, ENCRYPTION_KEY)
.catch(exception => {
throw exception;
});
// install a new keypair
await BunqClient.install()
.catch(exception => {
throw exception;
});
// register this device
await BunqClient.registerDevice(DEVICE_NAME)
.catch(error => {
throw error.response.data;
});
// register a new session
await BunqClient.registerSession()
.catch(error => {
throw error.response.data;
});
}
async function getUsers() {
// get payments
await BunqClient.getUsers(true).then(users => {
return users;
})
.catch(error => {
throw error;
});
}
setup().then( setup => {
getUsers().then(response => {
console.log(response.response.data.Response)
}, error => {
console.log(error.response.data.Response)
});
}, error => {
console.log(error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment