public int EnviarPagCartão(decimal Vlr) { int NFila = 0; ArrayList XmlPg = new ArrayList(); XmlPg.Add("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); XmlPg.Add("<Integrador>"); XmlPg.Add("<Identificador>"); XmlPg.Add("<Valor>1</Valor>"); XmlPg.Add("</Identificador>"); XmlPg.Add("<Componente Nome=\"VFP-e\">"); XmlPg.Add("<Metodo Nome=\"EnviarPagamento\">"); XmlPg.Add("<Construtor>"); XmlPg.Add("<Parametros>"); XmlPg.Add("<Parametro>"); XmlPg.Add("<Nome>chaveAcessoValidador</Nome>"); XmlPg.Add("<Valor>" + FrmFrenteLoja.FrmPrincipal.Parametros_Filial.ChaveValidador.Trim() + "</Valor>"); XmlPg.Add("</Parametro>"); XmlPg.Add("</Parametros>"); XmlPg.Add("</Construtor>"); XmlPg.Add("<Parametros>"); XmlPg.Add("<Parametro>"); XmlPg.Add("<Nome>ChaveRequisicao</Nome>"); XmlPg.Add("<Valor>" + FrmFrenteLoja.FrmPrincipal.Parametros_Filial.ChaveRequisicao.Trim() + "</Valor>"); XmlPg.Add("</Parametro>"); XmlPg.Add("<Parametro>"); XmlPg.Add("<Nome>Estabelecimento</Nome>"); XmlPg.Add("<Valor>0</Valor>"); XmlPg.Add("</Parametro>"); XmlPg.Add("<Parametro>"); XmlPg.Add("<Nome>SerialPos</Nome>"); XmlPg.Add("<Valor>" + FrmFrenteLoja.FrmPrincipal.Parametros_Filial.SerialPOS.Trim() + "</Valor>"); XmlPg.Add("</Parametro>"); XmlPg.Add("<Parametro>"); XmlPg.Add("<Nome>Cnpj</Nome>"); if (FrmFrenteLoja.FrmPrincipal.Parametros_Filial.NFEAmbiente == 0) { XmlPg.Add("<Valor>28763293000199</Valor>"); //SNPJ Contribuinte } else { XmlPg.Add("<Valor>" + FrmFrenteLoja.CadFilial.Cnpj.Trim() + "</Valor>"); } XmlPg.Add("</Parametro>"); XmlPg.Add("<Parametro>"); XmlPg.Add("<Nome>IcmsBase</Nome>"); //XmlPg.Add("<Valor>0,00</Valor>"); XmlPg.Add("<Valor>" + string.Format("{0:N2}", VlrVenda) + "</Valor>"); XmlPg.Add("</Parametro>"); XmlPg.Add("<Parametro>"); XmlPg.Add("<Nome>ValorTotalVenda</Nome>"); XmlPg.Add("<Valor>" + string.Format("{0:N2}", decimal.Parse(Vlr.ToString())) + "</Valor>"); XmlPg.Add("</Parametro>"); XmlPg.Add("<Parametro>"); XmlPg.Add("<Nome>OrigemPagamento</Nome>"); XmlPg.Add("<Valor>Venda 1</Valor>"); XmlPg.Add("</Parametro>"); XmlPg.Add("<Parametro>"); XmlPg.Add("<Nome>HabilitarMultiplosPagamentos</Nome>"); XmlPg.Add("<Valor>true</Valor>"); XmlPg.Add("</Parametro>"); XmlPg.Add("<Parametro>"); XmlPg.Add("<Nome>HabilitarControleAntiFraude</Nome>"); XmlPg.Add("<Valor>false</Valor>"); XmlPg.Add("</Parametro>"); XmlPg.Add("<Parametro>"); XmlPg.Add("<Nome>CodigoMoeda</Nome>"); XmlPg.Add("<Valor>BRL</Valor>"); XmlPg.Add("</Parametro>"); XmlPg.Add("<Parametro>"); XmlPg.Add("<Nome>EmitirCupomNFCE</Nome>"); XmlPg.Add("<Valor>false</Valor>"); XmlPg.Add("</Parametro>"); XmlPg.Add("</Parametros>"); XmlPg.Add("</Metodo>"); XmlPg.Add("</Componente>"); XmlPg.Add("</Integrador>"); try { string Xml = ""; for (int i = 0; i <= XmlPg.Count - 1; i++) { Xml = Xml + XmlPg[i].ToString(); } StreamWriter XmlNota; DirectoryInfo VerPath = new DirectoryInfo(@"C:\Integrador\Input"); if (!VerPath.Exists) { MessageBox.Show("Pasta Input do Integrador não localizada", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information); return(0); } string vArqXML = @"C:\Integrador\Input\IdPagamento.xml"; XmlNota = File.CreateText(vArqXML); XmlNota.Write(Xml); XmlNota.Close(); VerPath = new DirectoryInfo(System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\MFe_Input\\" + string.Format("{0:D3}", FrmFrenteLoja.FrmPrincipal.Parametros_Filial.IdFilial)); if (!VerPath.Exists) { VerPath.Create(); } vArqXML = System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\MFe_Input\\" + string.Format("{0:D3}", FrmFrenteLoja.FrmPrincipal.Parametros_Filial.IdFilial) + "\\IdPag" + PagCartao["ChaveCFe"].ToString().Trim() + ".xml"; XmlNota = File.CreateText(vArqXML); XmlNota.Write(Xml); XmlNota.Close(); } catch (Exception e) { MessageBox.Show("Falha ao salvar na pasta Input do Integrador, erro: " + e.ToString(), "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information); return(0); } // Lendo o Retorno string ArqRet = ""; for (int a = 1; a <= 10; a++) { string[] ListArquivos = Directory.GetFiles(@"C:\Integrador\Output"); foreach (string Arq in ListArquivos) { ArqRet = Path.GetFileName(Arq); } if (ArqRet != "") { break; } else { System.Threading.Thread.Sleep(1000); } } if (ArqRet == "") { System.IO.File.Delete(@"C:\Integrador\Input\IdPagamento.xml"); MessageBox.Show("Arquivo de Retorno do Pagamento não localizadona na pastra Output do Integrador", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information); return(0); } else { XmlDocument oXML = new XmlDocument(); oXML.Load(@"C:\Integrador\Output\" + ArqRet); try { string IdPag = oXML.GetElementsByTagName("IdPagamento")[0].InnerText; NFila = int.Parse(IdPag); } catch (Exception e) { MessageBox.Show("Registro de Pagamento não Autorizado, erro: " + e.ToString(), "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information); NFila = 0; } System.IO.File.Delete(@"C:\Integrador\Output\" + ArqRet); } return(NFila); }
public int EnviarRespFiscal() { int NResp = 0; ArrayList XmlPg = new ArrayList(); XmlPg.Add("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); XmlPg.Add("<Integrador>"); XmlPg.Add("<Identificador>"); XmlPg.Add("<Valor>1</Valor>"); XmlPg.Add("</Identificador>"); XmlPg.Add("<Componente Nome=\"VFP-e\">"); XmlPg.Add("<Metodo Nome=\"RespostaFiscal\">"); XmlPg.Add("<Construtor>"); XmlPg.Add("<Parametros>"); XmlPg.Add("<Parametro>"); XmlPg.Add("<Nome>chaveAcessoValidador</Nome>"); XmlPg.Add("<Valor>" + FrmFrenteLoja.FrmPrincipal.Parametros_Filial.ChaveValidador.Trim() + "</Valor>"); XmlPg.Add("</Parametro>"); XmlPg.Add("</Parametros>"); XmlPg.Add("</Construtor>"); XmlPg.Add("<Parametros>"); XmlPg.Add("<Parametro>"); XmlPg.Add("<Nome>idFila</Nome>"); XmlPg.Add("<Valor>" + IdPagamento + "</Valor>"); XmlPg.Add("</Parametro>"); XmlPg.Add("<Parametro>"); XmlPg.Add("<Nome>ChaveAcesso</Nome>"); XmlPg.Add("<Valor>" + PagCartao["ChaveCFe"].ToString() + "</Valor>"); XmlPg.Add("</Parametro>"); XmlPg.Add("<Parametro>"); XmlPg.Add("<Nome>Nsu</Nome>"); XmlPg.Add("<Valor>" + TxtNSU.Text.Trim() + "</Valor>"); XmlPg.Add("</Parametro>"); XmlPg.Add("<Parametro>"); XmlPg.Add("<Nome>NumerodeAprovacao</Nome>"); XmlPg.Add("<Valor>" + TxtNrAut.Text.Trim() + "</Valor>"); XmlPg.Add("</Parametro>"); XmlPg.Add("<Parametro>"); XmlPg.Add("<Nome>Bandeira</Nome>"); if (Bandeira == "") { XmlPg.Add("<Valor>" + PagCartao["Documento"].ToString() + "</Valor>"); } else { XmlPg.Add("<Valor>" + Bandeira + "</Valor>"); } XmlPg.Add("</Parametro>"); XmlPg.Add("<Parametro>"); XmlPg.Add("<Nome>Adquirente</Nome>"); if (AdqBandeira == "") { XmlPg.Add("<Valor>" + PagCartao["Adquirente"].ToString() + "</Valor>"); } else { XmlPg.Add("<Valor>" + AdqBandeira + "</Valor>"); } XmlPg.Add("</Parametro>"); XmlPg.Add("<Parametro>"); XmlPg.Add("<Nome>Cnpj</Nome>"); if (FrmFrenteLoja.FrmPrincipal.Parametros_Filial.NFEAmbiente == 0) { XmlPg.Add("<Valor>28763293000188</Valor>"); } else { XmlPg.Add("<Valor>" + FrmFrenteLoja.CadFilial.Cnpj.Trim() + "</Valor>"); } XmlPg.Add("</Parametro>"); XmlPg.Add("<Parametro>"); XmlPg.Add("<Nome>ImpressaoFiscal</Nome>"); // if (Bandeira != "") //{ // XmlPg.Add("<Valor><![CDATA[" + ImpressaoFiscal()); // XmlPg.Add("]]></Valor>"); // } XmlPg.Add("</Parametro>"); XmlPg.Add("<Parametro>"); XmlPg.Add("<Nome>NumeroDocumento</Nome>"); XmlPg.Add("<Valor>" + PagCartao["ChaveCFe"].ToString().Substring(34, 6) + "</Valor>"); XmlPg.Add("</Parametro>"); XmlPg.Add("</Parametros>"); XmlPg.Add("</Metodo>"); XmlPg.Add("</Componente>"); XmlPg.Add("</Integrador>"); try { string Xml = ""; for (int i = 0; i <= XmlPg.Count - 1; i++) { Xml = Xml + XmlPg[i].ToString(); } StreamWriter XmlNota; DirectoryInfo VerPath = new DirectoryInfo(@"C:\Integrador\Input"); if (!VerPath.Exists) { MessageBox.Show("Pasta Input do Integrador não localizada", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information); return(0); } string vArqXML = @"C:\Integrador\Input\RespostaFiscal.xml"; XmlNota = File.CreateText(vArqXML); XmlNota.Write(Xml); XmlNota.Close(); VerPath = new DirectoryInfo(System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\MFe_Input\\" + string.Format("{0:D3}", FrmFrenteLoja.FrmPrincipal.Parametros_Filial.IdFilial)); if (!VerPath.Exists) { VerPath.Create(); } vArqXML = System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\MFe_Input\\" + string.Format("{0:D3}", FrmFrenteLoja.FrmPrincipal.Parametros_Filial.IdFilial) + "\\IdRespFiscal" + PagCartao["ChaveCFe"].ToString().Trim() + ".xml"; XmlNota = File.CreateText(vArqXML); XmlNota.Write(Xml); XmlNota.Close(); } catch (Exception e) { MessageBox.Show("Falha ao salvar na pasta Input do Integrador, erro: " + e.ToString(), "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information); return(0); } // Lendo o Retorno string ArqRet = ""; for (int a = 1; a <= 10; a++) { string[] ListArquivos = Directory.GetFiles(@"C:\Integrador\Output"); foreach (string Arq in ListArquivos) { ArqRet = Path.GetFileName(Arq); } if (ArqRet != "") { break; } else { System.Threading.Thread.Sleep(1000); } } if (ArqRet == "") { MessageBox.Show("Arquivo de Retorno da Respota Fiscal não localizadona na pastra Output do Integrador", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information); return(0); } else { XmlDocument oXML = new XmlDocument(); oXML.Load(@"C:\Integrador\Output\" + ArqRet); try { string IdResp = oXML.GetElementsByTagName("retorno")[0].InnerText; NResp = int.Parse(IdResp); } catch (Exception e) { MessageBox.Show("Registro de Pagamento não Autorizado, erro: " + e.ToString(), "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information); NResp = 0; } System.IO.File.Delete(@"C:\Integrador\Output\" + ArqRet); } return(NResp); }
private void VerifiscarStatusPag() { TxtNrAut.Text = "0"; TxtNSU.Text = "0"; ArrayList XmlPg = new ArrayList(); XmlPg.Add("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); XmlPg.Add("<Integrador>"); XmlPg.Add("<Identificador>"); XmlPg.Add("<Valor>1</Valor>"); XmlPg.Add("</Identificador>"); XmlPg.Add("<Componente Nome=\"VFP-e\">"); XmlPg.Add("<Metodo Nome=\"VerificarStatusValidador\">"); XmlPg.Add("<Construtor>"); XmlPg.Add("<Parametros>"); XmlPg.Add("<Parametro>"); XmlPg.Add("<Nome>chaveAcessoValidador</Nome>"); XmlPg.Add("<Valor>" + FrmFrenteLoja.FrmPrincipal.Parametros_Filial.ChaveValidador.Trim() + "</Valor>"); XmlPg.Add("</Parametro>"); XmlPg.Add("</Parametros>"); XmlPg.Add("</Construtor>"); XmlPg.Add("<Parametros>"); XmlPg.Add("<Parametro>"); XmlPg.Add("<Nome>idFila</Nome>"); XmlPg.Add("<Valor>" + IdPagamento + "</Valor>"); XmlPg.Add("</Parametro>"); XmlPg.Add("<Parametro>"); XmlPg.Add("<Nome>Cnpj</Nome>"); if (FrmFrenteLoja.FrmPrincipal.Parametros_Filial.NFEAmbiente == 0) { XmlPg.Add("<Valor>28763293000188</Valor>"); } else { XmlPg.Add("<Valor>" + FrmFrenteLoja.CadFilial.Cnpj.Trim() + "</Valor>"); } XmlPg.Add("</Parametro>"); XmlPg.Add("</Parametros>"); XmlPg.Add("</Metodo>"); XmlPg.Add("</Componente>"); XmlPg.Add("</Integrador>"); try { string Xml = ""; for (int i = 0; i <= XmlPg.Count - 1; i++) { Xml = Xml + XmlPg[i].ToString(); } StreamWriter XmlNota; DirectoryInfo VerPath = new DirectoryInfo(@"C:\Integrador\Input"); if (!VerPath.Exists) { MessageBox.Show("Pasta Input do Integrador não localizada", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string vArqXML = @"C:\Integrador\Input\VerificarStatusPag.xml"; XmlNota = File.CreateText(vArqXML); XmlNota.Write(Xml); XmlNota.Close(); VerPath = new DirectoryInfo(System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\MFe_Input\\" + string.Format("{0:D3}", FrmFrenteLoja.FrmPrincipal.Parametros_Filial.IdFilial)); if (!VerPath.Exists) { VerPath.Create(); } vArqXML = System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\MFe_Input\\" + string.Format("{0:D3}", FrmFrenteLoja.FrmPrincipal.Parametros_Filial.IdFilial) + "\\VerStaPag" + PagCartao["ChaveCFe"].ToString().Trim() + ".xml"; XmlNota = File.CreateText(vArqXML); XmlNota.Write(Xml); XmlNota.Close(); } catch (Exception e) { MessageBox.Show("Falha ao salvar na pasta Input do Integrador, erro: " + e.ToString(), "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // Lendo o Retorno string ArqRet = ""; for (int a = 1; a <= 10; a++) { string[] ListArquivos = Directory.GetFiles(@"C:\Integrador\Output"); foreach (string Arq in ListArquivos) { ArqRet = Path.GetFileName(Arq); } if (ArqRet != "") { break; } else { System.Threading.Thread.Sleep(1000); } } if (ArqRet == "") { System.IO.File.Delete(@"C:\Integrador\Input\VerificarStatusPag.xml"); MessageBox.Show("Arquivo de Retorno do Pagamento não localizadona na pastra Output do Integrador", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else { XmlDocument oXML = new XmlDocument(); oXML.Load(@"C:\Integrador\Output\" + ArqRet); try { if (oXML.GetElementsByTagName("IdFila")[0].InnerText.ToString().Trim() == "0") { MessageBox.Show("Registro de Pagamento não Localizado", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { TxtNrAut.Text = oXML.GetElementsByTagName("CodigoAutorizacao")[0].InnerText; TxtNSU.Text = oXML.GetElementsByTagName("CodigoPagamento")[0].InnerText; decimal Vlr = decimal.Parse(oXML.GetElementsByTagName("ValorPagamento")[0].InnerText.ToString().Replace(".", ",")); Bandeira = oXML.GetElementsByTagName("Tipo")[0].InnerText; AdqBandeira = oXML.GetElementsByTagName("InstituicaoFinanceira")[0].InnerText; if (Vlr != decimal.Parse(PagCartao["VlrDoc"].ToString())) { System.IO.File.Delete(@"C:\Integrador\Output\" + ArqRet); MessageBox.Show("Valor da VENDA diferente do valor recebido, favor estornar o recebimento e efetuar novo recebimento", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information); IdPagamento = EnviarPagCartão(decimal.Parse(PagCartao["VlrDoc"].ToString())); PagCartao["IDPagMFE"] = IdPagamento.ToString(); IdRespFiscal = 0; TxtNrAut.Text = "0"; TxtNSU.Text = "0"; TxtIdFila.Text = IdPagamento.ToString(); Controle.ExecutaSQL("Update LancFinanceiro set IDPagMFE=" + IdPagamento.ToString() + " where id_lanc=" + PagCartao["IdFinanc"].ToString()); NovoIDPag = true; return; } } } catch (Exception e) { MessageBox.Show("Registro de Pagamento não Autorizado, erro: " + e.ToString(), "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information); } System.IO.File.Delete(@"C:\Integrador\Output\" + ArqRet); } return; }