{
  "name": "Customer Refund with Verifiable Decision Receipts",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "refund-request",
        "options": {},
        "responseMode": "responseNode"
      },
      "id": "31775a7b-3676-4c88-a698-e5a502dcb7fd",
      "name": "Shopify Refund Request",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [
        0,
        300
      ]
    },
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "GPT-4O"
        },
        "messages": {
          "values": [
            {
              "role": "system",
              "content": "=You are a customer-refund AI agent. Decide APPROVE_REFUND or DENY based on order history and policy. Return JSON: {\"decision\":\"APPROVE_REFUND|DENY\",\"amount\":0,\"charge_id\":\"...\",\"reason\":\"...\"}."
            },
            {
              "content": "=Decide the refund. Return JSON only.\n\nOrder:\n{{ JSON.stringify($json.body) }}"
            }
          ]
        },
        "jsonOutput": true,
        "options": {}
      },
      "id": "7a2dad1c-4105-4dd5-8d9c-5ac5408a43f4",
      "name": "AI Refund Decision",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 2.1,
      "position": [
        220,
        300
      ],
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose"
          },
          "conditions": [
            {
              "id": "bde5661d-d7b7-4f95-a0a1-77e306a4fa35",
              "leftValue": "={{ $json.message.content.decision }}",
              "rightValue": "APPROVE_REFUND",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "43f4a0aa-05d7-4eb4-afdf-1dcbc946391a",
      "name": "IF Approve Refund",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        440,
        300
      ]
    },
    {
      "parameters": {
        "operation": "generateReceipt",
        "agentName": "RefundDecisionAgent",
        "workflowName": "={{ $workflow.name }}",
        "action": "Approved customer refund",
        "decision": "={{ JSON.stringify($json.message.content) }}",
        "additionalFields": {
          "modelProvider": "openai",
          "modelUsed": "gpt-4o",
          "decisionType": "refund_approval",
          "riskLevel": "medium",
          "humanReview": false,
          "policies": "refund-policy-v2",
          "permissions": "refund.execute",
          "tags": "refund, payments, cx"
        }
      },
      "id": "17766073-6228-4555-9a6f-220eaf06a84a",
      "name": "Signatrust: Receipt",
      "type": "n8n-nodes-signatrust.signatrust",
      "typeVersion": 1,
      "position": [
        660,
        200
      ],
      "credentials": {
        "signatrustApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.stripe.com/v1/refunds",
        "sendBody": true,
        "contentType": "form-urlencoded",
        "bodyParameters": {
          "parameters": [
            {
              "name": "charge",
              "value": "={{ $('AI Refund Decision').item.json.message.content.charge_id }}"
            }
          ]
        },
        "options": {}
      },
      "id": "3410c1fe-a68d-45cc-b1e4-c3394ae34404",
      "name": "Stripe Refund",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        880,
        200
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ { \"status\":\"DENIED\",\"detail\":$('AI Refund Decision').item.json.message.content } }}",
        "options": {}
      },
      "id": "57f09695-73b1-4544-abbc-e4f76aabf1e9",
      "name": "Respond Denied",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        660,
        440
      ]
    },
    {
      "parameters": {
        "content": "## Customer Refund + Signatrust\nAI approves/denies refunds. Six months later you can **prove exactly why** a refund was issued, by which agent, under which policy \u2014 then the Stripe refund executes.",
        "height": 200,
        "width": 420,
        "color": 5
      },
      "id": "c1c1a89b-1d45-4805-ad00-08deba6cce04",
      "name": "Sticky Note 8308f4",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -40,
        30
      ]
    }
  ],
  "connections": {
    "Shopify Refund Request": {
      "main": [
        [
          {
            "node": "AI Refund Decision",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Refund Decision": {
      "main": [
        [
          {
            "node": "IF Approve Refund",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF Approve Refund": {
      "main": [
        [
          {
            "node": "Signatrust: Receipt",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Respond Denied",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Signatrust: Receipt": {
      "main": [
        [
          {
            "node": "Stripe Refund",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "tags": [
    {
      "name": "Customer Refund \u2014 Refund"
    },
    {
      "name": "Customer Refund \u2014 Payments"
    },
    {
      "name": "Signatrust (3)"
    },
    {
      "name": "Customer Refund \u2014 Shopify"
    }
  ],
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "versionId": "f95ab465-d20b-48e1-85d9-ed7136c8a24c"
}