Back to blog
March 25, 202615 min read

Building a PDF Invoice System with Stripe and pdfRelay

End-to-end tutorial: generate branded invoices from Stripe payment data, host them, and email download links to customers.

stripeinvoicestutorialintegration

The goal

Build an automated invoice system: when a Stripe payment succeeds, generate a branded PDF invoice and email the download link to the customer.

Step 1: Create an invoice template

Save a React JSX template in pdfRelay that accepts Stripe payment data as props. The template renders a professional invoice with your company branding, line items, tax calculations, and payment details.

Step 2: Listen for Stripe webhooks

// In your Stripe webhook handler
app.post('/webhooks/stripe', async (req, res) => {
  const event = stripe.webhooks.constructEvent(req.body, sig, secret);

  if (event.type === 'invoice.paid') {
    const invoice = event.data.object;

    // Generate PDF invoice via pdfRelay
    const pdf = await fetch('https://pdfrelay.com/api/v1/render', {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer sk_live_...',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        template: 'invoice',
        data: {
          invoice_number: invoice.number,
          customer: invoice.customer_name,
          items: invoice.lines.data.map(l => ({
            name: l.description,
            qty: l.quantity,
            price: l.amount / 100,
          })),
          total: invoice.amount_paid / 100,
          date: new Date(invoice.created * 1000).toLocaleDateString(),
        },
        hosting: { enabled: true, expires_in: 2592000 }, // 30 days
      }),
    });

    const result = await pdf.json();
    // Email result.download_url to the customer
  }
});

Step 3: Email the invoice

The response includes a download_url — a hosted, password-optional link that your customer can use to view and download the invoice. No file attachments needed. No S3 buckets to manage. Just HTML templates you already know how to write.

Ready to try pdfRelay?

Get started free. No credit card required.