471,605 Members | 1,515 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,605 software developers and data experts.

Pay Pal - Using HttpWebRequest

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=" + "in**@myemailaccount.com");
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.

Feb 7 '06 #1
4 3401
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
-------------------------------------------------------

"Code Monkey" <dl********@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
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=" + "in**@myemailaccount.com");
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.

Feb 7 '06 #2
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

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Code Monkey" wrote:
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=" + "in**@myemailaccount.com");
postData += ("&item_name=" + "Test");
postData += ("¤cy_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.

Feb 7 '06 #3
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 += "&b**********@emailaccount.com";
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!

Feb 8 '06 #4
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
-------------------------------------------------------

"Code Monkey" <dl********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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 += "&b**********@emailaccount.com";
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!

Feb 8 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Gregory A Greenman | last post: by
1 post views Thread by Vasu | last post: by
16 posts views Thread by thomas peter | last post: by
5 posts views Thread by Dave | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by MichaelMortimer | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.