rdgd
rdgd

Reputation: 1446

Pre-populate Donation Amount on Website

What I want to accomplish is to have user enter an amount into text input on website, and when the paypal donate button is clicked, the payment form is pre-populated with the amount that they entered into the text input.

I have seen other posts which have answers that seem to have solved this problem in the past, but while trying to implement the same solution myself, I am unable to get it work... If this is do to a small ignorant oversight on my part, then I apologize in advance.

Here is the code snippet that I get from paypal when I choose a donate button type and select the option "Donors enter their own contribution amount"

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
    <input type="hidden" name="cmd" value="_s-xclick">
    <input type="hidden" name="hosted_button_id" value="XXXXXXXXXX">
    <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
    <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

Here is a post that has solved this issue for others: Paypal custom amount for "Donate Now" button

Following what that post has to say, I modified my paypal snippet thusly:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
    <input type="hidden" name="cmd" value="_s-xclick">
    <input type="text" name="amount" id="amount" value"">
    <input type="hidden" name="hosted_button_id" value="XXXXXXXXXXX">
    <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
    <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

So, I've just added <input type="text" name="amount" id="amount" value"">, which from what I understand should have allowed me to pass the value of my input to the payment form. This isn't working for some reason.

Help would be very much appreciated!

Upvotes: 0

Views: 934

Answers (1)

Drew Angell
Drew Angell

Reputation: 26056

You're using a hosted button, so you can't set the amount directly within the button code like that. If you want to do that you'll need to use an un-hosted button, which you can go by going into the button editor in PayPal and unchecking the "save button on PayPal" option. That said, you should be able to setup the donate button to let people enter the amount on the PayPal page rather than on your own page and passing it over, so you might want to look into that.

The downside to the non-hosted button is people can see the amount, your email address, etc. in the button code and they could potentially view source, copy the code, change the values, then load it up and pay you a lesser amount than they should for a product. Of course, hopefully you'd have procedures in place to catch this before shipping a product or providing access to a subscription only website, but it's just something you'd need to keep in mind.

Another option would be to switch to the Express Checkout API. This is basically the API version of standard buttons, but when using the API none of that code is actually seen in a browser so people can't try to mess with it.

Upvotes: 1

Related Questions