Paypal: trying to pass an amount with a Donation button
Asked Answered
W

2

6

I have a Donate button set up for the user to enter the donation amount. I am trying to send an amount with the button. I can enter amount=1.00 in the Add Advanced Variables in the button setup - that works fine. However, I have had no success sending the amount as part of the URL. I have added the following line to the PayPal button form:

<input type="hidden" name="amount" value="9.99" />

but the amount field is blank when I get to PayPal. Any thoughts what I am doing wrong?

Wristwatch answered 2/8, 2013 at 21:14 Comment(3)
I don't believe you can. Here's a discussion about it: paypal-community.com/t5/Merchant-services-Archive/….Gladygladys
Thanks. It looks like Paypal is pretty buggy in this regard. At least I wasn't losing my mind.Wristwatch
Whoa, hold on. "It's not a bug, it's a feature!". I will clarify in my answer.Otherdirected
O
13

If you're creating a so called 'hosted button' (that is, a button where the button details are stored on the PayPal side), then the 'amount' POST parameter is ignored for requests to https://www.paypal.com/cgi-bin/webscr.
This is a security feature to prevent people from being able to manipulate the amount passed to PayPal for checkout.

You can identify whether you're using a hosted button by the following data;
Hosted buttons will have a value for cmd of _s-xclick and include the hosted_button_id parameter.

If this is the case, you cannot update the amount by passing in an extra amount POST parameter.

However, because you're dealing with donations and the amount is flexible by definition, you don't in fact need a 'hosted button'. In the button creation form, turn off 'Host button with PayPal', or write your own to point to PayPal.
If you do this, you can set the amount via the amount POST parameter.

For example, the below works fine;

<form method="POST" action="https://www.paypal.com/cgi-bin/webscr">
<input type="hidden" name="cmd" value="_donations">
<label for="amount">Amount: </label><input type="text" name="amount" value="">
<input type="submit" name="submit" value="Pay with PayPal">
</form>
Otherdirected answered 3/8, 2013 at 16:10 Comment(3)
thanks for the post, it cleared this issue up for me as well. One question: what did you mean by "write your own to point to PayPal"? I just want to be crystal clear about everything before I put a donate button up on my website. Also, to make sure there's a layer of security, should I use the Encrypted Website Payments feature if I'm not using a hosted button?Cavefish
You can create buttons via PayPal's 'Button Manager', or simply write the <form> element yourself. Either one is fine for donations. As for security; the security is generally intended to secure the amount paid and prevent anyone from tampering with that. That doesn't apply with a donation button (precisely because you want to allow people to modify the amount), so Encrypted Website Payments is not necessary for you.Otherdirected
This is not enough - you have to provide business and item_name. currency_code is also a good idea. See here for more details.Navarra
B
9

Robert's solution is on the right track, however a non-hosted PayPal form will not work without the hidden "business" field (which should have a value of the email address associated with your PayPal account.)

Other fields should be included for thoroughness:

<input type="hidden" name="business" value="[email protected]">
<input type="hidden" name="item_name" value="Donation Description">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="tax" value="0">
Bathtub answered 25/9, 2015 at 18:6 Comment(2)
PayPal also states you can also put your merchant ID in place of email for the business field. This helps avoid spammers from picking up your email address.Halleyhalli
If you want donors to be able to set up recurring donations, the amount field must be zero. If you specify any non-zero value, PayPal does not present donors with the option to set up recurring donations, and instead assumes the donor is making a one-time donation of the specified amount.Fumy

© 2022 - 2024 — McMap. All rights reserved.