update
This commit is contained in:
51
examples/quickstart.ts
Normal file
51
examples/quickstart.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { BunqAccount, BunqPayment } from '@apiclient.xyz/bunq';
|
||||
|
||||
async function main() {
|
||||
// Initialize bunq client
|
||||
const bunq = new BunqAccount({
|
||||
apiKey: 'your-api-key',
|
||||
deviceName: 'My App',
|
||||
environment: 'PRODUCTION' // or 'SANDBOX'
|
||||
});
|
||||
|
||||
try {
|
||||
// Initialize the client (handles installation, device registration, session)
|
||||
await bunq.init();
|
||||
console.log('Connected to bunq!');
|
||||
|
||||
// Get all monetary accounts
|
||||
const accounts = await bunq.getAccounts();
|
||||
console.log(`Found ${accounts.length} accounts:`);
|
||||
|
||||
for (const account of accounts) {
|
||||
console.log(`- ${account.description}: ${account.balance.currency} ${account.balance.value}`);
|
||||
}
|
||||
|
||||
// Get transactions for the first account
|
||||
const firstAccount = accounts[0];
|
||||
const transactions = await firstAccount.getTransactions();
|
||||
console.log(`\nRecent transactions for ${firstAccount.description}:`);
|
||||
|
||||
for (const transaction of transactions.slice(0, 5)) {
|
||||
console.log(`- ${transaction.amount.value} ${transaction.amount.currency}: ${transaction.description}`);
|
||||
}
|
||||
|
||||
// Create a payment (example)
|
||||
const payment = await BunqPayment.builder(bunq, firstAccount)
|
||||
.amount('10.00', 'EUR')
|
||||
.toIban('NL91ABNA0417164300', 'John Doe')
|
||||
.description('Payment for coffee')
|
||||
.create();
|
||||
|
||||
console.log(`\nPayment created successfully!`);
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error:', error.message);
|
||||
} finally {
|
||||
// Always clean up when done
|
||||
await bunq.stop();
|
||||
}
|
||||
}
|
||||
|
||||
// Run the example
|
||||
main().catch(console.error);
|
39
examples/sandbox.ts
Normal file
39
examples/sandbox.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { BunqAccount } from '@apiclient.xyz/bunq';
|
||||
|
||||
async function sandboxExample() {
|
||||
// Step 1: Create a sandbox user and get API key
|
||||
console.log('Creating sandbox user...');
|
||||
|
||||
const tempBunq = new BunqAccount({
|
||||
apiKey: '', // Empty for sandbox user creation
|
||||
deviceName: 'Sandbox Test',
|
||||
environment: 'SANDBOX'
|
||||
});
|
||||
|
||||
const sandboxApiKey = await tempBunq.createSandboxUser();
|
||||
console.log('Sandbox API key:', sandboxApiKey);
|
||||
|
||||
// Step 2: Initialize with the generated API key
|
||||
const bunq = new BunqAccount({
|
||||
apiKey: sandboxApiKey,
|
||||
deviceName: 'Sandbox Test',
|
||||
environment: 'SANDBOX'
|
||||
});
|
||||
|
||||
await bunq.init();
|
||||
console.log('Connected to sandbox!');
|
||||
|
||||
// Step 3: Use the API as normal
|
||||
const accounts = await bunq.getAccounts();
|
||||
console.log(`Found ${accounts.length} sandbox accounts`);
|
||||
|
||||
for (const account of accounts) {
|
||||
console.log(`- ${account.description}: ${account.balance.currency} ${account.balance.value}`);
|
||||
}
|
||||
|
||||
// Clean up
|
||||
await bunq.stop();
|
||||
}
|
||||
|
||||
// Run the sandbox example
|
||||
sandboxExample().catch(console.error);
|
Reference in New Issue
Block a user