Showing results for 
Search instead for 
Did you mean: 

When the trans is declined, need to capture error message and return either true or false

I am new to 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 = "";


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
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());

// 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();



I took this from the demo AIM project that sendbox is offering. But, I cant really understand and capture the respone message.  


Thank you.