Guides / Payments
You're building in the zone. A customer pays. You have no idea until you check Stripe 3 hours later.
With LogIt, you get a push notification the second checkout.session.completed fires β with the customer's email and the amount.
npm install logit stripe
// app/api/webhooks/stripe/route.ts (Next.js App Router)
import Stripe from "stripe";
import { init } from "logit";
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
const logit = init({ token: process.env.LOGIT_API_KEY! });
export async function POST(req: Request) {
const body = await req.text();
const sig = req.headers.get("stripe-signature")!;
const event = stripe.webhooks.constructEvent(
body,
sig,
process.env.STRIPE_WEBHOOK_SECRET!
);
if (event.type === "checkout.session.completed") {
const session = event.data.object;
const amount = ((session.amount_total ?? 0) / 100).toFixed(2);
const email = session.customer_email ?? "unknown";
await logit.now("payments", {
event: "Payment received π°",
description: `${email} β $${amount} ${(session.currency ?? "usd").toUpperCase()}`,
icon: "π°",
notify: true,
tags: { currency: session.currency ?? "usd" },
metadata: {
sessionId: session.id,
email,
amount: session.amount_total,
},
});
}
return new Response("ok");
}
https://yourdomain.com/api/webhooks/stripecheckout.session.completedSTRIPE_WEBHOOK_SECRETLOGIT_API_KEY=lk_live_xxxxxxxx
STRIPE_SECRET_KEY=sk_live_xxxxxxxx
STRIPE_WEBHOOK_SECRET=whsec_xxxxxxxx
stripe listen --forward-to localhost:3000/api/webhooks/stripe
stripe trigger checkout.session.completed
You'll see the event in your LogIt inbox within seconds.
Try LogIt free
7-day trial. No credit card required.