#ben-hamilton_best-practices
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1433185779554844703
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- ben_customcheckout-bug, 5 days ago, 74 messages
- ben-hamilton_api, 5 days ago, 12 messages
The guide above seems to assume that you'll collect the user's email before creating the checkout session -> initializing Web Elements -> mounting the element(s)
Hi there
hello again!
My main confusion is how sites implement e.g. Express Checkout elements if you can't even display them before collecting the user's email and looking up / creating the Stripe Customer ID
We got added to the Private Preview for dynamically updating checkout sessions, but it only allows updating a very few things (line items, shipping info) and not customer ID
Hmm the email isn't required at time of Checkout Session creation so you could collect it and then update the Customer's email thereafter using https://docs.stripe.com/js/custom_checkout/update_email
Oh, super interesting โ that's only possible on the client side, not the server side?
I was looking at the Node.js server-side API to update a checkout session, not the Stripe.JS client-side API
No you could update server-side as well... you would just update the Customer directly for that: https://docs.stripe.com/api/customers/update#update_customer-email
Huh, I see
Does that suggest that for the subscription_data passed in during checkout session creation time:
https://docs.stripe.com/api/checkout/sessions/create#create_checkout_session-subscription_data
there's also a way to update that using some sort of subscription ID?
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
we wanted to be able to dynamically update the description in specific based on what the user enters
Yeah no that's not possible without creating a new Checkout Session. By description I assume you mean the description of the line items?
For the subscription_data.description you can't update that -- really after you create a Checkout Session itself you never update the Session.
You update the objects that have been generated.
So you would create a new Checkout Session if you wanted different subscription_data
Right. Our use-case is our product supports:
- The customer purchasing a subscription for themselves (the customer can have only 0 or 1 of these)
- The customer purchasing a subscription as a gift for someone else (the customer can have 0 or more of these)
We wanted to make sure the customer can distinguish the subscriptions in the Stripe Customer Portal, so we have two options, the line item or the description
The UI at https://plant.staging.terraformation.com allows toggling between these two modes, so we either have to juggle two checkout sessions for the two modes, or update one checkout session dynamically
Whenever we create a new checkout session, AFAIK we have to unmount the Web Elements UI and remount it, which causes a lot of pain if the user half-filled out their info
The easiest way imo is just to set the corresponding product descripitons used for the line items.
That requires the Private Preview API to dynamically update the line items, right?
No
oh! what'd I miss
The customer is selecting what subscription(s) to purchase and then you are rendering Payment Element, right?
I was hoping to render the Payment and Express Checkout elements immediately
most users are not going to select the gift checkout
Ah okay well we don't handle private features here as this is a public server so I can't really speak to that. But overall if you wanted to render Payment Element / ECE immediately then yes you would need to be able to update the line items.
Right. That's why I was asking about best practices. Do most Stripe customers delay rendering Payment Elements until after collecting the user's email and other product choices?
Generally yes. The most common flow is to have an email tied to a login/auth for your customer so you would already have that stored. And yes, generally you would wait to render Payment Element until the customer "views their cart" -- basically after they have selected what they are purchasing.
Sure thing