{
  "format": "columba-flow",
  "formatVersion": 1,
  "app": "Columba · Blog",
  "flow": {
    "name": "Stripe · Fatura com vencimento (boleto)",
    "description": "Cliente escreve \"boleto\", \"fatura\" ou \"mensalidade\": o fluxo pede o e-mail (o Stripe exige e-mail para faturas com vencimento), grava no cliente do Stripe, cria a fatura com vencimento em 5 dias e manda o link (Pix, cartão ou boleto) e o PDF. Sem resposta em 30 minutos, oferece o link de pagamento no lugar. Se a fatura vencer sem pagamento, o fluxo \"Fatura vencida\" assume.",
    "triggerType": "trigger_keyword",
    "triggerConfig": {
      "nodeType": "trigger_keyword",
      "label": "Cliente pede boleto/fatura",
      "keywords": "boleto\nfatura\nmensalidade",
      "matchMode": "contains"
    },
    "priority": 25,
    "nodes": [
      {
        "id": "gatilho",
        "type": "trigger_keyword",
        "position": { "x": 0, "y": 0 },
        "data": {
          "nodeType": "trigger_keyword",
          "label": "Cliente pede boleto/fatura",
          "keywords": "boleto\nfatura\nmensalidade",
          "matchMode": "contains"
        }
      },
      {
        "id": "nota",
        "type": "note_sticky",
        "position": { "x": 380, "y": -40 },
        "data": {
          "nodeType": "note_sticky",
          "label": "Antes de publicar",
          "text": "Antes de publicar:\n1. No nó Fatura, troque o valor (R$ 99,00) e a descrição pelos seus.\n2. Vencimento: 5 dias. Mude em Vencimento (dias), se quiser.\n3. O Stripe manda a fatura também por e-mail (Enviar fatura por e-mail ligado).\nPrioridade 25: o fluxo \"2ª via\" (20) vem antes, para \"segunda via do boleto\" não gerar fatura nova."
        }
      },
      {
        "id": "pede_email",
        "type": "action_send_text",
        "position": { "x": 0, "y": 150 },
        "data": {
          "nodeType": "action_send_text",
          "label": "Pede o e-mail",
          "message": "Claro, {{contact.first_name}}! Para emitir a fatura com boleto eu preciso do seu e-mail. Pode me mandar?"
        }
      },
      {
        "id": "espera",
        "type": "logic_wait_for_reply",
        "position": { "x": 0, "y": 300 },
        "data": {
          "nodeType": "logic_wait_for_reply",
          "label": "Aguarda o e-mail (30 min)",
          "timeoutMinutes": 30
        }
      },
      {
        "id": "cliente",
        "type": "integration_stripe_upsert_customer",
        "position": { "x": -200, "y": 470 },
        "data": {
          "nodeType": "integration_stripe_upsert_customer",
          "label": "Cliente no Stripe com o e-mail",
          "customerEmail": "{{message.body}}",
          "searchByEmail": true,
          "updateExisting": true
        }
      },
      {
        "id": "fatura",
        "type": "integration_stripe_create_charge",
        "position": { "x": -200, "y": 640 },
        "data": {
          "nodeType": "integration_stripe_create_charge",
          "label": "Fatura R$ 99, vence em 5 dias",
          "kind": "invoice",
          "amount": "99,00",
          "description": "Mensalidade — {{contact.name}}",
          "daysUntilDue": 5,
          "sendInvoiceEmail": true,
          "existingPolicy": "reuse_open",
          "createCustomer": true
        }
      },
      {
        "id": "envia",
        "type": "action_send_text",
        "position": { "x": -500, "y": 830 },
        "data": {
          "nodeType": "action_send_text",
          "label": "Manda fatura e PDF",
          "message": "Sua fatura de {{flow.stripe_amount_formatted}} está pronta, com vencimento em 5 dias. Também mandei por e-mail.\n\nPagar (Pix, cartão ou boleto): {{flow.stripe_payment_url}}\nPDF do boleto: {{flow.stripe_invoice_pdf}}"
        }
      },
      {
        "id": "existente",
        "type": "action_send_text",
        "position": { "x": -200, "y": 830 },
        "data": {
          "nodeType": "action_send_text",
          "label": "Fatura já aberta",
          "message": "Você já tem uma fatura em aberto de {{flow.stripe_amount_formatted}}: {{flow.stripe_payment_url}}"
        }
      },
      {
        "id": "erro",
        "type": "integration_notify_team",
        "position": { "x": 100, "y": 830 },
        "data": {
          "nodeType": "integration_notify_team",
          "label": "Erro → sino",
          "notificationMessage": "Stripe: não consegui criar a fatura de {{contact.name}}: {{flow.stripe_error}} ({{flow.stripe_error_code}}).",
          "priority": "high"
        }
      },
      {
        "id": "timeout",
        "type": "action_send_text",
        "position": { "x": 300, "y": 470 },
        "data": {
          "nodeType": "action_send_text",
          "label": "Sem e-mail: oferece o link",
          "message": "Sem problemas! Se preferir, escreva \"pagar\" que eu gero um link de pagamento sem precisar de e-mail."
        }
      }
    ],
    "edges": [
      {
        "id": "e_gatilho_pede_email",
        "source": "gatilho",
        "target": "pede_email"
      },
      {
        "id": "e_pede_email_espera",
        "source": "pede_email",
        "target": "espera"
      },
      {
        "id": "e_espera_cliente_true",
        "source": "espera",
        "target": "cliente",
        "sourceHandle": "true",
        "label": "Respondeu"
      },
      {
        "id": "e_espera_timeout_false",
        "source": "espera",
        "target": "timeout",
        "sourceHandle": "false",
        "label": "Timeout"
      },
      {
        "id": "e_cliente_fatura_success",
        "source": "cliente",
        "target": "fatura",
        "sourceHandle": "success",
        "label": "Sucesso"
      },
      {
        "id": "e_cliente_erro_error",
        "source": "cliente",
        "target": "erro",
        "sourceHandle": "error",
        "label": "Erro"
      },
      {
        "id": "e_fatura_envia_created",
        "source": "fatura",
        "target": "envia",
        "sourceHandle": "created",
        "label": "Criada"
      },
      {
        "id": "e_fatura_existente_existing",
        "source": "fatura",
        "target": "existente",
        "sourceHandle": "existing",
        "label": "Já existia"
      },
      {
        "id": "e_fatura_erro_error",
        "source": "fatura",
        "target": "erro",
        "sourceHandle": "error",
        "label": "Erro"
      }
    ]
  }
}
