PayPal PDT integration ASP.NET

nedlogan used Ask the Experts™
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

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2011

I found some problem in
string serverURL = "https: //www. paypal. com/cgi-bin/webscr";
remove space between https: and //
Top Expert 2011
also additional spaces in URL
Instant Payment Notification - Code Samples


Thanks for your response.
I tried the IPN code you linked to yet regardless of the response I send from the sandbox ipn tester interperates it as SUCCESS?

Any ideas?


Never mind I found the other part of the puzzle here:

Further to my earlier post it should always be SUCCESS.

Thanks for the push.


Thanks for your help.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial