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

Commit

Permalink
Implementação de suporte a proxy nas requisições.
Browse files Browse the repository at this point in the history
  • Loading branch information
lealhugui committed Jun 24, 2019
1 parent c1f91a8 commit 56cfbfa
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
15 changes: 11 additions & 4 deletions src/factory/processor/nfeProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { RetornoProcessamentoNF, Empresa, Endereco, NFCeDocumento, NFeDocumento,
InfoAdicional, DetalhesProduto, Imposto, Icms, Cofins, Pis, IcmsTot, IssqnTot, DetalhePagamento, DetalhePgtoCartao, RetornoContingenciaOffline, ResponsavelTecnico, ServicosSefaz
} from '../interface/nfe';

import { WebServiceHelper } from "../webservices/webserviceHelper";
import { WebServiceHelper, WebProxy } from "../webservices/webserviceHelper";
import * as schema from '../schema/index';
import { XmlHelper } from '../xmlHelper';
import * as Utils from '../utils/utils';
Expand Down Expand Up @@ -40,7 +40,10 @@ function jsonOneLevel(obj: any): string {
*/
export class NFeProcessor {

constructor(private empresa: Empresa, private responsavelTecnico?: ResponsavelTecnico) { }
constructor(
private empresa: Empresa,
private responsavelTecnico?: ResponsavelTecnico,
private webProxy?: WebProxy) { }

/**
* Metodo para realizar o processamento de documento(s) do tipo 55 ou 65 de forma sincrona
Expand Down Expand Up @@ -260,11 +263,15 @@ export class NFeProcessor {
}

private async consultarProc(xml:string, cert: any) {
return await WebServiceHelper.makeSoapRequest(xml, cert, soapRetAutorizacao);
return await WebServiceHelper.makeSoapRequest(
xml, cert, soapRetAutorizacao, this.webProxy
);
}

private async enviarNF(xml: string, cert: any) {
return await WebServiceHelper.makeSoapRequest(xml, cert, soapAutorizacao);
return await WebServiceHelper.makeSoapRequest(
xml, cert, soapAutorizacao, this.webProxy
);
}

private gerarXmlConsultaProc(ambiente: string, recibo: string){
Expand Down
10 changes: 7 additions & 3 deletions src/factory/processor/statusServicoProcessor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as schema from '../schema/index'
import { XmlHelper } from "../xmlHelper";
import { WebServiceHelper } from "../webservices/webserviceHelper";
import { WebServiceHelper, WebProxy } from "../webservices/webserviceHelper";
import {Empresa, ServicosSefaz} from "../interface/nfe";
import * as Utils from "../utils/utils";
import { SefazNFCe } from "../webservices/sefazNfce";
Expand All @@ -11,7 +11,11 @@ import { SefazNFe } from "../webservices/sefazNfe";
*/
export class StatusServicoProcessor {

constructor(private empresa: Empresa, private ambiente: string, private modelo: string) { }
constructor(
private empresa: Empresa,
private ambiente: string,
private modelo: string,
private webProxy?: WebProxy) { }

async processarDocumento() {
let xml = this.gerarXmlStatusServico('4.00', this.ambiente, this.empresa.endereco.cUf);
Expand All @@ -21,7 +25,7 @@ export class StatusServicoProcessor {
async consultarStatusServico(xml: string, cert: any) {
let Sefaz = this.modelo == '65' ? SefazNFCe : SefazNFe;
let soap = Sefaz.getSoapInfo(this.empresa.endereco.uf, this.ambiente, ServicosSefaz.consultarStatusServico);
return await WebServiceHelper.makeSoapRequest(xml, cert, soap);
return await WebServiceHelper.makeSoapRequest(xml, cert, soap, this.webProxy);
}

gerarXmlStatusServico(versao: string, ambiente: string, cUf: string) {
Expand Down
25 changes: 20 additions & 5 deletions src/factory/webservices/webserviceHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ import { XmlHelper } from '../xmlHelper';

import { RetornoProcessamento } from '../interface/nfe'


export interface WebProxy {
host: string;
port: string;
auth?: {
username: string;
password: string;
}
}

export abstract class WebServiceHelper {

public static buildSoapEnvelope(xml: string, soapMethod: string) {
Expand Down Expand Up @@ -35,12 +45,10 @@ export abstract class WebServiceHelper {
}


public static async makeSoapRequest(xml: string, cert: any, soap: any) {
public static async makeSoapRequest(xml: string, cert: any, soap: any, proxy?: WebProxy) {
let result = <RetornoProcessamento>{ xml_enviado: xml };
try {

console.log('----->', soap.url)
let res = await axios({
const reqOpt: any = {
url: soap.url,
method: "post",
httpsAgent: this.getHttpsAgent(cert),
Expand All @@ -49,7 +57,14 @@ export abstract class WebServiceHelper {
"Content-Type": "text/xml;charset=utf-8",
"SOAPAction": soap.action
}
});
}

if (proxy) {
reqOpt.proxy = proxy
}

console.log('----->', soap.url)
let res = await axios(reqOpt);
console.log('----->', res.status)
result.status = res.status;
result.xml_recebido = res.data;
Expand Down

0 comments on commit 56cfbfa

Please sign in to comment.