Generate a PDF invoice after every Stripe payment

Stripe tells you a payment succeeded. Your customer gets a branded PDF invoice in seconds, and you're notified when they open it. Two ways to set it up, depending on whether you write code.

No code: use Zapier

Trigger: Stripe → New Payment. Then follow our Zapier PDF guide from step 2. About five minutes.

Code: Stripe webhook

A small Node.js endpoint that listens for checkout.session.completed and calls PDFMint. Full example below.

The code route (Node.js)

1. Create the webhook endpoint

Stripe signs every webhook, so always verify the signature before trusting the event. This example uses Express and the official stripe package:

const express = require('express');
const Stripe = require('stripe');
const stripe = Stripe(process.env.STRIPE_SECRET_KEY);
const app = express();

// Stripe needs the RAW body to verify the signature.
app.post('/stripe/webhook', express.raw({ type: 'application/json' }), async (req, res) => {
  let event;
  try {
    event = stripe.webhooks.constructEvent(req.body, req.headers['stripe-signature'], process.env.STRIPE_WEBHOOK_SECRET);
  } catch (err) {
    return res.status(400).send('Bad signature');
  }
  if (event.type === 'checkout.session.completed') {
    await sendInvoice(event.data.object);
  }
  res.json({ received: true });
});

2. Generate the invoice with PDFMint

Stripe amounts are in the smallest currency unit (cents), so divide by 100 for display:

async function sendInvoice(session) {
  const amount = (session.amount_total / 100).toFixed(2);
  const number = 'INV-' + session.id.slice(-8).toUpperCase();

  const r = await fetch('https://pdfmintapi.com/v1/generate', {
    method: 'POST',
    headers: { Authorization: `Bearer ${process.env.PDFMINT_KEY}`, 'Content-Type': 'application/json' },
    body: JSON.stringify({
      template: 'invoice',
      response_format: 'url',
      filename: number,
      callback_url: 'https://your-app.com/hooks/invoice-opened', // optional
      data: {
        invoice_number: number,
        date: new Date().toLocaleDateString('en-US', { dateStyle: 'long' }),
        currency: '$',
        from: { name: 'Your Company' },
        to: { name: session.customer_details.name, email: session.customer_details.email },
        items: [{ name: 'Order ' + number, qty: 1, amount }],
        total: amount,
      },
    }),
  });
  const { view_url } = await r.json();
  // Email view_url to session.customer_details.email with your mail provider.
}
Send the link, not an attachment. The view_url is tracked: you see Opened in your dashboard and your callback_url receives a document.viewed webhook. A file attachment can't report opens.

3. Register the endpoint in Stripe

Stripe Dashboard → Developers → Webhooks → Add endpoint → your URL → select checkout.session.completed. Copy the signing secret into STRIPE_WEBHOOK_SECRET. To test locally, use the Stripe CLI: stripe listen --forward-to localhost:3000/stripe/webhook.

Variations

Invoices that send themselves

Free tier: 100 PDFs a month, tracking included, no credit card.

Get your free API key →