I am new to authorize.net I need to run a transction and if there is an error, I need to capture it to a string then i need to return false. Can anyone share with me their thoughts on this?
This is what I currently have:
public bool ProccesPayment()
{
String post_url = "https://test.authorize.net/gateway/transact.dll";
string amount = paymentInfo.AmountPaid.ToString();
string cardNo = paymentInfo.CardNumber.ToString();
string expDate = paymentInfo.CardExpirationDate.ToString();
Dictionary<string, string> post_values = new Dictionary<string, string>();
post_values.Add("x_login", "xxxxxxxxxx");
post_values.Add("x_tran_key", "xxxxxxxxxxx");
post_values.Add("x_delim_data", "TRUE");
post_values.Add("x_delim_char", "|");
post_values.Add("x_relay_response", "FALSE");
post_values.Add("x_currency_code", "USD");
post_values.Add("x_type", "AUTH_CAPTURE");
post_values.Add("x_method", "CC");
post_values.Add("x_card_num", cardNo);
post_values.Add("x_exp_date", expDate);
post_values.Add("x_amount", amount);
post_values.Add("x_description", "McMahon Publishing Group subsription");
String post_string = "";
foreach (KeyValuePair<string, string> post_value in post_values)
{
post_string += post_value.Key + "=" + HttpUtility.UrlEncode(post_value.Value) + "&";
}
post_string = post_string.TrimEnd('&');
// create an HttpWebRequest object to communicate with Authorize.net
HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(post_url);
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();
using (StreamReader responseStream = new StreamReader(objResponse.GetResponseStream()))
{
post_response = responseStream.ReadToEnd();
responseStream.Close();
}
}
I took this from the demo AIM project that sendbox is offering. But, I cant really understand and capture the respone message.
06-29-2015 09:43 AM - edited 06-29-2015 09:47 AM
here is the AIM response doc
06-29-2015 10:59 AM
Thank you.
06-29-2015 11:41 AM