public bool ConfirmTransaction(int orderNumber, decimal orderTotal, string referenceNum) { string error; List <FirstPayTransaction> transactions; FirstPayTransaction transaction; FirstPayXmlResponse response = QueryGatewayForOrder(orderNumber); if (response == null) { return(false); } transactions = response.GetTransactionsFromQuery(); //Check to see if we have a transaction that matches our order number, reference number from first pay, and order total transaction = transactions.FirstOrDefault(t => t.ReferenceNumber.ToString() == referenceNum && t.OrderId == orderNumber.ToString() && t.Amount == orderTotal); //If we have no matching transaction or the transaction had a failed status then bail if (transaction == null || transaction.Status == 0) { return(false); } error = response.Fields.ContainsKey("error") ? response.Fields["error"] : ""; //At this point this should always be true but incase there is an error we'll catch it here (query should not return the error node and transactions) bool OrderIsValid = string.IsNullOrEmpty(error); //make sure our transaction was not voided or credited OrderIsValid = OrderIsValid && transaction.CreditVoid.ToLower() == "none"; return(OrderIsValid); }
public bool GetXmlResponse(string transactionCommand, out string response, out FirstPayXmlResponse xmlResponse) { Encoding encoding = System.Text.Encoding.GetEncoding(1252); bool returnVal = false; response = null; xmlResponse = null; byte[] data = encoding.GetBytes(transactionCommand); // Prepare web request... try { string AuthServer = AppLogic.AppConfig("1stPay.XmlURL"); HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(AuthServer); myRequest.ContentLength = data.Length; myRequest.Method = "POST"; Stream newStream = myRequest.GetRequestStream(); // Send the data. newStream.Write(data, 0, data.Length); newStream.Close(); // get the response HttpWebResponse myResponse; myResponse = (HttpWebResponse)myRequest.GetResponse(); using (StreamReader sr = new StreamReader(myResponse.GetResponseStream(), encoding)) { response = sr.ReadToEnd(); // Close and clean up the StreamReader sr.Close(); } myResponse.Close(); XmlDocument Doc = new XmlDocument(); // Zap the DOCTYPE so we don't try to find a corresponding DTD. string t1 = "<!DOCTYPE Response SYSTEM"; string t2 = ">"; string doctype = t1 + CommonLogic.ExtractToken(response, t1, t2) + t2; Doc.LoadXml(response.Replace(doctype, "")); xmlResponse = new FirstPayXmlResponse(Doc); returnVal = true; } catch { } return(returnVal); }