#kenny_code

1 messages ยท Page 1 of 1 (latest)

celest perchBOT
#

๐Ÿ‘‹ 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/1361623775942017044

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

rough flume
#

there are a lot of limits to the text size i was allowed to send so if there's any other context I care share with you i'd be happy to

pale bronze
#

hi there!

rough flume
#

and they show up properly in my stripe dashboard

pale bronze
#

what's your end goal here? to show existing payment methods in the Checkout Session?

rough flume
#

My goal here is for my saved payment methods to be accessible when checking out using the payment element. I'm trying to access my saved payment methods directly from the checkout session to display them to the user but it's always returning null. I didn't follow all of the above steps mentioned as I don't currently collect billing addresses. Is that required for me to access payment methods using the payment element though?

#

As you can see from my screenshot fetching the payment methods from stripe is trivial but I thought it would be best practice to grab the payment methods directly from the checkout session hook when a user is making a payment

pale bronze
#

so you managed to save the payment methods, but the issue is to redisplay them in the Payment Element?

rough flume
#

yes, exactly. they're saved in stripe as you see in both of my screenshots

pale bronze
rough flume
#

I haven't seen this one before but looking at the implementation it's pretty much the same as what I did

#

Maybe because this is a payment for a subscription I need to save them as off_session for them to be picked up by the payment element?

pale bronze
celest perchBOT
rough flume
#
    const intent = await stripe.setupIntents.create({
        automatic_payment_methods: {
            enabled: true,
        },
        customer: orgExt.customerId,
        usage: "off_session",
    });

    const customerSession = await stripe.customerSessions.create({
        customer: orgExt.customerId,
        components: {
            payment_element: {
                enabled: true,
                features: {
                    payment_method_redisplay: "enabled",
                    payment_method_save: "enabled",
                    payment_method_save_usage: "on_session",
                    payment_method_remove: "enabled",
                },
            },
        },
    });

    return {
        clientSecret: intent.client_secret,
        customerSessionClientSecret: customerSession.client_secret,
    };
pale bronze
#

can you share the PaymentMethod ID (pm_xxx) so I can check myself?

rough flume
#

I just realized in the doc you sent me i'm only using setupIntents for the payment method collection and the checkout session for payment elements when your guide seems to use setupIntent for both. Do I need to change to that?

#

mastercard: pm_1RE4hHCWRQ9TqHkCv3b0BUrW
visa: pm_1RE4fhCWRQ9TqHkCThJf8oij

pale bronze
#

they have allow_redisplay: "limited"

#

so you need to update it to always.

rough flume
#

okay so change payment_method_redisplay: "enabled", to payment_method_redisplay: "always",?

#

oh it only allows enabled or disabled

pale bronze
#

no

#

I'm talking about the PaymentMethod object itself

rough flume
#

Yeah I get that but wouldn't that value be controlled by creating the intents?

#

Or would I just hit the stripe api to change it from limited to always after stripe saves it

pliant rock
rough flume
#

okay and will this only work with the setupIntent flow or does it also work with the checkout session flow as well?

#

bc now that i made it always this shows up when I add a payment method but it still looks like this on my checkout session payment element

pliant rock
#

Could you please share the CheckoutSession ID/URL?

rough flume
#

absolutely

#

cs_test_a1k127MEXjkmOn4ankobcLecPehKI1aQrAXaYmoYufJfG5S3k9MQi98rqW

pliant rock
#
saved_payment_method_options: {
    payment_method_save: "enabled",
  },

This allows you to save PMs, not show saved PMs.

#

Hmmm, actually, you shouldn't need to provide any parameters to show saved PMs.
Let me check...

#

Which of the screenshot shows the Checkout Session?

rough flume
#

the one without the payment methods

pliant rock
#

I see that the Checkout Session you shared is of ui_mode=custom

rough flume
#

yes

#

i'm using the payment element

pliant rock
rough flume
rough flume
#

i don't really understand the difference between the two of these

rough flume
# pliant rock Are you creating a Customer Session? <https://docs.stripe.com/payments/existing-...

I'm creating this:

            const session = await stripe.checkout.sessions.create({
                ui_mode: "custom",
                line_items: [
                    {
                        price: formData.price,
                        quantity: formData.quantity,
                    },
                ],
                mode: formData.mode,
                return_url: `${BASE_URL}${href("/:orgSlug?")}?session_id={CHECKOUT_SESSION_ID}`,
                automatic_tax: { enabled: false },
                customer: orgExt.customerId,
                saved_payment_method_options: {
                    payment_method_save: "enabled",
                },
            });
pliant rock
#

What do you want to achieve exactly?
There's multiple choices of how to handle this on the backend and frontend.

rough flume
#

will payment intents and customer session approach work with subscriptions?

pliant rock
rough flume
#

no clue, i'll give it a look

pliant rock
rough flume
#

gotcha, i'll give the embedded component a shot. One last question before you go on my add payment form the only way it becomes "always" and not limited is if they press Save payment details to firestorm for future purchases. This isn't for future purchases it's for them to add their own payment methods meaning this should be removed and just always by default. How can I do that?

#

this is my stripe backend code for that:

    const intent = await stripe.setupIntents.create({
        automatic_payment_methods: {
            enabled: true,
        },
        customer: orgExt.customerId,
        usage: "off_session",
    });

    const customerSession = await stripe.customerSessions.create({
        customer: orgExt.customerId,
        components: {
            payment_element: {
                enabled: true,
                features: {
                    payment_method_redisplay: "enabled",
                    payment_method_save: "enabled",
                    payment_method_save_usage: "on_session",
                    payment_method_remove: "enabled",
                },
            },
        },
    });
pliant rock
#

You mean remove the disclaimer text at the bottom?

#

If you're not planning to use the PaymentMethod off-session, you could set usage="on_session". But if you want to be able to create a Subscription with this PM without bringing the customer on-session with Payment Element - the legal text is required.

rough flume
#

no, not the legal text I mean the "Save payment details to firestorm for future purchases" thing they have to click for it to be saved

#

cuz if they don't click that checkbox then it's saved as limited

#

not always

celest perchBOT
pliant rock
#

I am not sure I am following. It must be saved with allow_redisplay=always that way.

rough flume
#

yes, I want to save it but I want to set allow_redisplay=always without having to call the stripe api after already creating the payment method

devout knoll
#

๐Ÿ‘‹ taking over for my colleague. Let me catch up.

rough flume
#

can i modify something in the backend code I sent above so that it will set allow_redisplay=always by default?

devout knoll
#

unfortunately this needs to be done after you save the payment details

rough flume
#

okay, instead of setting it to always can I make it so that the element will show limited cards?

devout knoll
#

if the customer checks the box to save for future payments then allow_redisplay would be saved as always