#nancy-e_code
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/1451271772287664320
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hi ๐
You can redisplay saved payment methods using the Stripe Payment Element as we document here.
You will need to also use a Customer Session https://docs.stripe.com/api/customer_sessions/object
Okay - so I can use the Payment Element with the SetupIntents API for new method creation, and for listing existing payment methods, I can generate a Customer Session and then use the secret on the client-side to generate the Payment Elements for display?
Correct. Specifically when you create your Stripe Elements instance useElements(), you will pass the customerSessionClientSecret in the options param: https://docs.stripe.com/js/elements_object/create#stripe_elements-options-customerSessionClientSecret
You need to make sure, when you create the Customer Session on your server, that you specify components.payment_element.features.payment_method_allow_redisplay_filters to unspecified. This will display saved payment methods even if the Payment Method was saved without a specific allow_redisplay value.
right right right okay
You can see an example of the API call to create the Customer Session here: https://docs.stripe.com/api/customer_sessions/create
Is it possible to use CheckoutSessions to create new PaymentMethods without a charge or particular purchase? That's the method Stripe staff gave my team, but I wasn't able to use the Payment Element with the secret I generated in creating the CheckoutSession
Sure, you would just use mode: "setup" when creating the Checkout Session. https://docs.stripe.com/api/checkout/sessions/create#create_checkout_session-mode
Oof I can't find my code I used to test that out. I did try that 2-3 times unsuccecssfully. That was recommended. I guess I can try again, but I have been able to do this with no trouble with SetupIntents. This is to support both on-session and off-session flows where the user might not be the customer themselves
Oh, wait. The user may not be the Customer? Yeah Checkout Sessions won't do that
Gotcha. There are a few application surfaces here. In the future there will be one where the user is the customer
So you create the Payment Method, without a Customer and then later attach it to the Customer?
No, so we find-or-create the Stripe customer on load of our internal user detail page, and then use the Payment Element on the client-side to create and attach the PaymentMethod in one fell swoop.
It's a little hand-wavy because I'm not sure how the context of the Stripe Customer ID comes into play with the client-side SDK
Well that would come in with the Customer Session object. To be 100% clear, we expect you to already know you are displaying saved payment methods to that specific Customer.
I'm sure you can understand customers might be a bit concerned if their saved payment methods were being displayed to people other than themselves.
Lol yeah absolutely. OH I see what you're saying. Then in my case, that's coming in with the SetupIntent session object currently
We pass the found-or-created Stripe Customer.id to the backend to generate the secret and then use the secret on the frontend to mount the Payment Element
Well, what I mean is that if you render the Payment Element with both a Setup Intent and Customer Session it would redisplay any saved payment methods for that Customer.
In that scenario, only the individual represented by the Customer should be interfacing with the Payment Element.
If you just use the Setup Intent, we don't redisplay saved payment methods
oooooooh gotcha
so Customer Session is what I should be looking into
that's very helpful
When you want to redisplay the saved PMs to the Customer, yes.
๐
And it's an option you can pass to Stripe Elements
Yeah we'll have application surfaces where the user is the customer and others where the user is doing things on behalf of the customer
Yeah, making sure you have those two user paths cleanly separated is, I think, the key to properly setting this up. Getting the Payment Element configured to redisplay saved PMs is just an extra API call and one new param when creating Stripe elements.
๐ okay. I'll do my best. how long will this thread exist for? This has been very helpful.
We close threads for inactivity but the actual thread itself is retained. You just won't be able to keep posting in it.
fyi i'm taking over for snufkin, feel free to let me know if you have any more questions in the near term!