Closed utkarsh-1602 closed 10 months ago
Stripe.Event
:
Events are our way of letting you know when something interesting happens in your account. When an interesting event occurs, we create a new Event object. For example, when a charge succeeds, we create a charge.succeeded event, and when an invoice payment attempt fails, we create an invoice.payment_failed event. Certain API requests might create multiple events. For example, if you create a new subscription for a customer, you receive both a customer.subscription.created event and a charge.succeeded event
Use Stripe(publishableKey, options?)
to create an instance of the Stripe object. The Stripe object is your entrypoint to the rest of the Stripe.js SDK.
import Stripe from "stripe"
export const stripe = new Stripe(process.env.STRIPE_API_SECRET_KEY!, {
apiVersion: "2023-10-16",
typescript: true,
})
A Very Helpful Documentation for Setting Up and Deploying a webhook to listen events from stripe : https://stripe.com/docs/webhooks/quickstart Use webhooks for post-payment commerce events such as sending custom email receipts, fulfilling orders, or updating your database
This code defines a Next.js API route that handles incoming POST requests from Stripe webhooks. It validates the webhook signature, extracts relevant information from the Stripe event (specifically from the Checkout Session), and processes the event when a checkout session is completed. The order status and associated products are updated in the database accordingly. The route returns a 200 response to indicate successful processing of the webhook.
in my
api/webhook/route.ts
file, I've used Stripe webhook, I need a proper documentation which explain the stripe webhook working in the code.import Stripe from "stripe"; import { headers } from "next/headers" import { stripe } from "@/lib/stripe"; import { NextResponse } from "next/server"; import prismadb from "@/lib/prismadb";
export async function POST(req: Request) { const body = await req.text(); const signature = headers().get("Stripe-Signature") as string;
}