Pages

Showing posts with label Asp Dot Net Code Sample. Show all posts
Showing posts with label Asp Dot Net Code Sample. Show all posts

Thursday, March 25, 2010

Post data to another host specially to payment gateway (Authorize.net, blue fin payment gateway)

//Create an object of hash table
Hashtable post_values = new Hashtable();

//Add values in the hash table
post_values.Add("tran_type", "A");
post_values.Add("account_id",”AccountId”);

post_values.Add("pay_type", "C");

post_values.Add("card_cvv2",”cardCVV number”);

post_values.Add("card_number", “Card Number”);

post_values.Add("card_expire", “Card Expiry Date”);

post_values.Add("bill_name1,”Customer First Name”);

post_values.Add("bill_name2",”Customer Last Name”);

post_values.Add("bill_street, ”BillingAddress1”);

post_values.Add("bill_state", “bill_state”);



post_values.Add("bill_zip",” BillingZipCode”);



post_values.Add("bill_country", “bill_country”);

post_values.Add("amount,"totalorderamount");



// create an HttpWebRequest object to communicate with payment gateway site

HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(“PaymentGatewayURL”);



//Assign Methor by which request will be send

objRequest.Method = "POST";

objRequest.ContentLength = post_string.Length;

objRequest.ContentType = "application/x-www-form-urlencoded";

// post data is sent as a stream

StreamWriter myWriter = null;

myWriter = new StreamWriter(objRequest.GetRequestStream());

myWriter.Write(post_string);

myWriter.Close();



// returned values are returned as a stream, then read into a string

String post_response;

HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();

//Read response to the end response value will be stored in variable //post_response



using (StreamReader responseStream = new StreamReader(objResponse.GetResponseStream()))

{

post_response = responseStream.ReadToEnd();

responseStream.Close();

}