#lennard_code

1 messages ยท Page 1 of 1 (latest)

twin fogBOT
#

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

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

fathom sparrowBOT
#

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.

broken cape
#

Hey, the code:

import Stripe from 'stripe';

const stripe = new Stripe('test key');

const endpointSecret = 'secret :)';
import { headers } from "next/headers"

export async function POST(req: Request) {
  const body = await req.text()
  const signature = headers().get("Stripe-Signature") as string

  let event: Stripe.Event

  try {
    event = stripe.webhooks.constructEvent(
      body,
      signature,
      endpointSecret
    )
  } catch (error) {
    return new Response(`Webhook Error: ${error.message}`, { status: 400 })
  }

  const session = event.data.object as Stripe.Checkout.Session

  if (event.type === "checkout.session.completed") {
    const subscription = await stripe.subscriptions.retrieve(
      session.subscription as string
    )
    console.log("๐Ÿš€ ~ POST ~ subscription:", subscription)
  }

  if (event.type === "invoice.payment_succeeded") {
    const subscription = await stripe.subscriptions.retrieve(
      session.subscription as string
    )
    console.log("๐Ÿš€ ~ POST ~ subscription:", subscription)

  }

  return new Response(null, { status: 200 })
}

#

This might be due to the product being one-time-purchase and NOT a subscription. Can that be the case?

broken cape
#

Figured it out! Instead I had to use this to get the details:

const subscription = await stripe.checkout.sessions.retrieve(session.id)

console.log("๐Ÿš€ ~ POST ~ subscription:", subscription)```

Hope you have a great day
#

!solved

#

Idk how I can solve this thread :)