hi i am trying to integrate paypal to my asp.net application .I am new to this type of payment gateways. But, i had created the Sandbox accounts and every thing in sandbox is working fine.
I am sending the required values to the sandbox.paypal.com and there the traction is ok.
But , i am getting failure response when it come backs to my application and i am using PDT way of response .
and i am not getting the transaaction id (tx) from paypal.
Can anyone have an idea of over coming this issue.
Thanks in advance.........
I am using the following code
Values sent to paypal link
string redirectUrl = "";
redirectUrl += "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_xclick&business=" + ConfigurationManager.AppSettings["PayPalEmail"].ToString();
redirectUrl += "&first_name" + CommonHelper.FirstName;
redirectUrl += "&item_name= Credits";
redirectUrl += "&amount=" + lblPrice.Text;
redirectUrl += "¤cy_code=GBP";
redirectUrl += "&quantity=1";
redirectUrl += "&return=" + ConfigurationManager.AppSettings["SuccessURL"].ToString();
redirectUrl += "&cancel_return=" + ConfigurationManager.AppSettings["FailedURL"].ToString();
Response.Redirect(redirectUrl);
}
response comes to this page
paypalresponse.aspx
public partial class HandlePayPalResponse : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string authToken = ConfigurationManager.AppSettings["token"];
//read in txn token from querystring
string txToken = Request.QueryString.Get("tx");
string query = string.Format("cmd=_notify-synch&tx={0}&at={1}",
txToken, authToken);
// Create the request back
string url = ConfigurationManager.AppSettings["PayPalSubmitUrl"];
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
// Set values for the request back
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = query.Length;
// Write the request back IPN strings
StreamWriter stOut = new StreamWriter(req.GetRequestStream(),
System.Text.Encoding.ASCII);
stOut.Write(query);
stOut.Close();
// Do the request to PayPal and get the response
StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream());
string strResponse = stIn.ReadToEnd();
stIn.Close();
// sanity check
Label2.Text = strResponse;
// If response was SUCCESS, parse response string and output details
if (strResponse.StartsWith("SUCCESS"))
{
Paypal pdt = Paypal.Parse(strResponse);
Label1.Text =
string.Format("Thank you {0} {1} [{2}] for your payment of {3} {4}!",
pdt.PayerFirstName, pdt.PayerLastName,
pdt.PayerEmail, pdt.GrossTotal, pdt.Currency);
}
else
{
Label1.Text = "Oooops, something went wrong...";
}
}
web.config settings
<add key="token" value="ELtdsUBCPOulCijrkzz1cKXuXU9a23C1WJH4U3iNoiIhsGoPbUwVYfJeCaFl">;
<add key="PayPalEmail" value="test.merchant@gmail.com">
<add key="paypalsubmiturl" value="http://localhost/mysite.webapp/paypal.aspx">
<add key="successurl" value="http://localhost/mysite.webapp/paypal1.aspx">
<add key="failureurl" value="http://localhost/mysite.webapp/paypal2.aspx">