-
Notifications
You must be signed in to change notification settings - Fork 12
/
controller.js
42 lines (36 loc) · 941 Bytes
/
controller.js
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
/**
* controller.js
* Xendit Checkout Demo
* This file defines all the API call to Xendit API Gateway, for now is to create invoice
*/
'use strict';
const axios = require('axios');
class InvoiceController {
constructor() {
(this.url = process.env.API_GATEWAY_URL + '/v2/invoices'),
(this.headers = {
'Content-Type': 'application/json'
}),
(this.auth = {
username: process.env.API_KEY,
password: ''
});
this.timeout = 10000;
}
async create(data) {
const options = {
method: 'POST',
headers: this.headers,
timeout: this.timeout,
auth: this.auth,
url: this.url,
data
};
try {
return await axios(options);
} catch (e) {
throw e;
}
}
}
module.exports = InvoiceController;