By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,813 Members | 1,257 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,813 IT Pros & Developers. It's quick & easy.

Post Data to PayPal from Code Behind

P: n/a
Hi, I'm trying to post data to PayPal for a shopping cart, basically I want
to replicate a form like the following, but create the variables dynamically
from code behind:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business"
value="se****@designerfotos.com">
<input type="hidden" name="item_name"
value="Aggregated items">
<input type="hidden" name="amount" value="3.00">
<input type="submit" value="PayPal">
</form>

How can I create the hidden input variables in a code behind file and have
the data posted to https://www.paypal.com/cgi-bin/webscr and the user
redirected to that site?

I'm using the .NET 2 framework, but I still can't figure this out.

The only way I've been able to get somewhere is to have a PayPalForm.aspx
file which is displayed in an iframe (inside a checkout user control), and
has the following code:

<form name="paypalform" id="paypalform"
action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<asp:PlaceHolder ID="pchMain" runat="server"></asp:PlaceHolder>
</form>

Then, in the PayPalForm.aspx.cs file, I can add the hidden input variables
to the placeholder.

The problem with this approach though, is I need to access other controls (a
radio button list) that are on the checkout.ascx file which the iframe sits
on.

So I have:

Checkout.ascx
Radio Button List
Iframe
PayPalForm.aspx

and I need to access the radio button list from within PayPalForm.aspx.cs

Does that make sense??!!

Oct 20 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Yourself,

You're on the right track. Rather than making a post to the paypal
script, you should put all your stuff in a querystring, redirect to
that URL. There are a few ways to integrate into paypal, you can either
use the my website to their website and back to mine (standard), or
call their web services from your website (pro/premium).

My guess is that you just need to package all of that stuff into the
query string and redirect the browser to the url.

ex:

https://www.paypal.com/cgi-bin/we***...ignerfotos.com...

Don't forget to check out the paypal sandbox for testing.

http://www.sandbox.paypal.com

Good luck!

~Brenton MCSD.NET

Yourself wrote:
Hi, I'm trying to post data to PayPal for a shopping cart, basically I want
to replicate a form like the following, but create the variables dynamically
from code behind:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business"
value="se****@designerfotos.com">
<input type="hidden" name="item_name"
value="Aggregated items">
<input type="hidden" name="amount" value="3.00">
<input type="submit" value="PayPal">
</form>

How can I create the hidden input variables in a code behind file and have
the data posted to https://www.paypal.com/cgi-bin/webscr and the user
redirected to that site?

I'm using the .NET 2 framework, but I still can't figure this out.

The only way I've been able to get somewhere is to have a PayPalForm.aspx
file which is displayed in an iframe (inside a checkout user control), and
has the following code:

<form name="paypalform" id="paypalform"
action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<asp:PlaceHolder ID="pchMain" runat="server"></asp:PlaceHolder>
</form>

Then, in the PayPalForm.aspx.cs file, I can add the hidden input variables
to the placeholder.

The problem with this approach though, is I need to access other controls (a
radio button list) that are on the checkout.ascx file which the iframe sits
on.

So I have:

Checkout.ascx
Radio Button List
Iframe
PayPalForm.aspx

and I need to access the radio button list from within PayPalForm.aspx.cs

Does that make sense??!!
Oct 20 '06 #2

P: n/a
Thanks for the tip, I had thought about using the querystring to pass the
data, but I was hoping to avoid it, as it makes it even easier to change the
prices etc.

Am I correct in thinking that there is no possible way of posting data to an
external URL from code behind AND redirecting the user?

If so, I think I will stick to my iframe technique, and work out a way of
getting data between the PayPalForm.aspx and the Checkout.ascx - possibly
using ViewState?
"Superman" <br*****@ungernet.comwrote in message
news:11**********************@m7g2000cwm.googlegro ups.com...
Yourself,

You're on the right track. Rather than making a post to the paypal
script, you should put all your stuff in a querystring, redirect to
that URL. There are a few ways to integrate into paypal, you can either
use the my website to their website and back to mine (standard), or
call their web services from your website (pro/premium).

