-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathclientAPI.js
More file actions
77 lines (71 loc) · 2.1 KB
/
clientAPI.js
File metadata and controls
77 lines (71 loc) · 2.1 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
'user strict';
/**
* @module clientAPI
* @description Expone como funciones el consumo de los recursos del API de Nequi
* @author <jomgarci@bancolombia.com.co>
* @version 0.0.1
*/
const Q = require('q');
const awsSigner = require('./awsSigner.js');
module.exports = {
//Valida que un cliente NEQUI exista
validateClient:validateClient
};
const CHANNEL = "MF-001";
const API_RESOURCES = {
host: 'a7zgalw2j0.execute-api.us-east-1.amazonaws.com',
services : {
validateClient : '/qa/-services-clientservice-validateclient'
},
headers:{
'content-type' : 'application/json'
}
};
/**
* Encapsula el consumo del servicio de validacion de cliente del API y retorna la promesa con la respuesta del servicio
*/
function validateClient(phoneNumber, value){
return Q.Promise((resolve, reject) =>{
var body = getBodyValidateClient(phoneNumber, value);
awsSigner.makeSignedRequest(API_RESOURCES.host,
API_RESOURCES.services.validateClient, 'POST',
API_RESOURCES.headers, body,
(statusCode, result) => {
//Status HTTP
console.log(statusCode);
resolve(result);
}, (error) => {
reject(error);
});
});
}
/**
* Forma el cuerpo para consumir el servicio de validación de cliente del API
*/
function getBodyValidateClient(phoneNumber, value){
var messageId = new Date().getTime().toString();
return {
"RequestMessage": {
"RequestHeader": {
"Channel": CHANNEL,
"RequestDate": new Date().toJSON(),
"MessageID": messageId.substring(messageId.length-9),
"ClientID": phoneNumber.toString(),
"Destination": {
"ServiceName": "RechargeService",
"ServiceOperation": "validateClient",
"ServiceRegion": "C001",
"ServiceVersion": "1.0.0"
}
},
"RequestBody": {
"any": {
"validateClientRQ": {
"phoneNumber": phoneNumber.toString(),
"value": value.toString()
}
}
}
}
}
}