#when the imposter is sus เถ๐คฃ๐๐
1 messages ยท Page 1 of 1 (latest)
Hi there!
hello : )
can you share a PaymentIntent ID (pi_xxx) with this issue?
the email is in billing_details.email
is the billing_details supposed to be a property of event.data.object?
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
how do i retrieve that ?
check the latest_charge property, it should contain the Charge ID
it does
then retrieve the Charge with its ID
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
yes absolutely that works too!
thank you for you time ๐ is it okay if i ask another question here or do I have to make a sperate thread?
sure, what's your question?
about the paymentIntent.customer
from what i understand i should link it to that user in the database on a successful purchase, correct?
you mean in your own database? that's completely up to you
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 !
Happy to help ๐
Hey you still here? ๐คฃ
yes, how can I help?
The stripe customer id shouldn't change no matter how many transactions a user makes, right?
the paymentIntent.customer
if you pass the same customer parameter when creating the Chekcout Session, then yes
๐ taking over for my colleague. Let me know if there's any follow-up Qs I can answer!
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
in Checkout Sessions the default behavior for customer_creation https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-customer_creation is if_required which in the case of a mode: 'payment' Session isn't required
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.