{
  "format": "columba-flow",
  "formatVersion": 1,
  "app": "Columba · Blog",
  "flow": {
    "name": "Stripe · Fatura vencida: lembrete e financeiro",
    "description": "Dispara quando uma fatura vence sem pagamento (qualquer fatura da conta Stripe, inclusive as criadas no painel: \"Só cobranças criadas pelo Columba\" desligado). Manda a 2ª via na conversa, aplica a tag \"em atraso\", espera 2 dias e consulta de novo. Continua vencida: transfere a conversa e avisa no sino. Paga nesse meio-tempo: agradece e tira a tag.",
    "triggerType": "trigger_stripe_event",
    "triggerConfig": {
      "nodeType": "trigger_stripe_event",
      "label": "Fatura venceu no Stripe",
      "events": ["invoice_overdue"],
      "kind": "invoice",
      "onlyFromColumba": false,
      "channel": "whatsapp",
      "onActiveFlow": "restart",
      "createContact": true
    },
    "priority": 15,
    "nodes": [
      {
        "id": "gatilho",
        "type": "trigger_stripe_event",
        "position": { "x": 0, "y": 0 },
        "data": {
          "nodeType": "trigger_stripe_event",
          "label": "Fatura venceu no Stripe",
          "events": ["invoice_overdue"],
          "kind": "invoice",
          "onlyFromColumba": false,
          "channel": "whatsapp",
          "onActiveFlow": "restart",
          "createContact": true
        }
      },
      {
        "id": "nota",
        "type": "note_sticky",
        "position": { "x": 380, "y": -40 },
        "data": {
          "nodeType": "note_sticky",
          "label": "Antes de publicar",
          "text": "Antes de publicar:\n1. Crie a tag \"em atraso\" em Configurações › Tags.\n2. Em Transfere ao financeiro, escolha o time (ex.: Financeiro).\n3. Em número da API Oficial, configure o modelo de fallback no Lembrete: a fatura costuma vencer fora da janela de 24 horas.\n4. Em Extensões › Stripe › Notificações, deixe \"Fatura venceu\" ligado."
        }
      },
      {
        "id": "lembrete",
        "type": "action_send_text",
        "position": { "x": 0, "y": 160 },
        "data": {
          "nodeType": "action_send_text",
          "label": "Lembrete com 2ª via",
          "message": "Oi, {{contact.first_name}}! A fatura de {{stripe.object.amount_formatted}} venceu e ainda consta em aberto.\n\nSegunda via para pagar agora (Pix, cartão ou boleto):\n{{stripe.object.url}}\n\nSe já pagou, desconsidere esta mensagem. 🙏"
        }
      },
      {
        "id": "tag_atraso",
        "type": "integration_tag_contact",
        "position": { "x": 0, "y": 310 },
        "data": {
          "nodeType": "integration_tag_contact",
          "label": "Tag: em atraso",
          "tagAction": "add",
          "tags": "em atraso"
        }
      },
      {
        "id": "espera",
        "type": "action_delay",
        "position": { "x": 0, "y": 460 },
        "data": {
          "nodeType": "action_delay",
          "label": "Aguarda 2 dias",
          "duration": 48,
          "unit": "hours"
        }
      },
      {
        "id": "consulta",
        "type": "integration_stripe_lookup_charges",
        "position": { "x": 0, "y": 610 },
        "data": {
          "nodeType": "integration_stripe_lookup_charges",
          "label": "Ainda está vencida?",
          "limit": 5,
          "includeSubscription": false
        }
      },
      {
        "id": "financeiro",
        "type": "integration_transfer_human",
        "position": { "x": -360, "y": 800 },
        "data": {
          "nodeType": "integration_transfer_human",
          "label": "Transfere ao financeiro"
        }
      },
      {
        "id": "sino",
        "type": "integration_notify_team",
        "position": { "x": -360, "y": 950 },
        "data": {
          "nodeType": "integration_notify_team",
          "label": "Avisa a equipe",
          "notificationMessage": "Fatura vencida sem pagamento: {{contact.name}}, {{flow.stripe_last_charge_amount_formatted}}, vencida em {{flow.stripe_last_charge_due_date}}. Conversa transferida para o atendimento.",
          "priority": "high"
        }
      },
      {
        "id": "pago",
        "type": "action_send_text",
        "position": { "x": 0, "y": 800 },
        "data": {
          "nodeType": "action_send_text",
          "label": "Pagou nesse meio-tempo",
          "message": "Vi aqui que o pagamento entrou. Obrigado, {{contact.first_name}}! ✅"
        }
      },
      {
        "id": "tira_tag",
        "type": "integration_tag_contact",
        "position": { "x": 0, "y": 950 },
        "data": {
          "nodeType": "integration_tag_contact",
          "label": "Tira a tag em atraso",
          "tagAction": "remove",
          "tags": "em atraso"
        }
      },
      {
        "id": "pendente",
        "type": "action_send_text",
        "position": { "x": 360, "y": 800 },
        "data": {
          "nodeType": "action_send_text",
          "label": "Nova fatura em aberto",
          "message": "A fatura anterior foi regularizada e há uma nova em aberto de {{flow.stripe_last_charge_amount_formatted}}: {{flow.stripe_last_charge_url}}"
        }
      }
    ],
    "edges": [
      {
        "id": "e_gatilho_lembrete",
        "source": "gatilho",
        "target": "lembrete"
      },
      {
        "id": "e_lembrete_tag_atraso",
        "source": "lembrete",
        "target": "tag_atraso"
      },
      {
        "id": "e_tag_atraso_espera",
        "source": "tag_atraso",
        "target": "espera"
      },
      {
        "id": "e_espera_consulta",
        "source": "espera",
        "target": "consulta"
      },
      {
        "id": "e_consulta_financeiro_overdue",
        "source": "consulta",
        "target": "financeiro",
        "sourceHandle": "overdue",
        "label": "Vencida"
      },
      {
        "id": "e_financeiro_sino",
        "source": "financeiro",
        "target": "sino"
      },
      {
        "id": "e_consulta_pago_paid",
        "source": "consulta",
        "target": "pago",
        "sourceHandle": "paid",
        "label": "Paga"
      },
      {
        "id": "e_pago_tira_tag",
        "source": "pago",
        "target": "tira_tag"
      },
      {
        "id": "e_consulta_pendente_pending",
        "source": "consulta",
        "target": "pendente",
        "sourceHandle": "pending",
        "label": "Pendente"
      }
    ]
  }
}
