473,395 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 3485
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Gregory A Greenman | last post by:
I'm trying to write a program in vb.net to automate filling out a series of forms on a website. There are three forms I need to fill out in sequence. The first one is urlencoded. My program is...
0
by: Cenray | last post by:
How to generate a web request from a Winform Application using a WebService? In a C# Windows Application, when I try to genrate a web request using the following code, it is woking fine ...
1
by: Vasu | last post by:
Hi, I have a requirement to download a file from the web site using a client tool. Iam writing a C# program to download using WebRequest, HttpRequest, WebResponse and so on. The problem...
16
by: thomas peter | last post by:
I am building a precache engine... one that request over 100 pages on an remote server to cache them remotely... can i use the HttpWebRequest and WebResponse classes for this? or must i use the...
4
by: Steven Pu | last post by:
Hi, Specifically, the website I am trying to access is, https://gmail.google.com/ I've read elsewhere that Google only uses SSL2, while .NET uses SSL3 and is not backward compatible. Is...
0
by: Subra Mallampalli | last post by:
Hi, I am trying to connect over HTTPS using a client certificate. I am able to connect fine when using IE. From my application, however, I get the following error: The underlying connection...
7
by: | last post by:
Hello, I would like to do the following from a asp.net button click: <form method="POST" action="https://www.1234.com/trans_center/gateway/direct.cgi"> <input type="hidden" name="Merchant"...
5
by: | last post by:
Hi all, HttpWebRequest, and SoapHttpClientProtocol both expose a ClientCertificates property, which can hold multiple client certificates, but on the service side, it can only receive one client...
2
by: STEVE.KING | last post by:
Greetings: I need to download an executable and some other binary files (a C++ DLL) from a virtual directory in my WinForms application. No-Touch Deployment manages my .NET code fine but...
5
by: Dave | last post by:
What is the benefit of using "as" vs the other? HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("http://www.contoso.com/"); vs. HttpWebRequest myReq...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.