{
  "info": {
    "_postman_id": "7df7d097-ec7b-4a2a-8f3b-7e2f3b27b3a0",
    "name": "Sitepat Turboly Webhooks (API Routes)",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "item": [
    {
      "name": "Service Reservation Webhook",
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const secret = pm.environment.get('webhookSecret');",
              "const rawBody = pm.request.body && pm.request.body.raw ? pm.request.body.raw : '';",
              "const sig = CryptoJS.HmacSHA256(rawBody, secret).toString(CryptoJS.enc.Hex);",
              "pm.variables.set('computedSignature', sig);",
              "pm.variables.set('timestamp', new Date().toISOString());"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          { "key": "Content-Type", "value": "application/json" },
          { "key": "X-Turboly-Secret", "value": "{{webhookSecret}}" },
          { "key": "X-Turboly-Signature", "value": "sha256={{computedSignature}}" },
          { "key": "X-Timestamp", "value": "{{timestamp}}" }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"event\": \"service_reservation.confirmed\",\n  \"reservation\": {\n    \"id\": 12345,\n    \"status\": \"confirmed\",\n    \"customer_id\": 2,\n    \"vehicle_id\": 759675,\n    \"store_id\": 3385,\n    \"scheduled_at\": \"2025-10-29T08:00:00Z\",\n    \"notes\": \"example\"\n  }\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/webhooks/serviceReservations",
          "host": ["{{baseUrl}}"],
          "path": ["api","v1","webhooks","serviceReservations"]
        }
      }
    },
    {
      "name": "Service Order Webhook",
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const secret = pm.environment.get('webhookSecret');",
              "const rawBody = pm.request.body && pm.request.body.raw ? pm.request.body.raw : '';",
              "const sig = CryptoJS.HmacSHA256(rawBody, secret).toString(CryptoJS.enc.Hex);",
              "pm.variables.set('computedSignature', sig);",
              "pm.variables.set('timestamp', new Date().toISOString());"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          { "key": "Content-Type", "value": "application/json" },
          { "key": "X-Turboly-Secret", "value": "{{webhookSecret}}" },
          { "key": "X-Turboly-Signature", "value": "sha256={{computedSignature}}" },
          { "key": "X-Timestamp", "value": "{{timestamp}}" }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"event\": \"service_order.approved\",\n  \"service_order\": {\n    \"id\": 55555,\n    \"reservation_id\": 12345,\n    \"status\": \"approved\",\n    \"customer_id\": 2,\n    \"store_id\": 3385,\n    \"updated_at\": \"2025-10-29T09:00:00Z\"\n  }\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/webhooks/serviceOrders",
          "host": ["{{baseUrl}}"],
          "path": ["api","v1","webhooks","serviceOrders"]
        }
      }
    },
    {
      "name": "Work Order Webhook",
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const secret = pm.environment.get('webhookSecret');",
              "const rawBody = pm.request.body && pm.request.body.raw ? pm.request.body.raw : '';",
              "const sig = CryptoJS.HmacSHA256(rawBody, secret).toString(CryptoJS.enc.Hex);",
              "pm.variables.set('computedSignature', sig);",
              "pm.variables.set('timestamp', new Date().toISOString());"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          { "key": "Content-Type", "value": "application/json" },
          { "key": "X-Turboly-Secret", "value": "{{webhookSecret}}" },
          { "key": "X-Turboly-Signature", "value": "sha256={{computedSignature}}" },
          { "key": "X-Timestamp", "value": "{{timestamp}}" }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"event\": \"work_order.status_changed\",\n  \"work_order\": {\n    \"id\": 77777,\n    \"service_order_id\": 55555,\n    \"status\": \"in_progress\",\n    \"completed_tasks\": [\n      {\n        \"task_id\": 1,\n        \"status\": \"done\",\n        \"completed_at\": \"2025-10-29T09:30:00Z\"\n      }\n    ]\n  }\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/webhooks/serviceWorkOrders",
          "host": ["{{baseUrl}}"],
          "path": ["api","v1","webhooks","serviceWorkOrders"]
        }
      }
    },
    {
      "name": "Service Invoice Webhook",
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const secret = pm.environment.get('webhookSecret');",
              "const rawBody = pm.request.body && pm.request.body.raw ? pm.request.body.raw : '';",
              "const sig = CryptoJS.HmacSHA256(rawBody, secret).toString(CryptoJS.enc.Hex);",
              "pm.variables.set('computedSignature', sig);",
              "pm.variables.set('timestamp', new Date().toISOString());"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          { "key": "Content-Type", "value": "application/json" },
          { "key": "X-Turboly-Secret", "value": "{{webhookSecret}}" },
          { "key": "X-Turboly-Signature", "value": "sha256={{computedSignature}}" },
          { "key": "X-Timestamp", "value": "{{timestamp}}" }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"event\": \"service_invoice.completed\",\n  \"service_invoice\": {\n    \"id\": 99999,\n    \"service_order_id\": 55555,\n    \"amount\": 250000,\n    \"status\": \"completed\",\n    \"completed_at\": \"2025-10-29T10:00:00Z\"\n  }\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/v1/webhooks/serviceInvoices",
          "host": ["{{baseUrl}}"],
          "path": ["api","v1","webhooks","serviceInvoices"]
        }
      }
    }
  ]
}
