PC Review


Reply
Thread Tools Rating: Thread Rating: 9 votes, 4.56 average.

Post Data to PayPal from Code Behind

 
 
Yourself
Guest
Posts: n/a
 
      20th Oct 2006
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="(E-Mail Removed)">
<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??!!



 
Reply With Quote
 
 
 
 
Superman
Guest
Posts: n/a
 
      20th Oct 2006
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/websc...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="(E-Mail Removed)">
> <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??!!


 
Reply With Quote
 
 
 
 
Yourself
Guest
Posts: n/a
 
      20th Oct 2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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/websc...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="(E-Mail Removed)">
>> <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??!!

>



 
Reply With Quote
 
vMike
Guest
Posts: n/a
 
      20th Oct 2006

"Yourself" <(E-Mail Removed)> wrote in message
news:J46_g.38610$(E-Mail Removed)...
> 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="(E-Mail Removed)">
> <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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Phantom href code in paypal "add to cart" code Steve D. Microsoft Frontpage 2 18th Feb 2008 08:39 PM
Non-code behind to code behind John Microsoft ASP .NET 2 19th Feb 2007 08:08 PM
Code-Behind Pain in the Behind! Daniel Manes Microsoft ASP .NET 11 10th Jun 2005 10:47 PM
RE: How to access page code behind from User Control code behind Tian Min Huang Microsoft Dot NET 4 23rd Mar 2004 02:46 AM
Re: Code Behind vs. no code behind: error Ben Miller [msft] Microsoft ASP .NET 1 28th Jun 2003 02:46 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:23 PM.