This repository was archived by the owner on Jan 15, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
103 lines (83 loc) · 1.93 KB
/
example.js
File metadata and controls
103 lines (83 loc) · 1.93 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* A balanced-client example
*
* Steps:
* Creates a customer
* Creates a bank account
* Associates bank account with customer
* Requests bank account verification
* Verifies account
* Confirms account `can_debit` is true
*
* Uses some super basic flow control, similar to async series.
* See the main function at end for this.
*/
var balanced = require('./index').config('59ef4c8ef64211e284cc026ba7cd33d0')
, assert = require('assert')
var customer
, account
, verification
function createCustomer(cb) {
balanced.post('/v1/customers', {
name: "Some Customer",
phone: "410-555-5555",
}, function(err, data) {
customer = data
cb(err, data)
})
}
function createAccount(cb) {
balanced.post('/v1/bank_accounts', {
routing_number: 121000358,
account_number: 9900000001,
name: "Balanced Client Example Account",
type: "checking"
}, function(err, data) {
account = data
cb(err, data)
})
}
function associateAccountWithCustomer(cb) {
balanced.put(customer.uri, {
bank_account_uri: account.uri
}, cb)
}
function requestVerification(cb) {
balanced.post(account.verifications_uri, function(err, data) {
verification = data
cb(err, data)
})
}
function verifyAccount(cb) {
balanced.put(verification.uri, {amount_1: 1, amount_2: 1}, cb)
}
function confirmCanDebit(cb) {
balanced.get(account.uri, function(err, a) {
if (err) return cb(err)
assert.ok(a.can_debit)
cb(null, a)
})
}
function main() {
var step = -1
var steps = [
createCustomer,
createAccount,
associateAccountWithCustomer,
requestVerification,
verifyAccount,
confirmCanDebit,
]
function next(err, data) {
step += 1
var fn = steps[step]
if (!fn) return console.log("\n\nDone!\n\n")
fn(function(err, data) {
if (err) throw err
console.log("\n\n\n =====", fn.name, "=====\n\n", data)
next()
})
}
next()
}
main()