mirror of
https://github.com/sqlchat/sqlchat.git
synced 2025-09-23 18:43:18 +08:00
fix: use new stripe api to fetch receipt from latest charge (#97)
This commit is contained in:
@ -49,6 +49,10 @@ const webhookHandler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|||||||
// Cast event data to Stripe object.
|
// Cast event data to Stripe object.
|
||||||
if (event.type === "payment_intent.succeeded") {
|
if (event.type === "payment_intent.succeeded") {
|
||||||
const paymentIntent = event.data.object as Stripe.PaymentIntent;
|
const paymentIntent = event.data.object as Stripe.PaymentIntent;
|
||||||
|
const charge = await stripe.charges.retrieve(
|
||||||
|
paymentIntent.latest_charge as string
|
||||||
|
);
|
||||||
|
|
||||||
const customerId = paymentIntent.customer as string;
|
const customerId = paymentIntent.customer as string;
|
||||||
if (customerId) {
|
if (customerId) {
|
||||||
// Save the stripe customer id so that we can relate this customer to future payments.
|
// Save the stripe customer id so that we can relate this customer to future payments.
|
||||||
@ -86,7 +90,7 @@ const webhookHandler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|||||||
description: paymentIntent.metadata.description,
|
description: paymentIntent.metadata.description,
|
||||||
amount: paymentIntent.amount,
|
amount: paymentIntent.amount,
|
||||||
currency: paymentIntent.currency,
|
currency: paymentIntent.currency,
|
||||||
receipt: paymentIntent.charges.data[0].receipt_url,
|
receipt: charge.receipt_url as string,
|
||||||
};
|
};
|
||||||
await prisma.subscription.create({ data: subscription });
|
await prisma.subscription.create({ data: subscription });
|
||||||
} else if (event.type === "payment_intent.payment_failed") {
|
} else if (event.type === "payment_intent.payment_failed") {
|
||||||
|
Reference in New Issue
Block a user