public static TransactionResponse GetTransactionResponseFromXml(string xml) { XmlRootAttribute xmlRoot = new XmlRootAttribute(); xmlRoot.ElementName = "RESPONSE"; XmlSerializer xmlSerializer = new XmlSerializer(typeof(TerminalTxnResponse), xmlRoot); TransactionResponse txnResponse = new TransactionResponse(); TerminalTxnResponse xmlTxnResponse = new TerminalTxnResponse(); using (var ms = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(xml ?? ""))) { xmlTxnResponse = (TerminalTxnResponse)xmlSerializer.Deserialize(ms); txnResponse = xmlTxnResponse.GetTransactionResponse(); } return(txnResponse); }
public TransactionResponse RunTerminalTransaction(string uri, double amount, CardTransactionType transactionType) { TransactionResponse response = new TransactionResponse(); string txnType = VelocityTransactionType.GetTranType(transactionType); string postDataXml = string.Format("<DETAIL><TRAN_TYPE>{0}</TRAN_TYPE><AMOUNT>{1}</AMOUNT></DETAIL>", txnType, amount.ToString()); HttpClientApi httpClientApi = new HttpClientApi(); string responseMessage = httpClientApi.ProcessTransaction(uri, postDataXml); if (httpClientApi.httpStatus == System.Net.HttpStatusCode.OK && httpClientApi.exceptionStatus == "NONE") { response = TerminalTxnResponse.GetTransactionResponseFromXml(responseMessage); } else { response.ErrorMessage = string.Format("Error processing {0} on device {1} : Result: {2} : Detail: {3}", txnType, uri, httpClientApi.statusCode, httpClientApi.exceptionData); response.IsError = true; } return(response); }