Click here to Skip to main content
15,891,837 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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

C#
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 += "&currency_code=GBP";
                //redirectUrl += "&tax=" + lblVatPRice.Text;
                redirectUrl += "&quantity=1";

                redirectUrl += "&return=" + ConfigurationManager.AppSettings["SuccessURL"].ToString();
                redirectUrl += "&cancel_return=" + ConfigurationManager.AppSettings["FailedURL"].ToString();
                //redirectUrl += "&notify_url=" + ConfigurationManager.AppSettings["NotifyURL"].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">
Posted

1 solution

Never, ever, accept code from a insecure website to handle anything to do with real money.
You do not know who is giving you the code, you do not know what it does, you do not know that it places the monies correctly into the appropriate account, without passing the details to any third parties.

Only get such code from Paypal themselves - the scope for fraud otherwise is far too large. And remember, you personally could be liable for any monies lost if your action is seen to be negligent - which getting your code from a public forum would most certainly be!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900