/*THIS METHOD extract values from string*/ public PaymentXML parseXMLString(string xml) { PaymentXML xmlObj = new PaymentXML(); xmlObj.firstName = getProperty(xml, "CLIENTFIRSTNAME"); xmlObj.lastName = getProperty(xml, "CLIENTLASTNAME"); xmlObj.email = getProperty(xml, "EMAIL"); xmlObj.line1 = getProperty(xml, "ADDR1"); xmlObj.line2 = getProperty(xml, "ADDR2"); xmlObj.city = getProperty(xml, "CITY"); xmlObj.zipCode = getProperty(xml, "ZIPCODE"); xmlObj.phone = getProperty(xml, "TELEPHONE"); xmlObj.quantity = getProperty(xml, "QUANTITY"); xmlObj.IP = getProperty(xml, "IP"); return xmlObj; }
// Method used for generate a string need by securesystem with payment Information public string creatXML(PaymentXML payment) { string xml = "<VERSION>" + version + "</VERSION>\n" + "<AUTHORIZATIONID>" + athorizationID + "</AUTHORIZATIONID>\n" + "<CLIENTFIRSTNAME>" + payment.firstName + "</CLIENTFIRSTNAME>\n" + "<CLIENTLASTNAME>" + payment.lastName + "</CLIENTLASTNAME>\n" + "<EMAIL>" + payment.email + "</EMAIL>\n" + "<ADDR1>" + payment.line1 + "</ADDR1>\n" + "<ADDR2>" + payment.line2 + "</ADDR2>\n" + "<CITY>" + payment.city + "</CITY>\n" + "<ZIPCODE>" + payment.zipCode + "</ZIPCODE>\n" + "<TELEPHONE>" + payment.phone + "</TELEPHONE>\n" + "<QUANTITY>" + payment.quantity + "</QUANTITY>\n" + "<IP>" + payment.IP + "</IP>\n" + "<PRODUCTID>" + payment.productID + "</PRODUCTID>\n"; return xml; }
public xmlTransacctionID MakeWebServiceCall(PaymentXML payment) { // this is what we are sending //string post_data = "foo=bar&baz=oof"; string post_data = "xml=" + creatXML(payment); // this is where we will send it //http://secure2.uprm.edu/secure/inittrans.php string uri = "https://secure2.uprm.edu/secure/inttrans.php"; // create a request HttpWebRequest request = (HttpWebRequest) WebRequest.Create(uri); request.KeepAlive = false; request.ProtocolVersion = HttpVersion.Version10; request.Method = "POST"; // turn our request string into a byte stream byte[] postBytes = Encoding.UTF8.GetBytes(post_data); // this is important - make sure you specify type this way request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = postBytes.Length; Stream requestStream = request.GetRequestStream(); // now send it requestStream.Write(postBytes, 0, postBytes.Length); requestStream.Close(); // grab te response and print it out to the console along with the status code HttpWebResponse response = (HttpWebResponse)request.GetResponse(); // if (((HttpWebResponse)response).StatusCode != HttpStatusCode.OK) StreamReader reader = new StreamReader(response.GetResponseStream()); // Read the whole contents and return as a string string responseStr = reader.ReadToEnd(); xmlTransacctionID xmlTransaction = parseXMLTransacctionID(responseStr); reader.Close(); response.Close(); return xmlTransaction; }