-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.js
70 lines (63 loc) · 1.85 KB
/
main.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
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
/**
* IBANAPI.com nodejs module
* @author IBANAPI.com
* @since 04/09/2021
*/
const axios = require("axios")
const FormData = require('form-data');
const config = {apiKey:''}
const apiBaseURL = "https://api.ibanapi.com/v1/";
//Set the config
exports.setConfig = (apiKey) =>{
config.apiKey = apiKey
}
//Validate the iban
exports.validateIBAN = (iban,callback) =>{
if(config.apiKey == ""){
return { 'result:': 400, 'message': 'Please set the API key first!' }
}
bodyFormData = _setIBANFormData(iban)
_sendPost(apiBaseURL+"validate",bodyFormData,callback)
}
//Basic IBAN Validation
exports.validateIBANBasic = (iban,callback) =>{
if(config.apiKey == ""){
return { 'result:': 400, 'message': 'Please set the API key first!' }
}
bodyFormData = _setIBANFormData(iban)
_sendPost(apiBaseURL+"validate-basic",bodyFormData,callback)
}
//Get Account Balance
exports.getBalance = (callback) =>{
if(config.apiKey == ""){
return { 'result:': 400, 'message': 'Please set the API key first!' }
}
bodyFormData = _setIBANFormData(null,true)
_sendPost(apiBaseURL+"balance",bodyFormData,callback)
}
function _setIBANFormData(iban,isBalance=false){
var bodyFormData = new FormData();
if(!isBalance){
bodyFormData.append('iban',iban);
}
bodyFormData.append('api_key',config.apiKey);
return bodyFormData;
}
function _sendPost(url,objData,callback){
axios({
method: 'post',
url: url,
data: objData,
headers: {
'Content-Type': `multipart/form-data; boundary=${objData._boundary}`,
},
}).then((res) => {
callback(res.data);
}).catch((error) => {
if (error.response){
callback (error.response.data);
}else{
callback ({ 'result:': 400, 'message': error.message });
}
});
}