Prefilled amount for Stripe Checkout


Here’s the use case:
My users can decide what amount they want to donate.
They fill out the amount on a page in an input field then they press the “donate” button.

This action triggers a an API workflow to create a new checkout.session in Stripe (which I have built with the API Connector). The product in Stripe that is called up is set up with the “customer chooses price” setting, so that technically any value can be paid.
I can then redirect the user to the checkout URL.

However I can’t figure out how to set the amount that should be “prefilled” in the checkout window. It just defaults back to 0.
Do you know how to send an amount via API connector to be prefilled into the stripe checkout?

I tried setting the “amount_total”, “amount_subtotal”, but neither let me set a value.

I’m also open to other solutions.
Here’s what I tried and didn’t succeed with.

The standard Stripe plugin is not ideal, because it doesn’t give me access to all payment methods (e.g. Cash App Pay), nor can I customize the button in the checkout to say “donate”.

Just using the “Buy Button” solves the prefilled issue, but I can’t include some other important custom data.

That’s why I ended up building my own API Call.

You need to fill in the line_items[price] parameter with an id of a price object in Stripe, which is not appropriate for your use case.

Instead you should be configuring this API call to use the Child attributes of the line items to create the price object in stripe as well as the amount at the same time.

Look at stripe documentation for child attributes of the line_items or maybe just price.

Sure enough, this worked.
I created a separate call to create the price instead of using child attributes, simply because it fit well into the whole process I had set up. Thank you!

It’s of course kind of chaotic to have constantly new prices being created, so I’ll look into eventually moving away from that, but for now, this gets the job done.

Not another way when prices are dynamic.

This topic was automatically closed after 70 days. New replies are no longer allowed.