{
  "$schema": "./.schemas/page.schema.json",
  "title": "Stripe",
  "icon": "creditcard",
  "period": {
    "step": true,
    "choices": [
      {
        "id": "month",
        "label": "Month",
        "span": "month"
      }
    ]
  },
  "sources": {
    "account": {
      "url": "https://api.stripe.com",
      "secret": "stripe",
      "every": "5m",
      "headers": {
        "Stripe-Version": "2026-09-30.endive"
      },
      "requests": {
        "account": "/v1/account",
        "balance": "/v1/balance",
        "payouts": "/v1/payouts?limit=20",
        "disputes": {
          "path": "/v1/disputes?limit=100",
          "follow": {
            "items": "data",
            "while": "has_more",
            "param": "starting_after",
            "from_last": "id",
            "max": 5
          }
        }
      },
      "derive": [
        {
          "name": "cur",
          "value": {
            "path": "account.default_currency",
            "default": "usd"
          }
        },
        {
          "name": "unit",
          "value": {
            "template": "{cur|upper}"
          }
        },
        {
          "name": "scale",
          "value": {
            "path": "cur",
            "values": {
              "bif": 1,
              "clp": 1,
              "djf": 1,
              "gnf": 1,
              "jpy": 1,
              "kmf": 1,
              "krw": 1,
              "mga": 1,
              "pyg": 1,
              "rwf": 1,
              "vnd": 1,
              "vuv": 1,
              "xaf": 1,
              "xof": 1,
              "xpf": 1,
              "bhd": 0.001,
              "jod": 0.001,
              "kwd": 0.001,
              "omr": 0.001,
              "tnd": 0.001
            },
            "default": 0.01
          }
        },
        {
          "name": "dec",
          "value": {
            "path": "cur",
            "values": {
              "bif": 0,
              "clp": 0,
              "djf": 0,
              "gnf": 0,
              "jpy": 0,
              "kmf": 0,
              "krw": 0,
              "mga": 0,
              "pyg": 0,
              "rwf": 0,
              "vnd": 0,
              "vuv": 0,
              "xaf": 0,
              "xof": 0,
              "xpf": 0,
              "bhd": 3,
              "jod": 3,
              "kwd": 3,
              "omr": 3,
              "tnd": 3
            },
            "default": 2
          }
        },
        {
          "name": "sym",
          "value": {
            "path": "cur",
            "values": {
              "usd": "$",
              "eur": "€",
              "gbp": "£",
              "jpy": "¥",
              "inr": "₹",
              "krw": "₩",
              "cad": "CA$",
              "aud": "A$",
              "nzd": "NZ$",
              "hkd": "HK$",
              "sgd": "S$",
              "mxn": "MX$",
              "brl": "R$"
            },
            "default": {
              "template": "{cur|upper} "
            }
          }
        },
        {
          "name": "available",
          "value": {
            "multiply": [
              {
                "sum": "amount",
                "of": "balance.available",
                "where": {
                  "path": "currency",
                  "equals": {
                    "answer": "cur"
                  }
                },
                "default": 0
              },
              "scale"
            ],
            "round": 3
          }
        },
        {
          "name": "pending",
          "value": {
            "multiply": [
              {
                "sum": "amount",
                "of": "balance.pending",
                "where": {
                  "path": "currency",
                  "equals": {
                    "answer": "cur"
                  }
                },
                "default": 0
              },
              "scale"
            ],
            "round": 3
          }
        },
        {
          "name": "pending_words",
          "value": {
            "if": {
              "path": "dec",
              "equals": 0
            },
            "then": {
              "template": "{sym}{pending|round:0}"
            },
            "else": {
              "if": {
                "path": "dec",
                "equals": 3
              },
              "then": {
                "template": "{sym}{pending|round:3}"
              },
              "else": {
                "template": "{sym}{pending|round:2}"
              }
            }
          }
        },
        {
          "name": "next_count",
          "value": {
            "count": "payouts.data",
            "where": {
              "all": [
                {
                  "path": "status",
                  "in": [
                    "pending",
                    "in_transit"
                  ]
                },
                {
                  "path": "currency",
                  "equals": {
                    "answer": "cur"
                  }
                }
              ]
            }
          }
        },
        {
          "name": "next_amount",
          "value": {
            "multiply": [
              {
                "first": "amount",
                "of": "payouts.data",
                "where": {
                  "all": [
                    {
                      "path": "status",
                      "in": [
                        "pending",
                        "in_transit"
                      ]
                    },
                    {
                      "path": "currency",
                      "equals": {
                        "answer": "cur"
                      }
                    }
                  ]
                },
                "sort": "arrival_date"
              },
              "scale"
            ],
            "round": 3
          }
        },
        {
          "name": "next_day",
          "value": {
            "date": {
              "first": "arrival_date",
              "of": "payouts.data",
              "where": {
                "all": [
                  {
                    "path": "status",
                    "in": [
                      "pending",
                      "in_transit"
                    ]
                  },
                  {
                    "path": "currency",
                    "equals": {
                      "answer": "cur"
                    }
                  }
                ]
              },
              "sort": "arrival_date"
            },
            "match": "^[0-9]{4}-[0-9]{2}-[0-9]{2}"
          }
        },
        {
          "name": "payout_failed",
          "value": {
            "path": "payouts.data[0].status",
            "values": {
              "failed": 1
            },
            "default": 0
          }
        },
        {
          "name": "po_cur",
          "value": {
            "path": "payouts.data[0].currency",
            "default": {
              "template": "{cur}"
            }
          }
        },
        {
          "name": "po_scale",
          "value": {
            "path": "po_cur",
            "values": {
              "bif": 1,
              "clp": 1,
              "djf": 1,
              "gnf": 1,
              "jpy": 1,
              "kmf": 1,
              "krw": 1,
              "mga": 1,
              "pyg": 1,
              "rwf": 1,
              "vnd": 1,
              "vuv": 1,
              "xaf": 1,
              "xof": 1,
              "xpf": 1,
              "bhd": 0.001,
              "jod": 0.001,
              "kwd": 0.001,
              "omr": 0.001,
              "tnd": 0.001
            },
            "default": 0.01
          }
        },
        {
          "name": "po_dec",
          "value": {
            "path": "po_cur",
            "values": {
              "bif": 0,
              "clp": 0,
              "djf": 0,
              "gnf": 0,
              "jpy": 0,
              "kmf": 0,
              "krw": 0,
              "mga": 0,
              "pyg": 0,
              "rwf": 0,
              "vnd": 0,
              "vuv": 0,
              "xaf": 0,
              "xof": 0,
              "xpf": 0,
              "bhd": 3,
              "jod": 3,
              "kwd": 3,
              "omr": 3,
              "tnd": 3
            },
            "default": 2
          }
        },
        {
          "name": "po_sym",
          "value": {
            "path": "po_cur",
            "values": {
              "usd": "$",
              "eur": "€",
              "gbp": "£",
              "jpy": "¥",
              "inr": "₹",
              "krw": "₩",
              "cad": "CA$",
              "aud": "A$",
              "nzd": "NZ$",
              "hkd": "HK$",
              "sgd": "S$",
              "mxn": "MX$",
              "brl": "R$"
            },
            "default": {
              "template": "{po_cur|upper} "
            }
          }
        },
        {
          "name": "failed_payout_amount",
          "value": {
            "multiply": [
              "payouts.data[0].amount",
              "po_scale"
            ],
            "round": 3
          }
        },
        {
          "name": "failed_payout_money",
          "value": {
            "if": {
              "path": "po_dec",
              "equals": 0
            },
            "then": {
              "template": "{po_sym}{failed_payout_amount|round:0}"
            },
            "else": {
              "if": {
                "path": "po_dec",
                "equals": 3
              },
              "then": {
                "template": "{po_sym}{failed_payout_amount|round:3}"
              },
              "else": {
                "template": "{po_sym}{failed_payout_amount|round:2}"
              }
            }
          }
        },
        {
          "name": "failed_payout_words",
          "value": {
            "if": {
              "path": "payouts.data[0].failure_message",
              "exists": true
            },
            "then": {
              "template": "Payout of {failed_payout_money} failed: {payouts.data[0].failure_message}"
            },
            "else": {
              "template": "Payout of {failed_payout_money} failed"
            }
          }
        },
        {
          "name": "waiting",
          "value": {
            "count": "disputes.data",
            "where": {
              "path": "status",
              "in": [
                "needs_response",
                "warning_needs_response"
              ]
            }
          }
        },
        {
          "name": "disputes_cut",
          "value": {
            "path": "disputes.has_more",
            "values": {
              "true": "yes"
            }
          }
        },
        {
          "name": "first_due",
          "value": {
            "min": "evidence_details.due_by",
            "of": "disputes.data",
            "where": {
              "path": "status",
              "in": [
                "needs_response",
                "warning_needs_response"
              ]
            }
          }
        },
        {
          "name": "due_since",
          "value": {
            "since": "first_due"
          }
        },
        {
          "name": "waiting_words",
          "value": {
            "if": {
              "path": "disputes_cut",
              "exists": true
            },
            "then": {
              "template": "At least {waiting} disputes need a response; Stripe has more than 500"
            },
            "else": {
              "if": {
                "path": "waiting",
                "equals": 1
              },
              "then": {
                "template": "1 dispute needs a response by {first_due|day}"
              },
              "else": {
                "template": "{waiting} disputes need a response, the first by {first_due|day}"
              }
            }
          }
        },
        {
          "name": "paused",
          "value": {
            "if": {
              "path": "account.charges_enabled",
              "equals": false
            },
            "then": {
              "template": "Payments are off on this account"
            },
            "else": {
              "if": {
                "path": "account.payouts_enabled",
                "equals": false
              },
              "then": {
                "template": "Payouts are off on this account"
              }
            }
          }
        },
        {
          "name": "dispute_rows",
          "value": {
            "each": "disputes.data",
            "where": {
              "path": "status",
              "in": [
                "needs_response",
                "warning_needs_response"
              ]
            },
            "sort": "evidence_details.due_by",
            "fields": {
              "id": "id",
              "livemode": "livemode",
              "currency": "currency",
              "amount": "amount",
              "reason": "reason",
              "due": "evidence_details.due_by",
              "who": {
                "path": "evidence.customer_name",
                "default": {
                  "template": "A customer"
                }
              },
              "scale": {
                "path": "currency",
                "values": {
                  "bif": 1,
                  "clp": 1,
                  "djf": 1,
                  "gnf": 1,
                  "jpy": 1,
                  "kmf": 1,
                  "krw": 1,
                  "mga": 1,
                  "pyg": 1,
                  "rwf": 1,
                  "vnd": 1,
                  "vuv": 1,
                  "xaf": 1,
                  "xof": 1,
                  "xpf": 1,
                  "bhd": 0.001,
                  "jod": 0.001,
                  "kwd": 0.001,
                  "omr": 0.001,
                  "tnd": 0.001
                },
                "default": 0.01
              },
              "dec": {
                "path": "currency",
                "values": {
                  "bif": 0,
                  "clp": 0,
                  "djf": 0,
                  "gnf": 0,
                  "jpy": 0,
                  "kmf": 0,
                  "krw": 0,
                  "mga": 0,
                  "pyg": 0,
                  "rwf": 0,
                  "vnd": 0,
                  "vuv": 0,
                  "xaf": 0,
                  "xof": 0,
                  "xpf": 0,
                  "bhd": 3,
                  "jod": 3,
                  "kwd": 3,
                  "omr": 3,
                  "tnd": 3
                },
                "default": 2
              },
              "sym": {
                "path": "currency",
                "values": {
                  "usd": "$",
                  "eur": "€",
                  "gbp": "£",
                  "jpy": "¥",
                  "inr": "₹",
                  "krw": "₩",
                  "cad": "CA$",
                  "aud": "A$",
                  "nzd": "NZ$",
                  "hkd": "HK$",
                  "sgd": "S$",
                  "mxn": "MX$",
                  "brl": "R$"
                },
                "default": {
                  "template": "{currency|upper} "
                }
              }
            }
          }
        },
        {
          "name": "dispute_list",
          "value": {
            "each": "dispute_rows",
            "fields": {
              "key": "id",
              "text": "who",
              "subtitle": {
                "template": "{reason|title}"
              },
              "units": {
                "multiply": [
                  "amount",
                  "scale"
                ],
                "round": 3
              },
              "due": "due",
              "sym": "sym",
              "dec": "dec",
              "livemode": "livemode",
              "id": "id"
            }
          }
        }
      ]
    },
    "billing": {
      "url": "https://api.stripe.com",
      "secret": "stripe",
      "every": "5m",
      "headers": {
        "Stripe-Version": "2026-09-30.endive"
      },
      "requests": {
        "account": "/v1/account",
        "active": "/v1/subscriptions/search?query=status:'active'&limit=1&expand[]=total_count",
        "past_due": "/v1/subscriptions/search?query=status:'past_due'&limit=1&expand[]=total_count",
        "open": {
          "path": "/v1/invoices?status=open&limit=100",
          "follow": {
            "items": "data",
            "while": "has_more",
            "param": "starting_after",
            "from_last": "id",
            "max": 5
          }
        }
      },
      "derive": [
        {
          "name": "cur",
          "value": {
            "path": "account.default_currency",
            "default": "usd"
          }
        },
        {
          "name": "unit",
          "value": {
            "template": "{cur|upper}"
          }
        },
        {
          "name": "scale",
          "value": {
            "path": "cur",
            "values": {
              "bif": 1,
              "clp": 1,
              "djf": 1,
              "gnf": 1,
              "jpy": 1,
              "kmf": 1,
              "krw": 1,
              "mga": 1,
              "pyg": 1,
              "rwf": 1,
              "vnd": 1,
              "vuv": 1,
              "xaf": 1,
              "xof": 1,
              "xpf": 1,
              "bhd": 0.001,
              "jod": 0.001,
              "kwd": 0.001,
              "omr": 0.001,
              "tnd": 0.001
            },
            "default": 0.01
          }
        },
        {
          "name": "dec",
          "value": {
            "path": "cur",
            "values": {
              "bif": 0,
              "clp": 0,
              "djf": 0,
              "gnf": 0,
              "jpy": 0,
              "kmf": 0,
              "krw": 0,
              "mga": 0,
              "pyg": 0,
              "rwf": 0,
              "vnd": 0,
              "vuv": 0,
              "xaf": 0,
              "xof": 0,
              "xpf": 0,
              "bhd": 3,
              "jod": 3,
              "kwd": 3,
              "omr": 3,
              "tnd": 3
            },
            "default": 2
          }
        },
        {
          "name": "sym",
          "value": {
            "path": "cur",
            "values": {
              "usd": "$",
              "eur": "€",
              "gbp": "£",
              "jpy": "¥",
              "inr": "₹",
              "krw": "₩",
              "cad": "CA$",
              "aud": "A$",
              "nzd": "NZ$",
              "hkd": "HK$",
              "sgd": "S$",
              "mxn": "MX$",
              "brl": "R$"
            },
            "default": {
              "template": "{cur|upper} "
            }
          }
        },
        {
          "name": "open_cut",
          "value": {
            "path": "open.has_more",
            "values": {
              "true": "yes"
            }
          }
        },
        {
          "name": "schedule",
          "value": {
            "path": "account.settings.payouts.schedule.interval",
            "values": {
              "daily": "Daily",
              "weekly": "Weekly",
              "monthly": "Monthly",
              "manual": "Manual"
            }
          }
        },
        {
          "name": "schedule_words",
          "value": {
            "if": {
              "path": "account.settings.payouts.schedule.interval",
              "equals": "manual"
            },
            "then": {
              "template": "Manual"
            },
            "else": {
              "if": {
                "path": "account.settings.payouts.schedule.delay_days",
                "exists": true
              },
              "then": {
                "template": "{schedule} · {account.settings.payouts.schedule.delay_days}-day delay"
              },
              "else": {
                "template": "{schedule}"
              }
            }
          }
        },
        {
          "name": "active_n",
          "value": {
            "if": {
              "path": "active.total_count",
              "gte": 10000
            },
            "then": {
              "template": "10,000+"
            },
            "else": {
              "template": "{active.total_count}"
            }
          }
        },
        {
          "name": "past_due_n",
          "value": {
            "if": {
              "path": "past_due.total_count",
              "gte": 10000
            },
            "then": {
              "template": "10,000+"
            },
            "else": {
              "template": "{past_due.total_count}"
            }
          }
        },
        {
          "name": "subs_words",
          "value": {
            "if": {
              "path": "past_due.total_count",
              "gt": 0
            },
            "then": {
              "template": "{active_n} active · {past_due_n} past due"
            },
            "else": {
              "template": "{active_n} active"
            }
          }
        },
        {
          "name": "open_rows",
          "value": {
            "each": "open.data",
            "where": {
              "path": "currency",
              "equals": {
                "answer": "cur"
              }
            },
            "fields": {
              "amount_remaining": "amount_remaining",
              "late": {
                "since": "due_date"
              }
            }
          }
        },
        {
          "name": "open_count",
          "value": {
            "count": "open_rows"
          }
        },
        {
          "name": "open_owed",
          "value": {
            "multiply": [
              {
                "sum": "amount_remaining",
                "of": "open_rows",
                "default": 0
              },
              "scale"
            ],
            "round": 3
          }
        },
        {
          "name": "open_money",
          "value": {
            "if": {
              "path": "dec",
              "equals": 0
            },
            "then": {
              "template": "{sym}{open_owed|round:0}"
            },
            "else": {
              "if": {
                "path": "dec",
                "equals": 3
              },
              "then": {
                "template": "{sym}{open_owed|round:3}"
              },
              "else": {
                "template": "{sym}{open_owed|round:2}"
              }
            }
          }
        },
        {
          "name": "overdue",
          "value": {
            "count": "open_rows",
            "where": {
              "path": "late",
              "gt": 0
            }
          }
        },
        {
          "name": "open_words",
          "value": {
            "if": {
              "path": "open_cut",
              "exists": true
            },
            "then": {
              "template": "At least {open_money} · more than 500"
            },
            "else": {
              "if": {
                "path": "open_count",
                "equals": 0
              },
              "then": {
                "template": "None"
              },
              "else": {
                "if": {
                  "path": "overdue",
                  "gt": 0
                },
                "then": {
                  "template": "{open_money} · {overdue} overdue"
                },
                "else": {
                  "template": "{open_money} · {open_count} open"
                }
              }
            }
          }
        }
      ]
    },
    "money": {
      "url": "https://api.stripe.com",
      "secret": "stripe",
      "every": "15m",
      "headers": {
        "Stripe-Version": "2026-09-30.endive"
      },
      "requests": {
        "account": "/v1/account",
        "moves": {
          "path": "/v1/balance_transactions?created[gte]={period.start_unix}&created[lt]={period.end_unix}&limit=100",
          "follow": {
            "items": "data",
            "while": "has_more",
            "param": "starting_after",
            "from_last": "id",
            "max": 20
          }
        }
      },
      "derive": [
        {
          "name": "cur",
          "value": {
            "path": "account.default_currency",
            "default": "usd"
          }
        },
        {
          "name": "unit",
          "value": {
            "template": "{cur|upper}"
          }
        },
        {
          "name": "scale",
          "value": {
            "path": "cur",
            "values": {
              "bif": 1,
              "clp": 1,
              "djf": 1,
              "gnf": 1,
              "jpy": 1,
              "kmf": 1,
              "krw": 1,
              "mga": 1,
              "pyg": 1,
              "rwf": 1,
              "vnd": 1,
              "vuv": 1,
              "xaf": 1,
              "xof": 1,
              "xpf": 1,
              "bhd": 0.001,
              "jod": 0.001,
              "kwd": 0.001,
              "omr": 0.001,
              "tnd": 0.001
            },
            "default": 0.01
          }
        },
        {
          "name": "dec",
          "value": {
            "path": "cur",
            "values": {
              "bif": 0,
              "clp": 0,
              "djf": 0,
              "gnf": 0,
              "jpy": 0,
              "kmf": 0,
              "krw": 0,
              "mga": 0,
              "pyg": 0,
              "rwf": 0,
              "vnd": 0,
              "vuv": 0,
              "xaf": 0,
              "xof": 0,
              "xpf": 0,
              "bhd": 3,
              "jod": 3,
              "kwd": 3,
              "omr": 3,
              "tnd": 3
            },
            "default": 2
          }
        },
        {
          "name": "sym",
          "value": {
            "path": "cur",
            "values": {
              "usd": "$",
              "eur": "€",
              "gbp": "£",
              "jpy": "¥",
              "inr": "₹",
              "krw": "₩",
              "cad": "CA$",
              "aud": "A$",
              "nzd": "NZ$",
              "hkd": "HK$",
              "sgd": "S$",
              "mxn": "MX$",
              "brl": "R$"
            },
            "default": {
              "template": "{cur|upper} "
            }
          }
        },
        {
          "name": "moves_cur",
          "value": {
            "each": "moves.data",
            "where": {
              "path": "currency",
              "equals": {
                "answer": "cur"
              }
            },
            "fields": {
              "created": "created",
              "amount": "amount",
              "fee": "fee",
              "net": "net",
              "reporting_category": "reporting_category",
              "units": {
                "multiply": [
                  "amount",
                  {
                    "path": "currency",
                    "values": {
                      "bif": 1,
                      "clp": 1,
                      "djf": 1,
                      "gnf": 1,
                      "jpy": 1,
                      "kmf": 1,
                      "krw": 1,
                      "mga": 1,
                      "pyg": 1,
                      "rwf": 1,
                      "vnd": 1,
                      "vuv": 1,
                      "xaf": 1,
                      "xof": 1,
                      "xpf": 1,
                      "bhd": 0.001,
                      "jod": 0.001,
                      "kwd": 0.001,
                      "omr": 0.001,
                      "tnd": 0.001
                    },
                    "default": 0.01
                  }
                ],
                "round": 3
              }
            }
          }
        },
        {
          "name": "days",
          "value": {
            "each": "moves_cur",
            "where": {
              "path": "reporting_category",
              "in": [
                "charge",
                "partial_capture_reversal",
                "charge_failure"
              ]
            },
            "by_day": {
              "at": "created",
              "from": "{period.start}",
              "through": "{period.through}"
            },
            "fields": {
              "day": "from",
              "gross": {
                "sum": "units",
                "of": "rows"
              },
              "count": "count"
            }
          }
        },
        {
          "name": "gross",
          "value": {
            "multiply": [
              {
                "sum": "amount",
                "of": "moves_cur",
                "where": {
                  "path": "reporting_category",
                  "in": [
                    "charge",
                    "partial_capture_reversal",
                    "charge_failure"
                  ]
                },
                "default": 0
              },
              "scale"
            ],
            "round": 3
          }
        },
        {
          "name": "payments",
          "value": {
            "count": "moves_cur",
            "where": {
              "path": "reporting_category",
              "equals": "charge"
            }
          }
        },
        {
          "name": "net",
          "value": {
            "multiply": [
              {
                "sum": "net",
                "of": "moves_cur",
                "where": {
                  "path": "reporting_category",
                  "in": [
                    "charge",
                    "partial_capture_reversal",
                    "charge_failure",
                    "refund",
                    "refund_failure",
                    "dispute",
                    "dispute_reversal",
                    "fee"
                  ]
                },
                "default": 0
              },
              "scale"
            ],
            "round": 3
          }
        },
        {
          "name": "fees",
          "value": {
            "multiply": [
              {
                "add": [
                  {
                    "sum": "fee",
                    "of": "moves_cur",
                    "default": 0
                  },
                  {
                    "sum": "amount",
                    "of": "moves_cur",
                    "where": {
                      "path": "reporting_category",
                      "equals": "fee"
                    },
                    "default": 0,
                    "scale": -1
                  }
                ]
              },
              "scale"
            ],
            "round": 3
          }
        },
        {
          "name": "refunded",
          "value": {
            "multiply": [
              {
                "sum": "amount",
                "of": "moves_cur",
                "where": {
                  "path": "reporting_category",
                  "in": [
                    "refund",
                    "refund_failure"
                  ]
                },
                "default": 0,
                "scale": -1
              },
              "scale"
            ],
            "round": 3
          }
        },
        {
          "name": "refunds",
          "value": {
            "count": "moves_cur",
            "where": {
              "path": "reporting_category",
              "equals": "refund"
            }
          }
        },
        {
          "name": "net_money",
          "value": {
            "if": {
              "path": "dec",
              "equals": 0
            },
            "then": {
              "template": "{sym}{net|round:0}"
            },
            "else": {
              "if": {
                "path": "dec",
                "equals": 3
              },
              "then": {
                "template": "{sym}{net|round:3}"
              },
              "else": {
                "template": "{sym}{net|round:2}"
              }
            }
          }
        },
        {
          "name": "fees_money",
          "value": {
            "if": {
              "path": "dec",
              "equals": 0
            },
            "then": {
              "template": "{sym}{fees|round:0}"
            },
            "else": {
              "if": {
                "path": "dec",
                "equals": 3
              },
              "then": {
                "template": "{sym}{fees|round:3}"
              },
              "else": {
                "template": "{sym}{fees|round:2}"
              }
            }
          }
        },
        {
          "name": "refunded_money",
          "value": {
            "if": {
              "path": "dec",
              "equals": 0
            },
            "then": {
              "template": "{sym}{refunded|round:0}"
            },
            "else": {
              "if": {
                "path": "dec",
                "equals": 3
              },
              "then": {
                "template": "{sym}{refunded|round:3}"
              },
              "else": {
                "template": "{sym}{refunded|round:2}"
              }
            }
          }
        },
        {
          "name": "refund_words",
          "value": {
            "if": {
              "path": "refunds",
              "equals": 0
            },
            "then": {
              "template": "None"
            },
            "else": {
              "template": "{refunded_money} · {refunds}"
            }
          }
        }
      ]
    },
    "recent": {
      "url": "https://api.stripe.com",
      "secret": "stripe",
      "every": "5m",
      "headers": {
        "Stripe-Version": "2026-09-30.endive"
      },
      "requests": {
        "payments": "/v1/charges?limit=4&expand[]=data.customer",
        "events": "/v1/events?limit=20&types[]=charge.failed&types[]=refund.created&types[]=charge.dispute.created&types[]=customer.subscription.created&types[]=customer.subscription.deleted&types[]=invoice.payment_failed&types[]=payout.paid&types[]=payout.failed"
      },
      "derive": [
        {
          "name": "pay_rows",
          "value": {
            "each": "payments.data",
            "fields": {
              "id": "id",
              "livemode": "livemode",
              "status": "status",
              "created": "created",
              "pi": {
                "path": "payment_intent",
                "default": {
                  "template": "{id}"
                }
              },
              "who": {
                "if": {
                  "path": "customer.name",
                  "exists": true
                },
                "then": {
                  "template": "{customer.name}"
                },
                "else": {
                  "if": {
                    "path": "billing_details.name",
                    "exists": true
                  },
                  "then": {
                    "template": "{billing_details.name}"
                  },
                  "else": {
                    "if": {
                      "path": "customer.email",
                      "exists": true
                    },
                    "then": {
                      "template": "{customer.email}"
                    },
                    "else": {
                      "if": {
                        "path": "receipt_email",
                        "exists": true
                      },
                      "then": {
                        "template": "{receipt_email}"
                      },
                      "else": {
                        "template": "Payment"
                      }
                    }
                  }
                }
              },
              "what": {
                "if": {
                  "path": "description",
                  "exists": true
                },
                "then": {
                  "template": "{description}"
                },
                "else": {
                  "if": {
                    "path": "payment_method_details.card.last4",
                    "exists": true
                  },
                  "then": {
                    "template": "{payment_method_details.card.brand|title} ····{payment_method_details.card.last4}"
                  },
                  "else": {
                    "template": "{payment_method_details.type|title}"
                  }
                }
              },
              "why": {
                "if": {
                  "path": "outcome.reason",
                  "exists": true
                },
                "then": {
                  "template": "{outcome.reason|title}"
                },
                "else": {
                  "if": {
                    "path": "failure_code",
                    "exists": true
                  },
                  "then": {
                    "template": "{failure_code|title}"
                  },
                  "else": {
                    "template": "Failed"
                  }
                }
              },
              "units": {
                "if": {
                  "path": "captured",
                  "equals": false
                },
                "then": {
                  "multiply": [
                    "amount",
                    {
                      "path": "currency",
                      "values": {
                        "bif": 1,
                        "clp": 1,
                        "djf": 1,
                        "gnf": 1,
                        "jpy": 1,
                        "kmf": 1,
                        "krw": 1,
                        "mga": 1,
                        "pyg": 1,
                        "rwf": 1,
                        "vnd": 1,
                        "vuv": 1,
                        "xaf": 1,
                        "xof": 1,
                        "xpf": 1,
                        "bhd": 0.001,
                        "jod": 0.001,
                        "kwd": 0.001,
                        "omr": 0.001,
                        "tnd": 0.001
                      },
                      "default": 0.01
                    }
                  ],
                  "round": 3
                },
                "else": {
                  "if": {
                    "path": "amount_captured",
                    "exists": true
                  },
                  "then": {
                    "multiply": [
                      "amount_captured",
                      {
                        "path": "currency",
                        "values": {
                          "bif": 1,
                          "clp": 1,
                          "djf": 1,
                          "gnf": 1,
                          "jpy": 1,
                          "kmf": 1,
                          "krw": 1,
                          "mga": 1,
                          "pyg": 1,
                          "rwf": 1,
                          "vnd": 1,
                          "vuv": 1,
                          "xaf": 1,
                          "xof": 1,
                          "xpf": 1,
                          "bhd": 0.001,
                          "jod": 0.001,
                          "kwd": 0.001,
                          "omr": 0.001,
                          "tnd": 0.001
                        },
                        "default": 0.01
                      }
                    ],
                    "round": 3
                  },
                  "else": {
                    "multiply": [
                      "amount",
                      {
                        "path": "currency",
                        "values": {
                          "bif": 1,
                          "clp": 1,
                          "djf": 1,
                          "gnf": 1,
                          "jpy": 1,
                          "kmf": 1,
                          "krw": 1,
                          "mga": 1,
                          "pyg": 1,
                          "rwf": 1,
                          "vnd": 1,
                          "vuv": 1,
                          "xaf": 1,
                          "xof": 1,
                          "xpf": 1,
                          "bhd": 0.001,
                          "jod": 0.001,
                          "kwd": 0.001,
                          "omr": 0.001,
                          "tnd": 0.001
                        },
                        "default": 0.01
                      }
                    ],
                    "round": 3
                  }
                }
              },
              "refund_units": {
                "multiply": [
                  "amount_refunded",
                  {
                    "path": "currency",
                    "values": {
                      "bif": 1,
                      "clp": 1,
                      "djf": 1,
                      "gnf": 1,
                      "jpy": 1,
                      "kmf": 1,
                      "krw": 1,
                      "mga": 1,
                      "pyg": 1,
                      "rwf": 1,
                      "vnd": 1,
                      "vuv": 1,
                      "xaf": 1,
                      "xof": 1,
                      "xpf": 1,
                      "bhd": 0.001,
                      "jod": 0.001,
                      "kwd": 0.001,
                      "omr": 0.001,
                      "tnd": 0.001
                    },
                    "default": 0.01
                  }
                ],
                "round": 3
              },
              "refunded_some": {
                "if": {
                  "path": "amount_refunded",
                  "gt": 0
                },
                "then": {
                  "template": "yes"
                }
              },
              "refunded": "refunded",
              "disputed": "disputed",
              "captured": {
                "path": "captured",
                "default": true
              },
              "sym": {
                "path": "currency",
                "values": {
                  "usd": "$",
                  "eur": "€",
                  "gbp": "£",
                  "jpy": "¥",
                  "inr": "₹",
                  "krw": "₩",
                  "cad": "CA$",
                  "aud": "A$",
                  "nzd": "NZ$",
                  "hkd": "HK$",
                  "sgd": "S$",
                  "mxn": "MX$",
                  "brl": "R$"
                },
                "default": {
                  "template": "{currency|upper} "
                }
              },
              "dec": {
                "path": "currency",
                "values": {
                  "bif": 0,
                  "clp": 0,
                  "djf": 0,
                  "gnf": 0,
                  "jpy": 0,
                  "kmf": 0,
                  "krw": 0,
                  "mga": 0,
                  "pyg": 0,
                  "rwf": 0,
                  "vnd": 0,
                  "vuv": 0,
                  "xaf": 0,
                  "xof": 0,
                  "xpf": 0,
                  "bhd": 3,
                  "jod": 3,
                  "kwd": 3,
                  "omr": 3,
                  "tnd": 3
                },
                "default": 2
              }
            }
          }
        },
        {
          "name": "pay_list",
          "value": {
            "each": "pay_rows",
            "fields": {
              "id": "id",
              "who": "who",
              "what": "what",
              "why": "why",
              "status": "status",
              "disputed": "disputed",
              "refunded": "refunded",
              "captured": "captured",
              "refunded_some": "refunded_some",
              "created": "created",
              "livemode": "livemode",
              "pi": "pi",
              "units": "units",
              "refund_units": "refund_units",
              "sym": "sym",
              "dec": "dec",
              "money": {
                "if": {
                  "path": "dec",
                  "equals": 0
                },
                "then": {
                  "template": "{sym}{units|round:0}"
                },
                "else": {
                  "if": {
                    "path": "dec",
                    "equals": 3
                  },
                  "then": {
                    "template": "{sym}{units|round:3}"
                  },
                  "else": {
                    "template": "{sym}{units|round:2}"
                  }
                }
              },
              "refund_money": {
                "if": {
                  "path": "dec",
                  "equals": 0
                },
                "then": {
                  "template": "{sym}{refund_units|round:0}"
                },
                "else": {
                  "if": {
                    "path": "dec",
                    "equals": 3
                  },
                  "then": {
                    "template": "{sym}{refund_units|round:3}"
                  },
                  "else": {
                    "template": "{sym}{refund_units|round:2}"
                  }
                }
              }
            }
          }
        },
        {
          "name": "pay_count",
          "value": {
            "count": "pay_list"
          }
        },
        {
          "name": "event_rows",
          "value": {
            "each": "events.data",
            "fields": {
              "id": "id",
              "type": "type",
              "created": "created",
              "o": "data.object",
              "scale": {
                "path": "data.object.currency",
                "values": {
                  "bif": 1,
                  "clp": 1,
                  "djf": 1,
                  "gnf": 1,
                  "jpy": 1,
                  "kmf": 1,
                  "krw": 1,
                  "mga": 1,
                  "pyg": 1,
                  "rwf": 1,
                  "vnd": 1,
                  "vuv": 1,
                  "xaf": 1,
                  "xof": 1,
                  "xpf": 1,
                  "bhd": 0.001,
                  "jod": 0.001,
                  "kwd": 0.001,
                  "omr": 0.001,
                  "tnd": 0.001
                },
                "default": 0.01
              },
              "dec": {
                "path": "data.object.currency",
                "values": {
                  "bif": 0,
                  "clp": 0,
                  "djf": 0,
                  "gnf": 0,
                  "jpy": 0,
                  "kmf": 0,
                  "krw": 0,
                  "mga": 0,
                  "pyg": 0,
                  "rwf": 0,
                  "vnd": 0,
                  "vuv": 0,
                  "xaf": 0,
                  "xof": 0,
                  "xpf": 0,
                  "bhd": 3,
                  "jod": 3,
                  "kwd": 3,
                  "omr": 3,
                  "tnd": 3
                },
                "default": 2
              },
              "sym": {
                "path": "data.object.currency",
                "values": {
                  "usd": "$",
                  "eur": "€",
                  "gbp": "£",
                  "jpy": "¥",
                  "inr": "₹",
                  "krw": "₩",
                  "cad": "CA$",
                  "aud": "A$",
                  "nzd": "NZ$",
                  "hkd": "HK$",
                  "sgd": "S$",
                  "mxn": "MX$",
                  "brl": "R$"
                },
                "default": {
                  "template": "{data.object.currency|upper} "
                }
              }
            }
          }
        },
        {
          "name": "event_list",
          "value": {
            "each": "event_rows",
            "fields": {
              "id": "id",
              "type": "type",
              "created": "created",
              "sym": "sym",
              "dec": "dec",
              "units": {
                "if": {
                  "path": "type",
                  "in": [
                    "customer.subscription.created",
                    "customer.subscription.deleted"
                  ]
                },
                "then": {
                  "if": {
                    "all": [
                      {
                        "path": "o.quantity",
                        "equals": 1
                      },
                      {
                        "path": "o.items.total_count",
                        "equals": 1
                      },
                      {
                        "path": "o.plan.interval_count",
                        "equals": 1
                      }
                    ]
                  },
                  "then": {
                    "multiply": [
                      "o.plan.amount",
                      "scale"
                    ]
                  }
                },
                "else": {
                  "if": {
                    "path": "type",
                    "equals": "invoice.payment_failed"
                  },
                  "then": {
                    "multiply": [
                      "o.amount_due",
                      "scale"
                    ]
                  },
                  "else": {
                    "multiply": [
                      "o.amount",
                      "scale"
                    ]
                  }
                }
              },
              "who": {
                "if": {
                  "path": "o.billing_details.name",
                  "exists": true
                },
                "then": {
                  "template": "{o.billing_details.name}"
                },
                "else": {
                  "if": {
                    "path": "o.evidence.customer_name",
                    "exists": true
                  },
                  "then": {
                    "template": "{o.evidence.customer_name}"
                  },
                  "else": {
                    "if": {
                      "path": "o.customer_email",
                      "exists": true
                    },
                    "then": {
                      "template": "{o.customer_email}"
                    }
                  }
                }
              },
              "every": {
                "path": "o.plan.interval",
                "values": {
                  "day": " a day",
                  "week": " a week",
                  "month": " a month",
                  "year": " a year"
                },
                "default": ""
              }
            }
          }
        },
        {
          "name": "event_count",
          "value": {
            "count": "event_list"
          }
        }
      ]
    }
  },
  "cards": [
    {
      "id": "health",
      "type": "status",
      "placement": "page_info",
      "label": "Stripe",
      "state": "unknown",
      "width": "full",
      "url": "https://dashboard.stripe.com",
      "source": {
        "ref": "account",
        "map": {
          "state": {
            "if": {
              "path": "account.id",
              "exists": false
            },
            "then": {
              "template": "unknown"
            },
            "else": {
              "if": {
                "path": "paused",
                "exists": true
              },
              "then": {
                "template": "critical"
              },
              "else": {
                "if": {
                  "path": "payout_failed",
                  "equals": 1
                },
                "then": {
                  "template": "critical"
                },
                "else": {
                  "if": {
                    "path": "waiting",
                    "gt": 0
                  },
                  "then": {
                    "if": {
                      "path": "due_since",
                      "gt": -172800
                    },
                    "then": {
                      "template": "critical"
                    },
                    "else": {
                      "template": "warning"
                    }
                  },
                  "else": {
                    "if": {
                      "path": "disputes_cut",
                      "exists": true
                    },
                    "then": {
                      "template": "warning"
                    },
                    "else": {
                      "template": "ok"
                    }
                  }
                }
              }
            }
          },
          "detail": {
            "if": {
              "path": "account.id",
              "exists": false
            },
            "then": {
              "template": "Stripe didn't send the account"
            },
            "else": {
              "if": {
                "path": "paused",
                "exists": true
              },
              "then": {
                "template": "{paused}"
              },
              "else": {
                "if": {
                  "path": "payout_failed",
                  "equals": 1
                },
                "then": {
                  "template": "{failed_payout_words|clip:110}"
                },
                "else": {
                  "if": {
                    "path": "waiting",
                    "gt": 0
                  },
                  "then": {
                    "template": "{waiting_words}"
                  },
                  "else": {
                    "if": {
                      "path": "disputes_cut",
                      "exists": true
                    },
                    "then": {
                      "template": "Stripe has more than 500 disputes; check them in Stripe"
                    },
                    "else": {
                      "template": "Payments and payouts on · No disputes waiting"
                    }
                  }
                }
              }
            }
          }
        },
        "failed": {
          "state": "critical",
          "detail": "Stripe isn't answering",
          "after": 3
        }
      }
    },
    {
      "id": "available",
      "type": "stat",
      "label": "Available",
      "value": "—",
      "source": {
        "ref": "account",
        "map": {
          "value": "available",
          "unit": "unit",
          "delta": {
            "if": {
              "path": "pending",
              "gt": 0
            },
            "then": {
              "template": "{pending_words} pending"
            },
            "else": {
              "template": "None pending"
            }
          }
        }
      }
    },
    {
      "id": "payout",
      "type": "stat",
      "label": "Next payout",
      "value": "—",
      "source": {
        "ref": "account",
        "map": {
          "value": {
            "if": {
              "path": "next_count",
              "gt": 0
            },
            "then": "next_amount",
            "else": {
              "template": "—"
            }
          },
          "unit": "unit",
          "delta": {
            "if": {
              "path": "next_count",
              "gt": 0
            },
            "then": {
              "template": "{next_day|day}"
            },
            "else": {
              "template": "None on the way"
            }
          }
        }
      }
    },
    {
      "id": "volume",
      "type": "sparkline",
      "label": "Gross volume",
      "points": [
        0,
        0
      ],
      "change": false,
      "shape": "sharp",
      "source": {
        "ref": "money",
        "map": {
          "label": {
            "if": {
              "path": "moves.has_more",
              "equals": true
            },
            "then": {
              "template": "Gross volume · newest 2,000 movements"
            },
            "else": {
              "template": "Gross volume"
            }
          },
          "unit": "unit",
          "points": {
            "each": "days",
            "value": {
              "path": "gross",
              "round": 3
            },
            "running": true
          },
          "labels": {
            "each": "days",
            "template": "{day|date}"
          }
        }
      }
    },
    {
      "id": "month",
      "type": "facts",
      "items": [
        {
          "key": "Net after fees",
          "value": "—",
          "url": "legato://page/stripe-payments"
        },
        {
          "key": "Fees",
          "value": "—",
          "url": "legato://page/stripe-payments"
        },
        {
          "key": "Refunds",
          "value": "—",
          "url": "legato://page/stripe-payments"
        }
      ],
      "source": {
        "ref": "money",
        "map": {
          "label": {
            "if": {
              "path": "moves.has_more",
              "equals": true
            },
            "then": {
              "template": "Newest 2,000 movements"
            }
          },
          "items[0].value": "net_money",
          "items[1].value": "fees_money",
          "items[2].value": "refund_words"
        }
      }
    },
    {
      "id": "account",
      "type": "facts",
      "label": "Account",
      "items": [
        {
          "key": "Subscriptions",
          "value": "—"
        },
        {
          "key": "Open invoices",
          "value": "—"
        },
        {
          "key": "Payouts",
          "value": "—"
        }
      ],
      "source": {
        "ref": "billing",
        "map": {
          "items[0].value": "subs_words",
          "items[1].value": "open_words",
          "items[2].value": "schedule_words"
        }
      }
    },
    {
      "id": "disputes",
      "type": "list",
      "label": "Disputes",
      "max_items": 4,
      "items": [],
      "source": {
        "ref": "account",
        "when": {
          "path": "waiting",
          "gt": 0
        },
        "map": {
          "items": {
            "each": "dispute_list",
            "fields": {
              "key": "key",
              "text": "text",
              "subtitle": "subtitle",
              "detail": {
                "if": {
                  "path": "dec",
                  "equals": 0
                },
                "then": {
                  "template": "{sym}{units|round:0} · by {due|day}"
                },
                "else": {
                  "if": {
                    "path": "dec",
                    "equals": 3
                  },
                  "then": {
                    "template": "{sym}{units|round:3} · by {due|day}"
                  },
                  "else": {
                    "template": "{sym}{units|round:2} · by {due|day}"
                  }
                }
              },
              "url": {
                "if": {
                  "path": "livemode",
                  "equals": false
                },
                "then": {
                  "template": "https://dashboard.stripe.com/test/disputes/{id}"
                },
                "else": {
                  "template": "https://dashboard.stripe.com/disputes/{id}"
                }
              }
            }
          }
        }
      }
    },
    {
      "id": "payments",
      "type": "list",
      "label": "Payments",
      "max_items": 4,
      "items": [],
      "actions": [
        {
          "kind": "open",
          "label": "All payments",
          "icon": "list.bullet",
          "url": "legato://page/stripe-payments"
        }
      ],
      "actions_placement": "corner",
      "source": {
        "ref": "recent",
        "empty": {
          "text": "No payments yet",
          "when": {
            "path": "pay_count",
            "equals": 0
          }
        },
        "map": {
          "items": {
            "each": "pay_list",
            "fields": {
              "key": "id",
              "text": "who",
              "subtitle": {
                "if": {
                  "path": "status",
                  "equals": "failed"
                },
                "then": {
                  "template": "Failed · {why}"
                },
                "else": {
                  "if": {
                    "path": "disputed",
                    "equals": true
                  },
                  "then": {
                    "template": "Disputed · {what}"
                  },
                  "else": {
                    "if": {
                      "path": "refunded",
                      "equals": true
                    },
                    "then": {
                      "template": "Refunded · {what}"
                    },
                    "else": {
                      "if": {
                        "path": "refunded_some",
                        "exists": true
                      },
                      "then": {
                        "template": "{refund_money} refunded · {what}"
                      },
                      "else": {
                        "if": {
                          "path": "status",
                          "equals": "pending"
                        },
                        "then": {
                          "template": "Pending · {what}"
                        },
                        "else": {
                          "if": {
                            "path": "captured",
                            "equals": false
                          },
                          "then": {
                            "template": "Not captured · {what}"
                          },
                          "else": {
                            "template": "{what}"
                          }
                        }
                      }
                    }
                  }
                }
              },
              "detail": {
                "template": "{money} · {created|ago}"
              },
              "url": {
                "if": {
                  "path": "livemode",
                  "equals": false
                },
                "then": {
                  "template": "https://dashboard.stripe.com/test/payments/{pi}"
                },
                "else": {
                  "template": "https://dashboard.stripe.com/payments/{pi}"
                }
              }
            }
          }
        }
      }
    },
    {
      "id": "activity",
      "type": "list",
      "label": "Activity",
      "max_items": 4,
      "items": [],
      "source": {
        "ref": "recent",
        "empty": {
          "text": "Nothing in the last 30 days",
          "when": {
            "path": "event_count",
            "equals": 0
          }
        },
        "map": {
          "items": {
            "each": "event_list",
            "fields": {
              "key": "id",
              "icon": {
                "path": "type",
                "values": {
                  "charge.failed": "xmark.circle",
                  "refund.created": "arrow.uturn.backward.circle",
                  "charge.dispute.created": "exclamationmark.bubble",
                  "customer.subscription.created": "person.crop.circle.badge.plus",
                  "customer.subscription.deleted": "person.crop.circle.badge.minus",
                  "invoice.payment_failed": "doc.text",
                  "payout.paid": "building.columns",
                  "payout.failed": "building.columns"
                },
                "default": {
                  "template": "{type}"
                }
              },
              "text": {
                "path": "type",
                "values": {
                  "charge.failed": "Payment failed",
                  "refund.created": "Refund created",
                  "charge.dispute.created": "Dispute opened",
                  "customer.subscription.created": "New subscription",
                  "customer.subscription.deleted": "Subscription ended",
                  "invoice.payment_failed": "Invoice payment failed",
                  "payout.paid": "Payout paid",
                  "payout.failed": "Payout failed"
                },
                "default": {
                  "template": "{type}"
                }
              },
              "subtitle": {
                "if": {
                  "path": "units",
                  "exists": true
                },
                "then": {
                  "if": {
                    "path": "who",
                    "exists": true
                  },
                  "then": {
                    "if": {
                      "path": "dec",
                      "equals": 0
                    },
                    "then": {
                      "template": "{who} · {sym}{units|round:0}{every}"
                    },
                    "else": {
                      "if": {
                        "path": "dec",
                        "equals": 3
                      },
                      "then": {
                        "template": "{who} · {sym}{units|round:3}{every}"
                      },
                      "else": {
                        "template": "{who} · {sym}{units|round:2}{every}"
                      }
                    }
                  },
                  "else": {
                    "if": {
                      "path": "dec",
                      "equals": 0
                    },
                    "then": {
                      "template": "{sym}{units|round:0}{every}"
                    },
                    "else": {
                      "if": {
                        "path": "dec",
                        "equals": 3
                      },
                      "then": {
                        "template": "{sym}{units|round:3}{every}"
                      },
                      "else": {
                        "template": "{sym}{units|round:2}{every}"
                      }
                    }
                  }
                },
                "else": {
                  "if": {
                    "path": "who",
                    "exists": true
                  },
                  "then": {
                    "template": "{who}"
                  }
                }
              },
              "detail": {
                "template": "{created|ago}"
              }
            }
          }
        }
      }
    }
  ]
}
