forked from suhz/node-billplz
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·84 lines (69 loc) · 2.29 KB
/
index.js
File metadata and controls
executable file
·84 lines (69 loc) · 2.29 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
'use strict';
const Wreck = require('wreck')
let wreck
module.exports = class Billplz {
constructor(options) {
this._apiKey = null
this._apiEndpoint = 'https://www.billplz.com/api/v3/'
this._sandboxApiEndpoint = 'https://billplz-staging.herokuapp.com/api/v3/'
this._isSandbox = false
if (typeof options === 'object') {
this._apiKey = options.key || this._apiKey
this._apiEndpoint = options.endpoint || this._apiEndpoint
this._sandboxApiEndpoint = options.sandboxEndpoint || this._sandboxApiEndpoint
this._isSandbox = options.sandbox || this._isSandbox
}
else {
this._apiKey = options
}
if (this._isSandbox) {
this._apiEndpoint = this._sandboxApiEndpoint
}
wreck = Wreck.defaults({
headers: { 'Authorization': 'Basic ' + new Buffer(this._apiKey).toString('base64') }
});
}
request(method, params, callback) {
wreck.post(this._apiEndpoint + method, {
payload: params
}, (err, res, payload) => {
callback(err, JSON.parse(payload.toString()))
});
}
//create collection
create_collection(params, callback) {
return this.request('collections', params, callback)
}
//create open collection
create_collectionOpen(params, callback) {
return this.request('open_collections', params, callback)
}
//create bill
create_bill(params, callback) {
return this.request('bills', params, callback)
}
//get bill
get_bill(billId, callback) {
wreck.get(this._apiEndpoint + 'bills/' + billId, (err, res, payload) => {
callback(err, JSON.parse(payload.toString()))
});
}
//delete bill
delete_bill(billId, callback) {
wreck.delete(this._apiEndpoint + 'bills/' + billId, (err, res, payload) => {
callback(err, JSON.parse(payload.toString()))
});
}
//change collection status
change_collection_status(collectionId, status, callback) {
wreck.post(this._apiEndpoint + 'collections/' + collectionId + '/' + status, (err, res, payload) => {
callback(err, JSON.parse(payload.toString()))
});
}
//registration check
registration_check(bankAccountNumber, callback) {
wreck.get(this._apiEndpoint + 'check/bank_account_number/' + bankAccountNumber, (err, res, payload) => {
callback(err, JSON.parse(payload.toString()))
})
}
}