Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stripe donation payment link: how to initialize the amount from URL or javascript?

for a website allowing visitors to donate money, it looks like the easiest approach is to use Stripe payment links, with the option to let people choose what to pay: the amount can be freely entered by the user.

However, I would like to initialize that amount field with a specific value, actually computed from the values entered on other parts of the web page. To be more specific, the user would specify a donation A and a donation B, thus the Stripe payment link should be initialized with an amount equal to A+B.

And ideally, I would also like to make the amount field read-only, so that it cannot be modified to something else than A+B.

I see that the amount can be predefined when creating the payment link, but this is not what I want, because the amount will be different for any users.

I also see that the payment link can accept query parameters such as the user email or UTM data, but I cannot find anything for the amount.

Could you please let me know if this is possible, and how?

Otherwise, what would you recommend?

Many thanks!

like image 714
bfredo123 Avatar asked Sep 20 '25 08:09

bfredo123


2 Answers

I discovered playing with the "Buy Button" widget that you can use the __prefilled_amount query parameter. E.g. https://donate.stripe.com/mYDoNaTiOnId?__prefilled_amount=1500 will set it to $15 if the currency is USD.

like image 114
Trevor Dixon Avatar answered Sep 23 '25 12:09

Trevor Dixon


It is not currently possible to pre-fill the amount on a custom amount Payment Link via URL parameters. The only way to do this currently is by setting the preset parameter on the Price object used by the Payment Link. Equally, it's not possible to disable the field or make it read-only on the payment page.

If you require control over the donation amount on a per payment basis, I'd recommend looking at using Checkout with inline prices. You can capture the donation amount(s) from your customers, and trigger a session creation using the price_data parameter. Using that approach, the amounts are not editable by your customers on the Stripe payment page.

like image 38
Jonathan Steele Avatar answered Sep 23 '25 11:09

Jonathan Steele



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!