public async Task <IHttpActionResult> DenyDocument([FromBody] object document) { response = new GenericResponse(); actionDocument = new Document(); try { dynamic dynamicObject = JObject.Parse(document.ToString()); AceptaRechazaDocumento aceptaDocumento = JsonConvert.DeserializeObject <AceptaRechazaDocumento>(dynamicObject.document.ToString()); /*new AceptaRechazaDocumento() * { * NombreEmisor = document.NombreEmisor, * NumCedulaEmisor = document.NumCedulaEmisor, * FechaEmisionDoc = DateTime.Now, * NumConsecutivoCompr = document.NumConsecutivoCompr, * TipoDoc = document.TipoDoc, * Mensaje = document.Mensaje, * DetalleMensaje = document.DetalleMensaje, * NombreReceptor = document.NombreReceptor, * NumCedulaReceptor = document.NumCedulaReceptor, * IdentificacionExtranjero = document.IdentificacionExtranjero, * NumConsecutivorecep = document.NumConsecutivorecep * }; */ //var result = await actionDocument.SendAceptDenyDocument(aceptaDocumento, dynamicObject.accountId); response.input = document; response.status = HttpStatusCode.OK; } catch (Exception ex) { Utils.SetExceptionToResponse(ref response, ex); } return(Ok(JObject.Parse(JsonConvert.SerializeObject(response)))); }
public async Task <ReceivedDigitalDocument> SendAceptDenyDocument(AceptaRechazaDocumento documento, CredentialData credential, RequestAdditionalInfo additionalInfo) { ReceivedDigitalDocument InvoiceResponse = new ReceivedDigitalDocument(); string respuesta = string.Empty; X509Certificate2 cert; AuthenticationResponse oAuthResponse; XmlDocument xmlDocInvoice; object newRequest = null; try { if (!string.IsNullOrEmpty(credential.certificate) && !string.IsNullOrEmpty(credential.certificatePassword)) { cert = new X509Certificate2(Convert.FromBase64String(credential.certificate), credential.certificatePassword); } else { throw new Exception(Constants.Constants.fail_CertificateInfo_incomplete); } xmlDocInvoice = Utils.GetXmlFromObject(documento); CustomSignature.SignXML(documento.FechaEmisionDoc, ref xmlDocInvoice, null, cert); oAuthResponse = await Authentication.Instance().AuthenticationMH(credential.atvUser, credential.atvPassword); if (oAuthResponse != null) { newRequest = new { clave = documento.Clave, fecha = documento.FechaEmisionDoc, emisor = new { additionalInfo.Emisor.tipoIdentificacion, additionalInfo.Emisor.numeroIdentificacion }, receptor = new { additionalInfo.Receptor.tipoIdentificacion, additionalInfo.Receptor.numeroIdentificacion }, consecutivoReceptor = additionalInfo.ConsecutivoReceptor, comprobanteXml = Convert.ToBase64String(Encoding.UTF8.GetBytes(xmlDocInvoice.OuterXml)), callbackUrl = string.Format(Constants.Constants.RequestApiFormat_2, ConfigurationManager.AppSettings[Constants.Constants.serverDomain], ConfigurationManager.AppSettings[Constants.Constants.CallBackUrl]) }; } else { throw new Exception(Constants.Constants.fail_communication_oauth_hacienda); } try { HttpCustomClient client = new HttpCustomClient(); InvoiceResponse = await client.Post(newRequest, Constants.Constants.mhActionRecepcion, Constants.Constants.mhEndpoint, null, oAuthResponse.access_token); InvoiceResponse.xmlInvoice = Convert.ToBase64String(Encoding.UTF8.GetBytes(xmlDocInvoice.OuterXml)); InvoiceResponse.pdfInvoice = ""; } catch (Exception ex) { throw ex; } } catch (Exception ex) { ex.Message.ToString(); } return(InvoiceResponse); }