#mohammad-orabi_webhooks

1 messages ¡ Page 1 of 1 (latest)

pearl auroraBOT
#

👋 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/1217031241677930535

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

ripe topaz
#
  console.log("event", event);
  //method 1
  if (event.type === "customer.subscription.created") {
    const subscription = event.data.object;
    const status = subscription.status;
    const teamId = subscription.metadata.teamId;
    const subscriptionId = subscription.id;
    await updateTeamSubscription({ teamId, status, subscriptionId });
  }
  //method 2
  if (
    event.type == "checkout.session.completed" ||
    event.type == "checkout.session.async_payment_succeeded"
  ) {
    const session = event.data.object;
    if (session.payment_status == "paid") {
      const subscription = await stripe.subscriptions.retrieve(
        session.subscription as string
      );
      const status = subscription.status;
      const teamId = subscription.metadata.teamId;
      const subscriptionId = subscription.id;
      await updateTeamSubscription({ teamId, status, subscriptionId });
    }
  }
}```
surreal blazeBOT
quasi tide
#

checkout.session.completed event is for completing the Checkout Session. When the Checkout Session is in mode: subscription, the successful payment on the Checkout Session will send checkout.session.completed event.

For customer.subscription.created event, it doesn't mean that the subscription has been paid successfully. I'd recommend checking the guide here for provisioning the subscription created by Checkout Session: https://docs.stripe.com/billing/subscriptions/build-subscriptions?ui=stripe-hosted#provision-and-monitor

Create and manage subscriptions to accept recurring payments.

ripe topaz
#

ah okay , then the customer.subscription.created can be received even if the payment failed , but with a status of incomplete or something right?

quasi tide
#

Yes, that can happen

pearl auroraBOT