Pay Pal - Using HttpWebRequest

C

Code Monkey

I want to use Pay Pal in my web site.

What I want to do is attach the following code to a button

<code>
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "cmd=" + "business";
postData += ("&business=" + "(e-mail address removed)");
postData += ("&item_name=" + "Test");
postData += ("&currency_code=" + "GBP");
postData += ("&amount=" + "0.00");
postData += ("&return=" +
"http://www.myserver.com/paymentReceived.aspx");
postData += ("&rm=" + "2");
byte[] data = encoding.GetBytes(postData);
// Prepare web request...
HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create("https://www.paypal.com/cgi-bin/webscr");
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
// Send the data.
newStream.Write(data, 0, data.Length);
newStream.Close();
<code/>

Whilst this should (in theory at least) work, I'm not getting any
response from the Stream, ie; the Pay Pal website is not displayed.

I've tried using the Component One Pay Pal component, but the URL is
liable to get played - bad idea!

Can any one help?

Thanks in advance.
 
A

Alvin Bruney - ASP.NET MVP

paypal has licensing regulations that you need to be concerned about before
going this route. I suggest you speak with their support dept. first.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
 
G

Guest

Code Monkey,
Paypal has a developer section of their site that highlights plenty of
sample code, including for ASP.NET. I'd take a look there first.
Peter
 
C

Code Monkey

Thanks for all the MVPs' non-help - god help my flamed ass now! But I
fully appreciate what could potentially happen.

<code>
string formPostData = "cmd=_xclick";
formPostData += "&[email protected]";
formPostData += "&item_name=Test";
formPostData += "&quantity=1";
formPostData += "&currency_code=GBP";
formPostData += "&amount=0.01";
formPostData += "&return=http://myserver.com/paymentOK.aspx";
formPostData += "&rm=2";
formPostData += "&no_shipping=1"; //turns off shipping
information
formPostData += "&cs=0";

WebClient client = new WebClient();
client.Headers.Add("Content-Type",
"application/x-www-form-urlencoded");
byte[] postByteArray = Encoding.ASCII.GetBytes(formPostData);
byte[] responseArray =
client.UploadData("https://www.paypal.com/cgi-bin/webscr", "POST",
postByteArray);
string response = Encoding.UTF8.GetString(responseArray);

Response.Write(response);

</code>

That works OK. From there on, the customer logs in, and any further
user interaction is done under SSL on the PayPal site. Maybe I should
have explained what I was trying to do first of all!
 
A

Alvin Bruney - ASP.NET MVP

That wasn't a flame fyi.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top