#ingeniousambivert-payment-links
1 messages · Page 1 of 1 (latest)
Single Page Application
Ah thanks
I am using MERN stack
Gotcha
So you want to embed the payment form in your SPA, correct? You don't want to involve a redirect?
The flow is kinda similar to the subscription flow where the user gets access based on the payment plan
But instead of a fixed products I need dynamic amounts
Embed payment or redirect, whichever is easier works for me
But it needs to track the payment status thats it. I need some kind of a webhook or something to let my app know the payment succeeded or failed
Sounds like you are looking for one-time payments
But you mentioned Subscriptions so wanted to clarify
I need it to be one timed
Not recurring
Got it
Last question
is it a set Price amount per quantity of your product?
Like is it $1 per x units?
Or is this literally a "the customer specifies whatever they want"
Ah, I mentioned subscription because I am aware of the flow for it I need something similar.
App creates customer -> customer pays -> App is notified of payment
Yep that makes sense
No its just 1 unit with every payment
So my app decides the amount depending on a few other parameters
So for instance we have an "adjustable quantity" feature which would allow the customer to specify the quantity of a Product, but that Product would be like $1 per unit, as opposed to the customer just inputting $33.44 as the amount they are paying.
So are you looking for the ability for them to specify an arbitrary amount, or are you trying to give them a base amount and they choose the quantity of that amount?
Actually the customer does not decide anything
Hrmm okay now I'm confused 😅
Hold on
Let's back up and have you write out the flow for me
Yes
And I'll recommend the best integration based on that
Sure. Just a min
So basically the customer signs up on my app and then they check a few boxes and depending on that my app decides the amount they pay (one unit only). So I can either embed the payment form in my app or I can redirect them to a stripe payment page. As long as I can track what customer paid what amount, either option is fine.
Gotcha that's much simpler then
I'd recommend using Stripe Checkout in that case. The general docs are here: https://stripe.com/docs/payments/checkout
It does involve a redirect but it is the simplest integration
And will handle everything you need.
You can take a look at our Quickstart here: https://stripe.com/docs/checkout/quickstart to demo it and to see a very basic integration.
Do I need to create products and prices for this ?
Essentially you will just create a Checkout Session based on what your customer selects on your app, then redirect the customer to that Session's URL when they hit your "checkout" button. Then you implement webhooks (https://stripe.com/docs/payments/checkout/fulfill-orders) for fulfillment.
I need something where I just enter an amount and some description and the customer pays for it
Yes you do, but you can also create Prices inline (via price_data) if you prefer: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data
Right, you can dictate the amount when you create the Session.
Okay, I was looking into paymentIntents and charges.
Yep you could go that route
But it is a higher integration burden
So really just a trade-off of what you want.
Can you please explain me in a nutshell the flow for checkout, charges, payment intents ?
Sure
Thank you so much
Checkout = you create Checkout Session to determine how much to charge the user, you redirect user to session URL, we handle everything on the redirect page, customer is redirected back to your page after successful payment, you listen for webhooks for fulfillment
Checkout Sessions create PaymentIntents and Charges
So those will still be involved
Using Elements = you create a PaymentIntent to determine how much to charge the user, you pass the PaymentIntent's client secret to your client, you render the Stripe Payment Element within your webpage using that client secret, customer enters payment details into the Payment Element, upon success you show a success message, you handle fulfillment with Webhooks.
That is the short of it
Oh, okay. Can I control the ttl for the checkout session ?
Also what exactly would I need to store in my db to determine the success or failure of the payment via webhooks ? customerId, anything else ? Also do I need to create products and prices for checkout sessions (I am a little confused about this) ? Because I just want my app to dynamically decide the amount for the checkout so creating product and prices would be an overhead for me every single time a customer decides to pay (since the amount will be dyanmic )
Yep you can expire Checkout Sessions. Minimum amount of time though is 30 mins. They auto expire in 24 hours.
Can I extend the ttl to say 7 days ?
You store whatever you want in your DB, really. You likely want to store the Customer, the PaymentIntent, and perhaps some sort of Order ID, which you could set as metadata.
No 24 hours max for a Checkout Session
You would have to create a new Session
You can handle Prices dynamically with Checkout
Basically you would just create one Product in your Dashboard and then set that Product each time on the Session. Then you dictate the amount of the Session dynamically by setting line_items.price_data.unit_amount: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data-unit_amount
Sure thing! Let us know if you run into any issues while integrating!