Esempio n. 1
0
        /// <summary>
        /// Envia una Resumen de Boletas o Comunicaciones de Baja a Sunat
        /// </summary>
        /// <param name="pathFile">Ruta del archivo XML que contiene el resumen</param>
        /// <param name="content">Contenido del archivo</param>
        /// <returns>Retorna un estado booleano que indica si no hubo errores, con un string que contiene el Nro Ticket,
        /// con el que posteriormente, utilizando el método getStatus se puede obtener Constancia de Recepcióno</returns>
        public async Task <TicketResponse> SendSummary(string pathFile, byte[] content)
        {
            var fileToZip     = pathFile + Resources.ExtensionFile;
            var nameOfFileZip = pathFile + Resources.ExtensionZipFile;
            var res           = new TicketResponse();

            try
            {
                var zipBytes = ProcessZip.CompressFile(fileToZip, content);
                var service  = ServiceHelper.GetService <billService>(_config, _url);

                var result = await service.sendSummaryAsync(new sendSummaryRequest(nameOfFileZip, zipBytes));

                res.Ticket  = result.ticket;
                res.Success = true;
            }
            catch (FaultException ex)
            {
                res.Error = GetErrorFromFault(ex);
            }
            catch (Exception er)
            {
                res.Error = new ErrorResponse
                {
                    Description = er.Message
                };
            }
            return(res);
        }
Esempio n. 2
0
        /// <summary>
        /// Recibe la ruta XML con un único formato digital y devuelve la Constancia de Recepción – SUNAT.
        /// </summary>
        /// <param name="pathFile">Ruta del Archivo XML</param>
        /// <param name="content">Contenido del archivo</param>
        /// <returns>La respuesta contenida en el XML de Respuesta de la Sunat, si existe</returns>
        public async Task <SunatResponse> SendDocument(string pathFile, byte[] content)
        {
            var fileToZip     = pathFile + Resources.ExtensionFile;
            var nameOfFileZip = pathFile + Resources.ExtensionZipFile;

            var res = new SunatResponse
            {
                Success = false
            };

            try
            {
                var zipBytes = ProcessZip.CompressFile(fileToZip, content);
                var service  = ServiceHelper.GetService <billService>(_config, _url);
                var result   = await service.sendBillAsync(new sendBillRequest(nameOfFileZip, zipBytes));

                using (var outputXml = ProcessZip.ExtractFile(result.applicationResponse))
                    res = new SunatResponse
                    {
                        Success             = true,
                        ApplicationResponse = ProcessXml.GetAppResponse(outputXml),
                        ContentZip          = result.applicationResponse
                    };
            }
            catch (FaultException ex)
            {
                res.Error = GetErrorFromFault(ex);
            }
            catch (Exception er)
            {
                res.Error = new ErrorResponse
                {
                    Description = er.Message
                };
            }

            return(res);
        }