Docs

Stripe Events

Log charges, subscriptions, refunds, and failed payments directly from your Stripe webhooks. Know the moment money moves.


Overview

Add LogIt.Now() calls inside your Stripe webhook handler. Each event type maps to a channel — "payments", "subscriptions" — whatever makes your inbox readable.

Successful charge

ts
if (event.type === "charge.succeeded") {
  const charge = event.data.object;
  await logit.now("payments", {
    event: "Payment received",
    description: `${charge.billing_details.email} paid $${charge.amount / 100}`,
    icon: "💳",
    notify: true,
    tags: {
      plan: charge.metadata.plan ?? "unknown",
      currency: charge.currency,
    },
    metadata: {
      stripeChargeId: charge.id,
      amount: charge.amount / 100,
      email: charge.billing_details.email,
      customerId: charge.customer,
    },
  });
}

Subscription events

ts
// New subscription
if (event.type === "customer.subscription.created") {
  const sub = event.data.object;
  await logit.now("subscriptions", {
    event: "Subscription started",
    icon: "🔄",
    notify: true,
    tags: { plan: sub.items.data[0]?.price.nickname ?? "unknown" },
    metadata: { subscriptionId: sub.id, customerId: sub.customer },
  });
}

// Renewal
if (event.type === "invoice.payment_succeeded") {
  const invoice = event.data.object;
  if (invoice.billing_reason === "subscription_cycle") {
    await logit.now("subscriptions", {
      event: "Subscription renewed",
      icon: "✅",
      tags: { plan: invoice.lines.data[0]?.price?.nickname ?? "unknown" },
      metadata: { invoiceId: invoice.id, amount: (invoice.amount_paid ?? 0) / 100 },
    });
  }
}

Failed payments

ts
if (event.type === "payment_intent.payment_failed") {
  const pi = event.data.object;
  await logit.now("payments", {
    event: "Payment failed",
    description: pi.last_payment_error?.message ?? "Card declined",
    icon: "❌",
    notify: true,
    tags: {
      reason: pi.last_payment_error?.code ?? "unknown",
      declineCode: pi.last_payment_error?.decline_code ?? "none",
    },
    metadata: { paymentIntentId: pi.id, amount: pi.amount / 100 },
  });
}

Webhook setup

Listen to at least these Stripe events:

  • charge.succeeded
  • customer.subscription.created
  • invoice.payment_succeeded
  • payment_intent.payment_failed

Tip: Always verify the webhook signature using stripe.webhooks.constructEvent() before processing any event.