{
  "name": "Docspout: Stripe invoice paid → PDF invoice by email",
  "nodes": [
    {
      "parameters": {
        "content": "## Stripe invoice paid → invoice PDF → Gmail\n1. In Docspout, open an **Invoice** starter, click **Publish**, and copy its template id (`tpl_...`).\n2. Paste it over `tpl_REPLACE_ME` in the **Render invoice PDF** node.\n3. Credentials → New → **Header Auth**: name `Authorization`, value `Bearer sk_test_...` (a test key while you try it; switch to a live key after). Call it `Docspout API key`.\n4. Connect Stripe and Gmail credentials.\n\nThe Idempotency-Key is the Stripe event id, so a retried webhook never renders or counts twice.",
        "height": 300,
        "width": 520
      },
      "id": "note",
      "name": "Setup",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -60,
        -320
      ]
    },
    {
      "parameters": {
        "events": [
          "invoice.paid"
        ]
      },
      "id": "stripe-trigger",
      "name": "Stripe: invoice paid",
      "type": "n8n-nodes-base.stripeTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ],
      "webhookId": "docspout-stripe-invoice",
      "credentials": {
        "stripeApi": {
          "id": "",
          "name": "Stripe account"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://docspout.com/v1/renders",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Idempotency-Key",
              "value": "={{ $json.id }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ template: 'tpl_REPLACE_ME', output: 'pdf', filename: 'invoice-' + ($json.data.object.number || $json.data.object.id), data: { number: $json.data.object.number || $json.data.object.id, issued: new Date($json.data.object.created * 1000).toISOString().slice(0, 10), due: $json.data.object.due_date ? new Date($json.data.object.due_date * 1000).toISOString().slice(0, 10) : new Date($json.data.object.created * 1000).toISOString().slice(0, 10), company: { name: $json.data.object.account_name || 'Your company', address: 'Your address' }, customer: { name: $json.data.object.customer_name || $json.data.object.customer_email, email: $json.data.object.customer_email }, items: $json.data.object.lines.data.map(l => ({ name: l.description, qty: l.quantity, price: (l.price ? l.price.unit_amount : l.amount / l.quantity) / 100, amount: l.amount / 100 })), total: $json.data.object.total / 100, notes: 'Paid with Stripe. Thank you!' } }) }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        }
      },
      "id": "render-invoice-pdf",
      "name": "Render invoice PDF",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        260,
        0
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": "",
          "name": "Docspout API key"
        }
      }
    },
    {
      "parameters": {
        "sendTo": "={{ $('Stripe: invoice paid').item.json.data.object.customer_email }}",
        "subject": "=Your invoice {{ $('Stripe: invoice paid').item.json.data.object.number }}",
        "emailType": "text",
        "message": "Thanks for your payment. Your invoice is attached.",
        "options": {
          "attachmentsUi": {
            "attachmentsBinary": [
              {
                "property": "data"
              }
            ]
          }
        }
      },
      "id": "gmail",
      "name": "Email the PDF",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        520,
        0
      ],
      "webhookId": "docspout-gmail-1",
      "credentials": {
        "gmailOAuth2": {
          "id": "",
          "name": "Gmail account"
        }
      }
    }
  ],
  "connections": {
    "Stripe: invoice paid": {
      "main": [
        [
          {
            "node": "Render invoice PDF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Render invoice PDF": {
      "main": [
        [
          {
            "node": "Email the PDF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}