We help IT Professionals succeed at work.
Get Started

PayPal PDT integration ASP.NET

nedlogan asked
Last Modified: 2012-05-11
I'm going round in circles trying to integrate PayPal with my C# code. All I want to do is send the value of the shopping cart, e.g. £25.99 to paypal, have the client pay then send a response to PDT and update my database with SUCCESS, or FAIL response and return to my site.

I've set up Website Payments Standard code to send the form to paypal but nothing seems to be coming back to the PDT page in sandbox. There is so much documentation on the PayPal website that it I'm not sure where to look.

Does someone have some example code or know of a tutorial to get this done? It only needs to be really simple!

The code I tried to use is below, but I'm unsure where to go from here?
String strTransactionID = Request.QueryString["tx"].ToString();
    string sOut = "";
    string MyIDToken = "MyIdentityToken";
    string transactionID = Request.QueryString["tx"].ToString();
    string sCmd = "_notify-synch";
    string serverURL = "https: //www. paypal. com/cgi-bin/webscr";
        string strFormValues = Request.Form.ToString();
        string strPassValue;
        string strResponse;
        // Create the request back
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(serverURL);
        // Set values for the request back
        req.Method = "POST";
        req.ContentType = "application/x-www-form-urlencoded";
        //Append the transaction ID, ID Token, and command
        //to the form
        strPassValue = strFormValues + "&cmd = _notify-synch&at = " + MyIDToken + "&tx = " + transactionID;
        req.ContentLength = strPassValue.Length;
        // Write the request back IPN strings
        StreamWriter stOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
        // Do the request to PayPal and get the response
        StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream());
        strResponse = stIn.ReadToEnd();
        sOut = Server.UrlDecode(strResponse);
    catch (Exception x)

Open in new window

Watch Question
Top Expert 2011
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE