public static ProcessingResults QueryMPITransaction(string transactionId) { if ((transactionId == "") || (transactionId == null)) { return(null); } var rand = new Random(); string uniqueID = DateTime.Now.ToString("yyyyddMM") + rand.Next(0, 1000); string result = ""; string poststring = "user="******"&password="******"&int_in=<ashrait>" + "<request>" + "<language>HEB</language>" + "<command>inquireTransactions</command>" + "<inquireTransactions>" + "<terminalNumber>" + _newCardTerminalId + "</terminalNumber>" + "<mainTerminalNumber/>" + "<queryName>mpiTransaction</queryName>" + "<mid>" + _mid + "</mid>" + "<mpiTransactionId>" + transactionId + "</mpiTransactionId>" + "<userData1/>" + "<userData2/>" + "<userData3/>" + "<userData4/>" + "<userData5/>" + "</inquireTransactions>" + "</request>" + "</ashrait>"; StreamWriter myWriter = null; var objRequest = (HttpWebRequest)WebRequest.Create(_gatewayUrl); objRequest.Method = "POST"; objRequest.ContentLength = poststring.Length; objRequest.ContentType = "application/x-www-form-urlencoded"; var processingResults = new ProcessingResults(); Helpers.LogProcessing("QueryMPITransaction - " + transactionId + " - request", poststring, false); try { myWriter = new StreamWriter(objRequest.GetRequestStream()); myWriter.Write(poststring); } catch (Exception e) { //log e.Message; Helpers.LogProcessing("QueryMPITransaction - ex -" + transactionId + " - ", result + "\n exception: " + e.ToString(), true); processingResults.ErrorMessage = e.Message; } finally { myWriter.Close(); } var objResponse = (HttpWebResponse)objRequest.GetResponse(); using (StreamReader sr = new StreamReader(objResponse.GetResponseStream())) { result = sr.ReadToEnd(); Helpers.LogProcessing("QueryMPITransaction - " + transactionId + " - response", result, false); // Close and clean up the StreamReader sr.Close(); } var doc = new XmlDocument(); doc.LoadXml(result); string cardToken = doc.GetElementsByTagName("cardId")[0].InnerText; processingResults.ResultCode = doc.GetElementsByTagName("result")[1].InnerText; processingResults.UniqueId = Convert.ToInt64(doc.GetElementsByTagName("uniqueid")[0].InnerText); processingResults.AuthNumber = doc.GetElementsByTagName("authNumber")[0].InnerText; processingResults.CardToken = doc.GetElementsByTagName("cardId")[0].InnerText; processingResults.CardExpiration = doc.GetElementsByTagName("cardExpiration")[0].InnerText; processingResults.PersonalId = doc.GetElementsByTagName("personalId")[0].InnerText; processingResults.TransactionID = doc.GetElementsByTagName("tranId")[0].InnerText; processingResults.Last4Digits = cardToken.Substring(cardToken.Length - 4); if (doc.GetElementsByTagName("statusText") != null && doc.GetElementsByTagName("statusText").Count > 1) { processingResults.ErrorMessage = doc.GetElementsByTagName("statusText")[1].InnerText; } return(processingResults); }
public static ProcessingResults ProcessSavedCard(long appUserId, decimal amount, int numberOfPayments, string mastercardId, string specialInstructions, string cardToken, string cardExpiration, out string transactionId) { string result = ""; int firstPayment = 0; int periodicalPaymentNum = 0; int periodicalPayment = 0; string numOfPaymentsText = "<numberOfPayments/>"; string creditType = "RegularCredit"; transactionId = null; if (numberOfPayments > 1) { periodicalPayment = (100 / numberOfPayments); periodicalPaymentNum = numberOfPayments - 1; creditType = "Payments"; firstPayment = (100 - periodicalPayment * periodicalPaymentNum); numOfPaymentsText = "<numberOfPayments>" + periodicalPaymentNum + "</numberOfPayments>" + "<firstPayment>" + firstPayment + "</firstPayment>" + "<periodicalPayment>" + periodicalPayment + "</periodicalPayment>"; } bool isProduction = Convert.ToBoolean(AppConfig.GetString(@"IsProduction", @"false")); String poststring = "user="******"&password="******"&int_in=" + "<ashrait>" + "<request>" + "<command>doDeal</command>" + "<version>1001</version>" + "<language>HEB</language>" + "<mayBeDuplicate>0</mayBeDuplicate>" + "<doDeal>" + "<terminalNumber>" + _terminalId + "</terminalNumber>" + "<cardId>" + cardToken + "</cardId>" + "<cardExpiration>" + cardExpiration + "</cardExpiration>" + "<transactionType>Debit</transactionType>" + "<currency>ILS</currency>" + "<transactionCode>Phone</transactionCode>" + "<total>" + 100 + "</total>" + "<validation>Verify</validation>"; if (isProduction) { poststring += "<dealerNumber>" + mastercardId + "</dealerNumber>"; } poststring += "<authNumber/>" + numOfPaymentsText + "<creditType>" + creditType + "</creditType>" + "<user>" + _userId + "</user>" + "<customerData>" + "<userData2>" + numberOfPayments + "</userData2>" + "<userData3>" + specialInstructions + "</userData3>" + "<userData4>" + appUserId + "</userData4>" + "<userData5/>" + "<userData6/>" + "<userData7/>" + "<userData8/>" + "<userData9/>" + "<userData10/>" + "</customerData>" + "</doDeal>" + "</request>" + "</ashrait>"; StreamWriter myWriter = null; HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(_gatewayUrl); objRequest.Method = "POST"; objRequest.ContentType = "application/x-www-form-urlencoded"; //ServicePointManager.ServerCertificateValidationCallback = //delegate(object s, X509Certificate certificate, // X509Chain chain, SslPolicyErrors sslPolicyErrors) //{ return true; }; ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; var processingResults = new ProcessingResults(); try { Helpers.LogProcessing("ProcessSavedCard- " + cardToken + "- request", poststring, false); myWriter = new StreamWriter(objRequest.GetRequestStream()); myWriter.Write(poststring); } catch (Exception e) { Helpers.LogProcessing("ProcessSavedCard - ex -" + cardToken + " - ", result + "\n exception: " + e.ToString(), true); processingResults.ErrorMessage = e.Message; } finally { myWriter.Close(); } var objResponse = (HttpWebResponse)objRequest.GetResponse(); using (StreamReader sr = new StreamReader(objResponse.GetResponseStream())) { result = sr.ReadToEnd(); Helpers.LogProcessing("ProcessSavedCard- " + cardToken + "- request", result, false); // Close and clean up the StreamReader sr.Close(); } var doc = new XmlDocument(); doc.LoadXml(result); processingResults.ResultCode = doc.GetElementsByTagName("result")[0].InnerText; processingResults.AuthNumber = doc.GetElementsByTagName("authNumber")[0].InnerText; processingResults.CardToken = cardToken; processingResults.Last4Digits = cardToken.Substring(cardToken.Length - 4); processingResults.CardExpiration = doc.GetElementsByTagName("cardExpiration")[0].InnerText; processingResults.TransactionID = doc.GetElementsByTagName("tranId")[0].InnerText; return(processingResults); }