Last active
June 19, 2018 20:27
-
-
Save basst85/65cb49f4717ecd9d2e03a1073972a48f to your computer and use it in GitHub Desktop.
Use BunqJSClient with NodeJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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