//--------------------------------------------------------------------------------------------- /// <summary> /// Handle an error response from HMRC /// </summary> /// <param name="aResponse"></param> private int ProcessErrorResponse(VAT100_BusinessErrorResponse aResponse) { // The response was not good news string errorNarrative = string.Empty; int Result = 0; VAT100BusinessResponseDetails details = aResponse.GovTalkDetails; if (details.GovTalkErrors.Count > 0) { for (int index = 0; index < details.GovTalkErrors.Count; index++) { GovTalkError error = details.GovTalkErrors[index]; errorNarrative += error.Error.Text + "\n\r\n\r"; } } // GovTalkErrors done. Now look for messages in the <Body> if (aResponse.Body.ErrorResponse != null) { if (aResponse.Body.ErrorResponse.ErrorList.Length > 0) { foreach (VAT100_ErrorResponseError error in aResponse.Body.ErrorResponse.ErrorList) { errorNarrative += error.Text + "\n\r\n\r"; errorNarrative += error.Location + "\n\r"; } } } // Update its status FPendingDocument.theDocument.status = Convert.ToInt16(SubmissionStatus.ssError); // Add the narrative FPendingDocument.theDocument.hmrcNarrative = errorNarrative; // Save the record Result = VAT100Database.Instance.UpdateVAT100Entry(FPendingDocument.theDocument, FPendingDocument.companyCode); return(Result); }
private int ProcessErrorResponse(VAT100_BusinessErrorResponse aResponse) { // The response was not good news string errorNarrative = string.Empty; int Result = 0; VAT100BusinessResponseDetails details = aResponse.GovTalkDetails; if (details.GovTalkErrors.Count > 0) { for (int index = 0; index < details.GovTalkErrors.Count; index++) { GovTalkError error = details.GovTalkErrors[index]; errorNarrative += error.Error.Text + "\n\r\n\r"; } } // GovTalkErrors done. Now look for messages in the <Body> if (aResponse.Body.ErrorResponse != null) { if (aResponse.Body.ErrorResponse.ErrorList.Length > 0) { foreach (VAT100_ErrorResponseError error in aResponse.Body.ErrorResponse.ErrorList) { errorNarrative += error.Text + "\n\r\n\r"; errorNarrative += error.Location + "\n\r"; } } } // Add the narrative textNarrative.AppendText(errorNarrative + "\r\n\r\n"); return(Result); }
/// <summary> /// Handles the response returned from the HMRC Gateway for the VAT Submission /// that is currently being processed. Returns false if the response is either /// that the VAT Return was in error or if it was accepted successfully, and /// therefore that polling should be stopped. Otherwise it returns true, and /// polling should continue. /// </summary> /// <param name="responseXML"></param> /// <returns></returns> private int HandleHMRCResponse(string responseXML) { string filename; int Result = 0; // Deserialise the response. At this point we don't know if its a business response or an error response. VAT100_BusinessResponseMessage responseMsg = null; VAT100_BusinessErrorResponse errorMsg = null; try { XmlSerializer responseSerialiser = new XmlSerializer(typeof(VAT100_BusinessResponseMessage)); using (StringReader reader = new StringReader(responseXML)) { responseMsg = (VAT100_BusinessResponseMessage)(responseSerialiser.Deserialize(reader)); } XmlSerializer errorSerialiser = new XmlSerializer(typeof(VAT100_BusinessErrorResponse)); using (StringReader reader = new StringReader(responseXML)) { errorMsg = (VAT100_BusinessErrorResponse)(errorSerialiser.Deserialize(reader)); } } catch (Exception ex) { LogText("Error handling HMRC response : " + ex.Message); } //........................................................................................... // Determine the response type. // For a pending submission, this will be "acknowledgement" // For a successful submission, this will be "response" // For a submission failure, this will be "error" string responseType = responseMsg.Header.MessageDetails.Qualifier; // response, error, acknowledgement string function = responseMsg.Header.MessageDetails.Function; switch (responseType.ToLower()) { case "acknowledgement": // Nothing to do. We'll continue polling until we get a business response or an error. Log.Add("Acknowledgement received"); Result = 0; break; case "response": // Business Response. We can stop polling, save the data and then delete the request (unless it was a delete). Log.Add("Response received"); // CJS 2015-09-24 - ABSEXCH-16922 - HMRC Filing VAT Submissions xml folder // Save the XML filename = string.Format("response{0}.xml", responseMsg.Body.SuccessResponse.ResponseData.VATDeclarationResponse.Header.VATPeriod.PeriodId); XMLWrite.ToReceivedFolder(FDatabase.tToolkit.Configuration.EnterpriseDirectory, filename, responseXML); Result = ProcessBusinessResponse(responseMsg); if (function.ToLower() != "delete") { Delete(FPendingDocument.theDocument.correlationID); } break; case "error": Log.Add("Error response received"); // CJS 2015-09-24 - ABSEXCH-16922 - HMRC Filing VAT Submissions xml folder // Save the XML DateTime timenow = DateTime.Now; filename = string.Format("error{0:yyyyMMdd_hhmm}.xml", timenow); XMLWrite.ToReceivedFolder(FDatabase.tToolkit.Configuration.EnterpriseDirectory, filename, responseXML); // Error Response. We can stop polling, save the data and then delete the request (unless it was a delete). Result = ProcessErrorResponse(errorMsg); if (function.ToLower() != "delete") { Delete(FPendingDocument.theDocument.correlationID); } break; default: // Unrecognised response qualifier throw new Exception("Unexpected response received from HMRC"); } return(Result); }