All files / src/utils index.js

100% Statements 4/4
100% Branches 1/1
100% Functions 1/1
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                        6x             6x   6x                         6x        
import moment from 'moment'
 
/**
 * Cabeceras para las peticiones nequi
 * @param config
 * @param ServiceOperation
 * @param RestEndpoint
 * @param ServiceName
 * @returns {{headers: {Authorization: *, Accept: string, 'x-api-key': *, 'Content-Type': string}, endpoint: string, RequestHeader: {Destination: {ServiceRegion: string, ServiceName: string, ServiceVersion: string, ServiceOperation}, RequestDate: *, Channel: string, ClientID: string, MessageID: *}}}
 */
export function nequiHeaders (config, ServiceOperation, RestEndpoint, ServiceName = 'PaymentsService') {
  
  const headers = {
    'Content-Type': 'application/json',
    Accept: 'application/json',
    Authorization: config.token,
    'x-api-key': config.apiKey
  }
  
  const endpoint = `${ config.apiBasePath }${ RestEndpoint }`
  
  const RequestHeader = {
    Channel: 'PQR03-C001',
    RequestDate: moment(new Date()).format('YYYY-MM-DDTHH:mm:ss.SSSZ'),
    MessageID: config.messageID,
    ClientID: config.clientId,
    Destination: {
      ServiceName,
      ServiceOperation,
      ServiceRegion: 'C001',
      ServiceVersion: '1.2.0'
    }
  }
  
  return {
    headers, endpoint, RequestHeader
  }
}