Avatar of nedlogan
nedloganFlag for United Kingdom of Great Britain and Northern Ireland

asked on 

PayPal PDT integration ASP.NET

Hi,
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";
    try
    {
        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);
        stOut.Write(strPassValue);
        stOut.Close();
        // Do the request to PayPal and get the response
        StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream());
        strResponse = stIn.ReadToEnd();
        stIn.Close();
        sOut = Server.UrlDecode(strResponse);
    }
    catch (Exception x)
    {
    }

Open in new window


Thanks,
NL
ASP.NETWeb Development

Avatar of undefined
Last Comment
nedlogan
Avatar of dj_alik
dj_alik

I found some problem in
string serverURL = "https: //www. paypal. com/cgi-bin/webscr";
remove space between https: and //
ASKER CERTIFIED SOLUTION
Avatar of dj_alik
dj_alik

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of nedlogan
nedlogan
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

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?
Avatar of nedlogan
nedlogan
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Never mind I found the other part of the puzzle here:
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_admin_IPNIntro#id091F0M006Y4

Further to my earlier post it should always be SUCCESS.

Thanks for the push.
Avatar of nedlogan
nedlogan
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Thanks for your help.
ASP.NET
ASP.NET

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

128K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo