I am getting 400 Bad request when try to payment through the pay pal.
Here i got the transaction id but also i did not get the success response
How can i solve this error please me.
My code is:
public void Getresponse()
{
try
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
ServicePointManager.DefaultConnectionLimit = 9999;
string authToken = ConfigurationManager.AppSettings["PaypalToken"].ToString();
string txToken = Request.QueryString["tx"];
Label1.Text = txToken;
string query = "cmd=_notify-synch&tx=" + txToken + "&at=" + authToken;
int pid = Convert.ToInt32(Request.QueryString["Pid"]);
string strPaypalLive = ConfigurationManager.AppSettings["PaypalLive"].ToString();
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strPaypalLive);
var encoding = new UTF8Encoding();
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = query.Length;
StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
streamOut.Write(query);
streamOut.Close();
StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
string strResponse = streamIn.ReadToEnd();
streamIn.Close();
Dictionary<string, string> results = new Dictionary<string, string>();
Label3.Text = strResponse;
if (strResponse != "")
{
Label2.Text = strResponse;
StringReader reader = new StringReader(strResponse);
string line = reader.ReadLine();
if (line == "SUCCESS")
{
Label2.Text = "Inside Success !";
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "msg", "alert('Hello')", true);
using (OwlEducationEntities context = new OwlEducationEntities())
{
if (Request.QueryString["Custom"] != null)
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "msg", "alert("+txToken+")", true);
string QryString = Request.QueryString["Custom"].ToString();
GRI_Package pkg = (from t in context.GRI_Package where t.PackageID == 3 select t).SingleOrDefault();
pkg.TransectionID = txToken;
pkg.IsPaid = true;
context.SaveChanges();
}
}
}
else if (line == "FAIL")
{
Label3.Text = "Fail"+line;
}
}
else
{
Label3.Text = "Error";
Response.Write("ERROR");
}
}
catch (Exception Ex)
{
Label3.Text ="catch"+ Ex.Message;
Exceptions.LogException(Ex);
}
}
What I have tried:
i tried this code for getting response
StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
streamOut.Write(query);
streamOut.Close();
StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
string strResponse = streamIn.ReadToEnd();
streamIn.Close();