PDA

View Full Version : passing variables to paypal


sharktacos
7-1-05, 02:58 PM
The standard way to do paypal is to have "buy" button that you click on that takes you into the paypal secured site. I would like to instead have

1) the "buy" button take them to a new page on my site where they would be able to see the item they selected, choose quantities and have it calculate totals. Then when they click "next" to go to
2) another page where it would ask for shipping information. Then when they click on "next"
3) take them into paypal where it would populate all the stuff they had filled out (quantities, shipping, etc) from the previous pages and could complete the order.

So my question is, what would be the best way to go about that? Is there a way to store the variables so that it could collect them all on the various pages and then pass it all into paypal? Is this something I can do with the "make buttons" thingie in paypal?

thanks!

P.S. I'm not really thinking of doing this with osCommerce because it is way more complex than I want to get. I'm thinking more about just making my own stuff with (maybe) forms and java script.

stevel
7-1-05, 03:55 PM
PayPal has a shopping cart system you can try - it is more than a "buy" button. Read about it on their site.

sharktacos
7-1-05, 04:39 PM
hi Steve,

I think the problem with the paypal shopping cart is that if I had all my info on one page I could pass all the variables into paypal when people checked out. The problem is how to pass the variables from one page to the next (on my website) so I accumulate variables on different pages before I go to the paypal site.

I asked on paypaldev.org and they seemed to think that the paypal shopping cart couldn't do this (YMMV), so I was thinking about maybe doing it with forms to pass the variables, and java scripting for some basic math. But I wanted to run this all by you nice programmer types to see if that was a good approach since I've never done this before (had an online shop that is).

stevel
7-1-05, 06:06 PM
You typically would use a cookie to pass information from page to page, or you could use a PHP session with the session ID passed in a cookie or in the URL. This is how osCommerce does it.

sharktacos
7-1-05, 09:45 PM
could you point me to some examples of the code for this please?
I've never worked with cookies or PHP before.

I did find some stuff on doing this with Java Script but it was pretty complex. Would it be easier to do the way(s) you are recommending?

stevel
7-2-05, 10:08 AM
Pick up a book on PHP, such as "Programming PHP" from O'Reilly Press. You'll need more than just "code examples". I have seen shopping carts done with JavaScript and cookies - you can probably find examples somewhere.

If it were me, I'd just use one of the cart systems such as osCommerce or Zen Cart that had PayPal support and concentrate on my store rather than reinventing a cart.

bflores
7-15-05, 09:29 PM
In PHP, you can do this (and I've done so) using "hidden" fields in a form. The hidden fields from, say, Page 1 become part of $_POST on Page 2. Extract all fields from $_POST on Page 2, and then pass the ones you want using hidden fields to Page 3, etc, etc.

So... you have a form on Page 1 that asks for the user's phone number, and that field has a name of (cleverly) $phone. Since $phone is part of the array $_POST when the form is submitted, it is also available on page 2. Now, on page 2 you have a different form that asks for other things. But, you want to make sure page 3 know what's in $phone. Easy. As part of your form on page 2, include something like this prior to the Submit button:

<input type='hidden' name='phone' value=<? echo "$phone"; ?>>

Then, even though you don't have "phone" as part of your visible form on Page 2, it will still be posted to Page 3.

I use this method so that I can create a "review page" for the user before they press the "payment" button.

Dabrowski
7-15-05, 10:36 PM
Of course, at some point you'll have to worry about sensitive info, which you shouldn't pass through hidden form variables.

I agrees with Steve--don't reinvent the cart. Us osCommerce or something, and worry about the modifications there, and the store.

I was trying to reinvent the cart myself, but I ended up installing osC, and now I'm trying to reinvent the cart at my leisure:)