-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
43 lines (36 loc) · 1.19 KB
/
index.js
File metadata and controls
43 lines (36 loc) · 1.19 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
const axios = require('axios')
const FormData = require("form-data")
module.exports = class DirectDebitClient {
constructor(production, userCode, password) {
let subdomain = production ? "dos" : "dos-dr"
this.baseURL = `https://${subdomain}.directdebit.co.za:31143/v2/`
this.auth = {
username: userCode,
password: password
}
}
async WhoAmI() {
return new Promise((resolve, reject) => {
let url = this.baseURL + 'whoami'
axios.get(url, {auth: this.auth})
.then(r => resolve(r.data))
.catch(r => reject(r))
});
}
async UploadEFTFile(content, fileName) {
fileName || (fileName = "file_data.csv")
let form = new FormData()
form.append("file_data", content, {
filename: fileName
})
return new Promise((resolve, reject) => {
let conf = {
headers: form.getHeaders(),
auth: this.auth
}
axios.post(this.baseURL + "batch/eft/csv", form.getBuffer(), conf)
.then(r => resolve(r.data))
.catch(r => reject(r))
});
}
}