Skip to content Skip to sidebar Skip to footer

How To Create An Paypal Button With Overwritable Variables

Hello I would like to create a paypal buy button which has a dynamic set amount. I would like to pass the amount by a text input field within the form and the item_number by a hid

Solution 1:

The reason you can't override the amount dynamically, is because you have a so-called 'PayPal hosted button'. With a hosted button, the amount is stored on PayPal's side and can't be overwritten with the 'amount' variable. You'll either want to use a non-hosted button, or use the BMUpdateButton API call to dynamically update the button's amount. To use a non-hosted button, simply find 'Step 2' in the button creation tool and untick 'Host button with PayPal'.

Option 2: Still use the hosted button, and use the BMUpdateButton API to update the amount. An example request for BMUpdateButton would look as follows:

USER=Your API username
PWD=Your API password
SIGNATURE=Your API signature
VERSION=82.0HOSTEDUBTTONID=The value of <input type="hidden" name="hosted_button_id" value="">
BUTTONTYPE=The type of button. E.g. BUYNOW
BUTTONCODE=The type of code you want to get back. E.g. HOSTED
L_BUTTONVAR0=amount=The new amount with a period as separator
L_BUTTONVAR1=item_name=Optional: a new item name if you wish

Similary, you could also use the BMCreateButton API to create a new button, or use the BMButtonSearch API to search through a list of all your stored hosted buttons (to find the hosted_button_id of your button automatically, for example)

The reason to use a hosted button is because it's more secure. A non-hosted, unencrypted button would basically leave the amounts open to manipulation. Fraudulent transactions waiting to happen.

Solution 2:

you shouldn't use xclick which isn't encrypted . the way I solved this is using paypal button api - with some kind of caching in the client so you won't do the whole http request response every time.

note that paypal uses 2 types of api - the NVP which is sort of restful (also not really) and SOAP (I used the NVP method)

you could also generate the the encrypted button in your server using openssl - but I run into unsolvable problems with this method and couldn't get any help for that either here or in paypal horrible developer forums

edit: the problem with not encrypted buttons are that anyone using firebug (not talking about more advanced tools) could interecept a payment and change the cost etc'..

If you insist in that direction you could follow the simple html form from paypal to create this button. you do it in paypal site and create an unencrypted button and then just edit the html and change the needed field to <?php $variable?>. I would strongly advice against this path.

Solution 3:

I think this might work for you if you update ... "you@yoursite.com" ... it's non encrypted and still seems to host on paypal's site for clearing

drop the: value="my_default_price" if you want the user to enter it into a blank text box ... for my page, prices are tied to the price of gold, so I have to dynamically update the variable "amount" and i just leave off value=

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<inputtype="hidden" name="cmd" value="_xclick">
<inputtype="hidden" name="business" value="you@yoursite.com">
<inputtype="hidden" name="item_name" value="example description">
<inputtype="hidden" name="item_number" value="">
<inputtype="text" name="amount" value="my_default_price">
<inputtype="hidden" name="no_shipping" value="1">
<inputtype="hidden" name="return" value="http://www.yoursite.com/returnpage.php">
<inputtype="hidden" name="currency_code" value="USD">
<inputtype="hidden" name="lc" value="US">
<inputtype="hidden" name="bn" value="PP-BuyNowBF">
<inputtype="image" src="https://www.paypal.com/en_US/i/btn/x-click-but02.gif" border="0" name="submit" alt="Make your payments with PayPal. It is free, secure, effective.">
<img alt="" border="0" src="https://www.paypal.com/it_IT/i/scr/pixel.gif" width="1" height="1">
</form>

Post a Comment for "How To Create An Paypal Button With Overwritable Variables"