#imzikkado

1 messages · Page 1 of 1 (latest)

potent loomBOT
#

Hello! We'll be with you shortly. 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.

unborn sphinx
#

First where do you want to set the metadta? The PaymentIntent or the Customer?

bright saddle
#

I didn't find information on how to include the PaymentIntent in checkout.create, I even tried with ChatGPT, but it doesn't return functional codes (it must be because of the old api), I tried using the metadata in the customer, but it returns an empty {}

#
stripeRouter.post('/', async (req, res) => {

    if (!req.isAuthenticated())
        res.redirect('/auth')

    const customer = await stripe.customers.create({
        metadata: {
            userId: req.session.passport.user.id
        }
    })

    const session = await stripe.checkout.sessions.create({
        payment_method_types: ['card'],
        line_items: [
            {
                price_data: {
                    currency: "brl",
                    product_data: {
                        name: "RPSide - 1 Month",
                    },
                    unit_amount: 3000,
                },
                quantity: 1
            },
        ],
        payment_intent_data: {
            setup_future_usage: 'off_session'
        },
        customer: customer.id,
        mode: "payment",
        success_url: "http://localhost:8080/painel",
        cancel_url: "http://localhost:8080/planos"
    });


    res.json({ id: session.id });


});

unborn sphinx
#

What do you mean by returns empty

#

Anything in Stripe API is an object, and they have their own metadata

bright saddle
#

the metadata

unborn sphinx
#

ie. Customer can has its own metadata, same the PaymentIntent, and CheckoutSession

#

If you set metadata to the Customer, then it should have the metadata

bright saddle
#

I will perfom some test

#

Do you have any example code on how to include the paymentIntent in the checkout? I really have a problem with the payment system integration logic.

unborn sphinx
#

What do you mean by include?

bright saddle
#

I don't need to pass the PaymentIntent in checkout.session,create?

#

stripe.paymentIntents.create

#

example

#
const customer = await stripe.customers.create({
        metadata: {
            itemType: req.body.itemType,
            userId: req.session.passport.user.id
        }
    })


    


const session = await stripe.checkout.sessions.create({
        payment_method_types: ['card'],
        line_items: [
            {
                price_data: {
                    currency: "brl",
                    product_data: {
                        name: "RPSide - 1 Month",
                    },
                    unit_amount: 3000,
                },
                quantity: 1
            },
        ],
        payment_intent_data: {
            setup_future_usage: 'off_session'
        },
        customer: customer.id,
        mode: "payment",
        success_url: "http://localhost:8080/painel",
        cancel_url: "http://localhost:8080/planos"
    });

customer: customer.id = stripe.customers.create

unborn sphinx
#

No, Checkout Session will generate a PaymentIntent under the hood

bright saddle
#

? = stripe.paymentIntents.create

unborn sphinx
#

Please follow this guide for step by step introduction

bright saddle
#

so what is stripe.paymentIntents.create for?

#

Now I don't understand.

unborn sphinx
#

It's to create a standalone PaymentIntent. It's a different flow, to be used with Payment Element (not Checkout)

bright saddle
#

in a subscription system it would be useful then as there will not be items.