Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

Commit

Permalink
Correção getContentType
Browse files Browse the repository at this point in the history
Foi implementado a função da forma correta
  • Loading branch information
Cristovam Martins authored and lealhugui committed Feb 22, 2022
1 parent 8939f7c commit 64f095c
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 17 deletions.
1 change: 1 addition & 0 deletions lib/factory/webservices/functions.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare function getContentType(uf: string): string;
8 changes: 4 additions & 4 deletions lib/factory/webservices/functions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getContentType = void 0;
function getContentType(uf) {
switch (uf) {
case 'GO':
Expand Down Expand Up @@ -33,7 +36,4 @@ function getContentType(uf) {
throw new Error('Content Type não encontrado!');
}
}

module.exports = {
getContentType
};
exports.getContentType = getContentType;
5 changes: 2 additions & 3 deletions lib/factory/webservices/sefazNfce.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports.SefazNFCe = void 0;
const nfe_1 = require("../interface/nfe");
const { getContentType } = require("./functions.js");
const functions_1 = require("./functions");
const Utils = require("../utils/utils");
const servicos = require('../../../servicos.json');
const autorizadores = require('../../../autorizadores.json');
Expand Down Expand Up @@ -49,7 +49,6 @@ class SefazNFCe {
throw new Error('Autorizador não encontrado!');
}
}

static getInfoQRCodeByUF(uf, amb) {
if (amb == '1') {
switch (uf) {
Expand Down Expand Up @@ -180,7 +179,7 @@ class SefazNFCe {
soap.urlQRCode = infoQRCode.urlQRCode;
soap.urlChave = infoQRCode.urlChave;
}
soap.contentType = getContentType(uf);
soap.contentType = functions_1.getContentType(uf);
soap.method = servicos[servico].method;
soap.action = servicos[servico].action;
return soap;
Expand Down
5 changes: 2 additions & 3 deletions lib/factory/webservices/sefazNfe.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SefazNFe = void 0;
const { getContentType } = require("./functions.js");
const functions_1 = require("./functions");
const Utils = require("../utils/utils");
const servicos = require('../../../servicos.json');
const autorizadores = require('../../../autorizadoresNFe.json');
Expand Down Expand Up @@ -87,15 +87,14 @@ class SefazNFe {
throw new Error('Autorizador não encontrado!');
}
}

static getSoapInfo(uf, amb, servico, isContingencia) {
let soap = {};
let autorizador = isContingencia ? this.getAutorizadorContingenciaByUF(uf) : this.getAutorizadorByUF(uf);
if (amb == '1')
soap.url = Utils.validaUrlWsdl(autorizador.servicos[servico].url_producao);
else
soap.url = Utils.validaUrlWsdl(autorizador.servicos[servico].url_homologacao);
soap.contentType = getContentType(uf);
soap.contentType = functions_1.getContentType(uf);
soap.method = servicos[servico].method;
soap.action = servicos[servico].action;
return soap;
Expand Down
8 changes: 3 additions & 5 deletions lib/factory/webservices/webserviceHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ class WebServiceHelper {
}
static buildSoapEnvelope(xml, soapMethod) {
let soapEnvelopeObj = {
'$': {
'xmlns:soap': 'http://www.w3.org/2003/05/soap-envelope',
'$': { 'xmlns:soap': 'http://www.w3.org/2003/05/soap-envelope',
'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'xmlns:xsd': 'http://www.w3.org/2001/XMLSchema'
},
'xmlns:xsd': 'http://www.w3.org/2001/XMLSchema' },
'soap:Body': {
'nfeDadosMsg': {
'$': {
Expand Down Expand Up @@ -111,7 +109,7 @@ class WebServiceHelper {
let retorno = xmlHelper_1.XmlHelper.deserializeXml(result.xml_recebido, { explicitArray: false });
if (retorno) {
//result.data = retorno;
Object(retorno)['soap:Envelope'] != undefined ? result.data = Object(retorno)['soap:Envelope']['soap:Body']['nfeResultMsg'] : result.data = Object(retorno)['env:Envelope']['env:Body']['nfeResultMsg'];
result.data = Object(retorno)['soap:Envelope'] != undefined ? result.data = Object(retorno)['soap:Envelope']['soap:Body']['nfeResultMsg'] : result.data = Object(retorno)['env:Envelope']['env:Body']['nfeResultMsg'];
//console.log(result.data)
}
}
Expand Down
36 changes: 36 additions & 0 deletions src/factory/webservices/functions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
export function getContentType(uf: string) : string {
switch (uf) {
case 'GO':
return "application/soap+xml";
case 'AC':
case 'AL':
case 'AP':
case 'DF':
case 'ES':
case 'MG':
case 'PB':
case 'RJ':
case 'RN':
case 'RO':
case 'RR':
case 'RS':
case 'SC':
case 'SE':
case 'SP':
case 'TO':
case 'AM':
case 'BA':
case 'CE':
case 'MA':
case 'MS':
case 'MT':
case 'PA':
case 'PE':
case 'PI':
case 'PR':
return "text/xml;charset=utf-8";
default:
throw new Error('Content Type não encontrado!');
}
}

2 changes: 2 additions & 0 deletions src/factory/webservices/sefazNfce.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ServicosSefaz } from '../interface/nfe';
import { getContentType } from './functions';
import * as Utils from '../utils/utils';
const servicos = require('../../../servicos.json')
const autorizadores = require('../../../autorizadores.json')
Expand Down Expand Up @@ -182,6 +183,7 @@ export abstract class SefazNFCe {
soap.urlChave = infoQRCode.urlChave;
}

soap.contentType = getContentType(uf);
soap.method = servicos[servico].method;
soap.action = servicos[servico].action;

Expand Down
2 changes: 2 additions & 0 deletions src/factory/webservices/sefazNfe.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ServicosSefaz } from '../interface/nfe';
import { getContentType } from './functions';
import * as Utils from '../utils/utils';
const servicos = require('../../../servicos.json')
const autorizadores = require('../../../autorizadoresNFe.json')
Expand Down Expand Up @@ -97,6 +98,7 @@ export abstract class SefazNFe {
else
soap.url = Utils.validaUrlWsdl(autorizador.servicos[servico].url_homologacao);

soap.contentType = getContentType(uf);
soap.method = servicos[servico].method;
soap.action = servicos[servico].action;

Expand Down
4 changes: 2 additions & 2 deletions src/factory/webservices/webserviceHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export abstract class WebServiceHelper {
url: soapParams.url,
agentOptions: this.buildCertAgentOpt(cert),
headers: {
"Content-Type": "text/xml;charset=utf-8",
"Content-Type": soapParams.contentType,
"SOAPAction": soapParams.action
},
body: this.buildSoapEnvelope(xml, soapParams.method),
Expand Down Expand Up @@ -138,7 +138,7 @@ export abstract class WebServiceHelper {
let retorno = XmlHelper.deserializeXml(result.xml_recebido, {explicitArray: false});
if (retorno) {
//result.data = retorno;
result.data = Object(retorno)['soap:Envelope']['soap:Body']['nfeResultMsg'];
result.data = Object(retorno)['soap:Envelope'] != undefined ? result.data = Object(retorno)['soap:Envelope']['soap:Body']['nfeResultMsg'] : result.data = Object(retorno)['env:Envelope']['env:Body']['nfeResultMsg'];
//console.log(result.data)
}
}
Expand Down

0 comments on commit 64f095c

Please sign in to comment.