My guess is that you just need to package all of that stuff into the
query string and redirect the browser to the url.

ex:

https://www.paypal.com/cgi-bin/we***...ignerfotos.com...

Don't forget to check out the paypal sandbox for testing.

http://www.sandbox.paypal.com

Good luck!

~Brenton MCSD.NET

Yourself wrote:
>Hi, I'm trying to post data to PayPal for a shopping cart, basically I
want
to replicate a form like the following, but create the variables
dynamically
from code behind:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business"
value="se****@designerfotos.com">
<input type="hidden" name="item_name"
value="Aggregated items">
<input type="hidden" name="amount" value="3.00">
<input type="submit" value="PayPal">
</form>

How can I create the hidden input variables in a code behind file and
have
the data posted to https://www.paypal.com/cgi-bin/webscr and the user
redirected to that site?

I'm using the .NET 2 framework, but I still can't figure this out.

The only way I've been able to get somewhere is to have a PayPalForm.aspx
file which is displayed in an iframe (inside a checkout user control),
and
has the following code:

<form name="paypalform" id="paypalform"
action="https://www.paypal.com/cgi-bin/webscr" method="post"
target="_top">
<asp:PlaceHolder ID="pchMain" runat="server"></asp:PlaceHolder>
</form>

Then, in the PayPalForm.aspx.cs file, I can add the hidden input
variables
to the placeholder.

The problem with this approach though, is I need to access other controls
(a
radio button list) that are on the checkout.ascx file which the iframe
sits
on.

So I have:

Checkout.ascx
Radio Button List
Iframe
PayPalForm.aspx

and I need to access the radio button list from within PayPalForm.aspx.cs

Does that make sense??!!

Oct 20 '06 #3

P: n/a

"Yourself" <in*****@email.addresswrote in message
news:J4******************@text.news.blueyonder.co. uk...
Hi, I'm trying to post data to PayPal for a shopping cart, basically I
want
to replicate a form like the following, but create the variables
dynamically
from code behind:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business"
value="se****@designerfotos.com">
<input type="hidden" name="item_name"
value="Aggregated items">
<input type="hidden" name="amount" value="3.00">
<input type="submit" value="PayPal">
</form>

How can I create the hidden input variables in a code behind file and have
the data posted to https://www.paypal.com/cgi-bin/webscr and the user
redirected to that site?

I'm using the .NET 2 framework, but I still can't figure this out.

The only way I've been able to get somewhere is to have a PayPalForm.aspx
file which is displayed in an iframe (inside a checkout user control), and
has the following code:

<form name="paypalform" id="paypalform"
action="https://www.paypal.com/cgi-bin/webscr" method="post"
target="_top">
<asp:PlaceHolder ID="pchMain" runat="server"></asp:PlaceHolder>
</form>

Then, in the PayPalForm.aspx.cs file, I can add the hidden input variables
to the placeholder.

The problem with this approach though, is I need to access other controls
(a
radio button list) that are on the checkout.ascx file which the iframe
sits
on.

So I have:

Checkout.ascx
Radio Button List
Iframe
PayPalForm.aspx

and I need to access the radio button list from within PayPalForm.aspx.cs

Does that make sense??!!
Here is how I do this.

I have a form which has the static data. I have a placeholder in the form. I
build the non-static form data using stringbuilder and add is using

Dim ctrl as control = Page.ParseControl(PayPalFormDataString)
plc1.controls.add(ctrl).

I have the form automatically submit when it is called using javascript. (I
also have a button appear for those that have it disabled).

Couple of caveats... you want to make sure the page is only called by a
valid checkout button click and not from someone just going to that page.
You also need to handle the broken back button issue .. I use a redirect,
and finally you don't want the page to cache locally. I use <%@ OutputCache
Location="None" VaryByParam="None" %>

I also have a javascript waiting progress bar to provide some motion while
the post is processing.

An alternative to all of this is paypal has some code to handle a lot of
this but I choose not to use.
Mike
Oct 20 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.