truleighsyd
truleighsyd

Reputation: 301

How to allow users to enter custom amount vs charging set amount in stripe?

Thus far, I've only seen examples/tutorials for stripe in which you declare an amount via choosen library to charge customers/clients. How would you write code that allows the user to input custom amount for say a "pay bill" or "donation" form. Conceptually it seems this might be an if/else statement that sets a high/low parameter but I'm not entirely sure nor how to code this to work with Stripe API. Could really use some help here. Ultimate goal is to make a simple payment page that allows user to make a custom payment and then create a customer object to charge customer at a later date.

Upvotes: 3

Views: 1679

Answers (1)

Ywain
Ywain

Reputation: 17503

(I realize this is an older question, but I figure the information might be useful to some people.)

Here's a simple example of a Checkout custom integration where the user can specify the amount.

Of course, Checkout doesn't actually create the charge, it only returns a card token. The amount value passed in the handler.open() call is only used for display purposes.

Once the form is submitted, in your server-side code, you'd need to retrieve the value of the amount form field and convert it to cents before making the charge creation request.

Additionally, you should validate the amount both on the client side and server side, to make sure it's an actual number, superior to the minimum charge amount and inferior to a reasonable maximum.

Upvotes: 4

Related Questions