public HMRCResponse Save(HMRCResponse response) { var res = _hmrcResponseRepository.Add(response); SaveCommit(); return(res); }
public HMRCResponse SendDataRequest(string senderId, string senderValue, bool testInLive) { HMRCResponse hmrcResponse = (HMRCResponse)null; if (testInLive) { _submissionUrl = ConfigurationManager.AppSettings["testsubmissionurl"]; } else { _submissionUrl = ConfigurationManager.AppSettings["submissionurl"]; } if (!String.IsNullOrEmpty(senderId) && !String.IsNullOrEmpty(senderValue)) { var govTalkMessageForDataRequest = _gatewayService.CreateGovTalkMessageForDataRequest(senderId, senderValue, testInLive); var dataRequest = HelperMethods.GovTalkMessageToXDocumentForData(govTalkMessageForDataRequest, testInLive); var strDataRequest = dataRequest.ToString(); Log(strDataRequest, _filepath, "submission_dataRequest"); if (!(String.IsNullOrEmpty(strDataRequest))) { hmrcResponse = _gatewayService.SendHMRCMessage(strDataRequest, _submissionUrl); Log(hmrcResponse.ResponseData, _filepath, "submission_dataResponse"); return(hmrcResponse); } } Log(hmrcResponse.ResponseData, _filepath, "submission_deleteResponse"); return(hmrcResponse); }
public HMRCResponse SendHMRCMessage(string message, string uri) { HMRCResponse hmrcResponse = (HMRCResponse)null; if (uri.Trim() != "" && message != null) { try { HttpWebRequest httpWebRequest = WebRequest.Create(uri) as HttpWebRequest; if (httpWebRequest != null) { httpWebRequest.Method = "POST"; byte[] bytes = Encoding.UTF8.GetBytes(message); httpWebRequest.ContentType = "application/x-www-form-urlencoded"; httpWebRequest.ContentLength = (long)bytes.Length; Stream requestStream = httpWebRequest.GetRequestStream(); requestStream.Write(bytes, 0, bytes.Length); requestStream.Close(); HttpWebResponse httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse; if (httpWebResponse != null && httpWebResponse.StatusCode == HttpStatusCode.OK) { Stream responseStream = httpWebResponse.GetResponseStream(); if (responseStream != null) { StreamReader streamReader = new StreamReader(responseStream); string str = streamReader.ReadToEnd(); hmrcResponse = new HMRCResponse(str); streamReader.Close(); } if (responseStream != null) { responseStream.Close(); } } if (httpWebResponse != null) { httpWebResponse.Close(); } } } catch (WebException ex) { using (var stream = ex.Response.GetResponseStream()) { if (stream != null) { using (var reader = new StreamReader(stream)) { string str = reader.ReadToEnd(); hmrcResponse = new HMRCResponse(str); } } hmrcResponse = null; } } } return(hmrcResponse); }
public ResponseViewModel(HMRCResponse XML) { if(XML != null) { var strContent = HelperMethods.ExtractBodyContent(XML.ResponseData.ToString()); this._response = HelperMethods.Deserialize<SuccessResponse>(strContent); this._message = _response.Message; } }
public HMRCResponse SendDeleteRequest(string correlationId, bool testInLive, string uri) { HMRCResponse hmrcResponse = (HMRCResponse)null; if (!String.IsNullOrEmpty(correlationId)) { var govTalkMessageForDeletion = _gatewayService.CreateGovTalkMessageForDeleteRequest(correlationId, testInLive); //StringWriter sw = new StringWriter(); //var deleteReq = new XmlSerializer(typeof(GovTalkMessage)); //deleteReq.Serialize(sw, govTalkMessageForDeletion); var deletereq = HelperMethods.GovTalkMessageToXDocumentForDelete(govTalkMessageForDeletion, testInLive).ToString(); var strdeleteReq = deletereq.ToString(); Log(strdeleteReq, _filepath, "submission_deleteRequest"); if (!(String.IsNullOrEmpty(strdeleteReq))) { hmrcResponse = _gatewayService.SendHMRCMessage(strdeleteReq, uri); Log(hmrcResponse.ResponseData, _filepath, "submission_deleteResponse"); return(hmrcResponse); } } Log(hmrcResponse.ResponseData, _filepath, "submission_deleteResponse"); return(hmrcResponse); }
public HMRCResponse SendSubmissionRequest(Sender sender, Business business, PeriodData periodData, VAT100 vatData, bool testInLive) { HMRCResponse hmrcResponse = (HMRCResponse)null; if (testInLive) { _submissionUrl = ConfigurationManager.AppSettings["testsubmissionurl"]; } else { _submissionUrl = ConfigurationManager.AppSettings["submissionurl"]; } //create govtalk message var govTalkMessage = _gatewayService.CreateGovTalkMessage(sender, business, periodData, vatData, testInLive); //serailize object to string //var strGovTalkMessage = HelperMethods.Serialize(govTalkMessage); var strGovTalkMessage = HelperMethods.GovTalkMessageToXDocument(govTalkMessage).ToString(); //generate irmark from govtalk message byte[] bytes = Encoding.UTF8.GetBytes(strGovTalkMessage); //var iREnvelopeBody = _gatewayService.CreateIRenvelopeBody(sender, business, perioddata, vatData); var irmark = HelperMethods.GetIRMark(bytes); XDocument xdoc; //set irmark value to the govtalk message body if (irmark != null) { xdoc = XDocument.Parse(strGovTalkMessage, LoadOptions.PreserveWhitespace); //xdoc.Save("Without.xml"); if (xdoc.Root != null) { XNamespace ns = xdoc.Root.Name.Namespace; XElement body = xdoc.Root.Element(ns + "Body"); if (body != null) { var bodyElelemts = from el in body.Descendants() where el.Name.LocalName == "IRenvelope" select el; foreach (var ele in bodyElelemts) { XNamespace ns1 = ele.Name.Namespace; var element = ele.Descendants(ns1 + "IRmark").First(); if (element != null) { element.Value = irmark; } } } } string strSendRequest = xdoc.ToString(); this._filename = business.BusinessName.ToString(); this._path = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/ClientData"), _filename); bool folderexists = CreateBusDir(_path); bool periodexists = CreatePerdiodDir(_path + "\\" + periodData.PeriodrefId); this._filepath = _path + "\\" + periodData.PeriodrefId; if (folderexists == true && periodexists) { Log(strSendRequest, _filepath, "submission_Request"); //System.IO.StreamWriter file = new System.IO.StreamWriter(_filepath +"\\" + "submissionrequest.xml"+DateTime.Now); //file.WriteLine(strSendRequest); //file.Close(); } hmrcResponse = _gatewayService.SendHMRCMessage(strSendRequest, _submissionUrl); if (_filepath != null && hmrcResponse.ResponseData != null) { if (hmrcResponse.Type.ToString() == "error") { Log(hmrcResponse.ResponseData, _filepath, "submission_Error"); } else if (hmrcResponse.Type.ToString() == "acknowledgement") { Log(hmrcResponse.ResponseData, _filepath, "submission_Acknowledgement"); } else { Log(hmrcResponse.ResponseData, _filepath, "submission_Response"); } } return(hmrcResponse); } return(null); }