Guides / Payments

Get Notified When Someone Pays You on Stripe

5 min readΒ·Payments

The Problem

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.

Setup

bash
npm install logit stripe

Webhook handler

ts
// 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");
}

Register in Stripe

  1. Stripe Dashboard β†’ Developers β†’ Webhooks β†’ Add endpoint
  2. URL: https://yourdomain.com/api/webhooks/stripe
  3. Event: checkout.session.completed
  4. Copy the Signing secret to STRIPE_WEBHOOK_SECRET

Environment variables

bash
LOGIT_API_KEY=lk_live_xxxxxxxx
STRIPE_SECRET_KEY=sk_live_xxxxxxxx
STRIPE_WEBHOOK_SECRET=whsec_xxxxxxxx

Testing locally

bash
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.

Start free