{
  "name": "S2D recipe - stripe-payment-receipt-pdf",
  "nodes": [
    {
      "id": "c5000000-0000-4000-8000-000000000001",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -760,
        -400
      ],
      "parameters": {
        "width": 600,
        "height": 340,
        "content": "## PDF receipt from a Stripe payment\nWhen a Stripe Checkout session completes and is paid, the workflow starts one SourceToDocs run: a receipt from your Google Docs template, saved to Google Drive as a Doc and a PDF. Gmail then sends the PDF link to the address the customer paid with.\n\n**Set up before you activate**\n- Credentials: Stripe on the trigger (use a test mode key first), a SourceToDocs API token on the SourceToDocs node, Gmail on the Gmail node\n- SourceToDocs node: your receipt document and its data set with the columns Customer, Email, Amount, Reference, Paid on\n- Amount divides by 100: change it for currencies without a minor unit\n- The Drive folder must be shared so the customer can open the link\n\nGuide: https://sourcetodocs.com/automations/stripe-payment-receipt-pdf/"
      }
    },
    {
      "id": "c5000000-0000-4000-8000-000000000002",
      "name": "Stripe Trigger",
      "type": "n8n-nodes-base.stripeTrigger",
      "typeVersion": 1,
      "position": [
        -700,
        0
      ],
      "parameters": {
        "events": [
          "checkout.session.completed"
        ]
      }
    },
    {
      "id": "c5000000-0000-4000-8000-000000000003",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.4,
      "position": [
        -480,
        0
      ],
      "parameters": {
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "c5c00000-0000-4000-8000-000000000001",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.data.object.payment_status }}",
              "rightValue": "paid"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "c5000000-0000-4000-8000-000000000004",
      "name": "SourceToDocs",
      "type": "@twovmodules/n8n-nodes-sourcetodocs.sourceToDocs",
      "typeVersion": 1.1,
      "position": [
        -240,
        -20
      ],
      "parameters": {
        "resource": "document",
        "operation": "generate",
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "rowsFrom": "mapped",
        "mappedDataSetId": "",
        "output": "simplified",
        "options": {},
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Customer": "={{ $json.data.object.customer_details.name }}",
            "Email": "={{ $json.data.object.customer_details.email }}",
            "Amount": "={{ ($json.data.object.amount_total / 100).toFixed(2) }} {{ $json.data.object.currency.toUpperCase() }}",
            "Reference": "={{ $json.data.object.payment_intent }}",
            "Paid on": "={{ DateTime.fromSeconds($json.created).toFormat('d LLLL yyyy') }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Customer",
              "displayName": "Customer",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false,
              "removed": false
            },
            {
              "id": "Email",
              "displayName": "Email",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false,
              "removed": false
            },
            {
              "id": "Amount",
              "displayName": "Amount",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false,
              "removed": false
            },
            {
              "id": "Reference",
              "displayName": "Reference",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false,
              "removed": false
            },
            {
              "id": "Paid on",
              "displayName": "Paid on",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        }
      }
    },
    {
      "id": "c5000000-0000-4000-8000-000000000005",
      "name": "Gmail",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.2,
      "position": [
        0,
        -20
      ],
      "parameters": {
        "resource": "message",
        "operation": "send",
        "sendTo": "={{ $('Stripe Trigger').first().json.data.object.customer_details.email }}",
        "subject": "Your receipt",
        "emailType": "html",
        "message": "=Thank you for your payment. Your receipt: {{ $json.deliveries[0].result.pdf_url }}",
        "options": {}
      }
    }
  ],
  "connections": {
    "Stripe Trigger": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "SourceToDocs",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "SourceToDocs": {
      "main": [
        [
          {
            "node": "Gmail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}
