private string SendRetrievalRequest(string urlRoute) { try { ConfigureCommunication(); var responseContent = _communication.Get(urlRoute); var receivedBytes = responseContent.GetByteData(); var xmlResponse = ChargebackUtils.BytesToString(receivedBytes); ChargebackUtils.PrintXml(xmlResponse, Config.Get("printXml"), Config.Get("neuterXml")); return(xmlResponse); } catch (WebException we) { throw ChargebackRetrievalWebException(we); } }
private ChargebackWebException ChargebackRetrievalWebException(WebException we) { var webErrorResponse = (HttpWebResponse)we.Response; var httpStatusCode = (int)webErrorResponse.StatusCode; var rawResponse = ChargebackUtils.GetResponseXml(webErrorResponse); if (!webErrorResponse.ContentType.Contains("application/com.vantivcnp.services-v2+xml")) { return(new ChargebackWebException(string.Format("Retrieval Failed - HTTP {0} Error", httpStatusCode), httpStatusCode, rawResponse)); } ChargebackUtils.PrintXml(rawResponse, Config.Get("printXml"), Config.Get("neuterXml")); var errorResponse = ChargebackUtils.DeserializeResponse <errorResponse>(rawResponse); var errorMessages = errorResponse.errors; return(new ChargebackWebException(string.Format("Retrieval Failed - HTTP {0} Error", httpStatusCode), httpStatusCode, rawResponse, errorMessages)); }
private chargebackUpdateResponse SendUpdateRequest(long caseId, string xmlBody) { string xmlRequest = Serialize(xmlBody); ChargebackUtils.PrintXml(xmlRequest, Config.Get("printXml"), Config.Get("neuterXml")); try { ConfigureCommunication(); var responseContent = communication.Put(ServiceRoute + "/" + caseId, ChargebackUtils.StringToBytes(xmlRequest)); var receivedBytes = responseContent.GetByteData(); var xmlResponse = ChargebackUtils.BytesToString(receivedBytes); ChargebackUtils.PrintXml(xmlResponse, Config.Get("printXml"), Config.Get("neuterXml")); return(ChargebackUtils.DeserializeResponse <chargebackUpdateResponse>(xmlResponse)); } catch (WebException we) { throw ChargebackUpdateWebException(we); } }
private chargebackDocumentUploadResponse HandleResponse(ResponseContent responseContent) { var contentType = responseContent.GetContentType(); var responseBytes = responseContent.GetByteData(); if (!contentType.Contains("application/com.vantivcnp.services-v2+xml")) { var stringResponse = ChargebackUtils.BytesToString(responseBytes); throw new ChargebackException( string.Format("Unexpected returned Content-Type: {0}. Call Vantiv immediately!" + "\nAttempting to read the response as raw text:" + "\n{1}", contentType, stringResponse)); } var xmlResponse = ChargebackUtils.BytesToString(responseBytes); ChargebackUtils.PrintXml(xmlResponse, Config.Get("printXml"), Config.Get("neuterXml")); var docResponse = ChargebackUtils.DeserializeResponse <chargebackDocumentUploadResponse>(xmlResponse); return(docResponse); }