#when the imposter is sus เถž๐Ÿคฃ๐Ÿ‘Œ๐Ÿ‘Œ

1 messages ยท Page 1 of 1 (latest)

fickle belfryBOT
clever sand
#

Hi there!

rocky badger
#

hello : )

clever sand
#

can you share a PaymentIntent ID (pi_xxx) with this issue?

rocky badger
#

pi_3OKcwaFIVDvu8LCT1rvneaoS

#

i am using test mode btw

clever sand
#

the email is in billing_details.email

rocky badger
#

is the billing_details supposed to be a property of event.data.object?

clever sand
#

no directly. this is actually stored on the Charge object itself

#

so if you listen to payment_intent.succeeded, first you'll need to retrieve the associated Charge object

rocky badger
#

how do i retrieve that ?

clever sand
#

check the latest_charge property, it should contain the Charge ID

rocky badger
#

it does

clever sand
#

then retrieve the Charge with its ID

rocky badger
#

i just figured out another way, is it a common approach to do it like this?

import { stripe } from "@utils/stripe";
import type { NextApiRequest, NextApiResponse } from "next";

export default async function handler(
    req: NextApiRequest,
    res: NextApiResponse
) {
    try {
        const { priceId } = req.query;
        const session = await stripe.checkout.sessions.create({
            mode: "payment",
            payment_method_types: ["card"],
            line_items: [{ price: priceId as string, quantity: 1 }],
            success_url: "http://localhost:3000/payment-success",
            cancel_url: "http://localhost:3000/payment-canceled",
            payment_intent_data: { metadata: { email: "test@email.com" } },
        });

        res.send({ id: session.id });
    } catch (error) {
        console.log(error);
    }
}

#

i just found out that u can pass the payment_intent_data from here

clever sand
#

yes absolutely that works too!

rocky badger
#

thank you for you time ๐Ÿ™‚ is it okay if i ask another question here or do I have to make a sperate thread?

clever sand
#

sure, what's your question?

rocky badger
#

about the paymentIntent.customer

#

from what i understand i should link it to that user in the database on a successful purchase, correct?

clever sand
#

you mean in your own database? that's completely up to you

rocky badger
#

nvm, looks like i can achieve what i want without needing it, idk why the tutorial guy used it. I guess i gotta do more research before asking questions

#

thank you !

clever sand
#

Happy to help ๐Ÿ™‚

rocky badger
#

Hey you still here? ๐Ÿคฃ

clever sand
#

yes, how can I help?

rocky badger
#

The stripe customer id shouldn't change no matter how many transactions a user makes, right?

#

the paymentIntent.customer

clever sand
#

if you pass the same customer parameter when creating the Chekcout Session, then yes

fickle belfryBOT
jaunty crescent
#

๐Ÿ‘‹ taking over for my colleague. Let me know if there's any follow-up Qs I can answer!

rocky badger
#

yeah even I felt bad asking him all these questions.
I am listing for payment_intent.succeeded even type but the customer is null for some reason

jaunty crescent