/// <summary> /// Uses the given path with the BaseUri and ApiKey to make a call to the /// ThreadFix REST API using the HTTP verb POST. /// </summary> /// <param name="path">Path to the resources to post to (i.e. teams/new)</param> /// <param name="data">Data to post</param> /// <returns>JsonResponse</returns> async Task <JsonResponse> Post(string path, NameValuePairs nvPairs, Type objectType) { path = "threadfix/" + REST + "/" + path; path += String.Format("?apiKey={0}", ApiKey); //JSON content //StringContent content = new StringContent(nvPairs.ToJson(), Encoding.UTF8, "application/json"); //Query content StringContent content = new StringContent(nvPairs.ToString(), Encoding.UTF8, "application/x-www-form-urlencoded"); Uri uri = new Uri(BaseUri, path); Log.Debug(String.Format("Sending HTTP POST request to {0} containing data: {1}", uri, nvPairs)); HttpResponseMessage response = await Client.PostAsync( uri, content); Log.Debug(String.Format("Received HTTP response from {1}: {0}", response.StatusCode, uri)); response.EnsureSuccessStatusCode(); string json = await response.Content.ReadAsStringAsync(); return(JsonResponse.GetInstance(json, objectType)); }
internal SolidTrustPayTransactionResponse(SolidTrustPayAccount usedAccount, NameValuePairs response, string rawResponse) { RawResponse = response.ToString(); UsedAccount = usedAccount; Note = string.Empty; //Get success indicator IsSuccess = rawResponse.Contains("ACCEPTED"); Note = rawResponse; //Get reference number if (IsSuccess) { try { int beginIndex = rawResponse.IndexOf("=") + 1; int endIndex = rawResponse.IndexOf("Status") - 1; ReferenceNumber = rawResponse.Substring(beginIndex, endIndex); } catch (Exception ex) { ErrorLogger.Log(ex); } } }
internal PayPalTransactionResponse(PayPalAccount usedAccount, NameValuePairs response) { RawResponse = response.ToString(); UsedAccount = usedAccount; Note = string.Empty; string refNo; response.TryGetValue("responseEnvelope.correlationId", out refNo); ReferenceNumber = refNo; string success = ""; bool isAck = response.TryGetValue("paymentExecStatus", out success); IsSuccess = isAck && String.Equals(success, "COMPLETED", StringComparison.OrdinalIgnoreCase); if (!IsSuccess) { string errorCode, message; if (!response.TryGetValue("error.errorId", out errorCode)) { response.TryGetValue("error(0).errorId", out errorCode); if (!response.TryGetValue("error(0).errorId", out errorCode)) { response.TryGetValue("L_ERRORCODE0", out errorCode); } } if (!response.TryGetValue("error.message", out message)) { response.TryGetValue("error(0).message", out message); if (!response.TryGetValue("error(0).message", out message)) { response.TryGetValue("L_LONGMESSAGE0", out message); } } Note = errorCode + ": " + message; } else { Note = Resources.U4000.MONEYSENT.Replace("%p%", "PayPal"); } }
internal PayPalTransactionResponseForMassPay(PayPalAccount usedAccount, NameValuePairs response) { RawResponse = response.ToString(); UsedAccount = usedAccount; Note = string.Empty; string refNo; response.TryGetValue("CORRELATIONID", out refNo); ReferenceNumber = refNo; string success = ""; bool isAck = response.TryGetValue("ACK", out success); IsSuccess = isAck && String.Equals(success, "Success", StringComparison.OrdinalIgnoreCase); if (!IsSuccess) { string severity, errorCode, message; if ((!response.TryGetValue("error.severity", out severity)) || !response.TryGetValue("error(0).severity", out severity)) { response.TryGetValue("L_SHORTMESSAGE0", out severity); } if ((!response.TryGetValue("error.errorId", out errorCode)) || !response.TryGetValue("error(0).errorId", out errorCode)) { response.TryGetValue("L_ERRORCODE0", out errorCode); } if ((!response.TryGetValue("error.message", out message)) || !response.TryGetValue("error(0).message", out message)) { response.TryGetValue("L_LONGMESSAGE0", out message); } Note = severity + " " + errorCode + ": " + message; } else { Note = Resources.U4000.MONEYSENT.Replace("%p%", "PayPal"); } }
internal PayzaTransactionResponse(PayzaAccount usedAccount, NameValuePairs response) { RawResponse = response.ToString(); UsedAccount = usedAccount; try { string refNo; response.TryGetValue("REFERENCENUMBER", out refNo); ReferenceNumber = refNo; ReturnCode = Convert.ToInt32(response["RETURNCODE"]); Note = response["DESCRIPTION"]; IsTestMode = response["TESTMODE"] == "1"; } catch (Exception e) { ErrorLogger.Log(e); } IsSuccess = (ReturnCode == SuccessCode); }
internal EgoPayTransactionResponse(EgoPayAccount usedAccount, NameValuePairs response) { RawResponse = response.ToString(); UsedAccount = usedAccount; Note = string.Empty; string refNo; response.TryGetValue("responseEnvelope.correlationId", out refNo); ReferenceNumber = refNo; string success = ""; bool isAck = response.TryGetValue("paymentExecStatus", out success); IsSuccess = isAck && String.Equals(success, "COMPLETED", StringComparison.OrdinalIgnoreCase); if (!IsSuccess) { string severity, errorCode, message; if (!response.TryGetValue("error.severity", out severity)) { response.TryGetValue("error(0).severity", out severity); } if (!response.TryGetValue("error.errorId", out errorCode)) { response.TryGetValue("error(0).errorId", out errorCode); } if (!response.TryGetValue("error.message", out message)) { response.TryGetValue("error(0).message", out message); } Note = severity + " " + errorCode + ": " + message; } }