#!/usr/bin/env bash # ============================================================================ # BLACKROAD OS, INC. - PROPRIETARY AND CONFIDENTIAL # BlackRoad Revenue Dashboard # Real-time Stripe metrics and business intelligence # ============================================================================ set -e # Color functions (printf-based, escape-safe) c_pink() { printf '\033[38;5;205m'; } c_blue() { printf '\033[38;5;75m'; } c_green() { printf '\033[38;5;82m'; } c_yellow() { printf '\033[38;5;226m'; } c_red() { printf '\033[38;5;196m'; } c_purple() { printf '\033[38;5;141m'; } c_orange() { printf '\033[38;5;208m'; } c_gray() { printf '\033[38;5;240m'; } c_cyan() { printf '\033[38;5;87m'; } c_reset() { printf '\033[0m'; } c_clear() { printf '\033[2J\033[H'; } c_bold() { printf '\033[1m'; } # Check for Stripe CLI check_stripe_cli() { if ! command -v stripe >/dev/null 2>&1; then return 1 fi return 0 } # Check for jq check_jq() { if ! command -v jq >/dev/null 2>&1; then return 1 fi return 0 } # ================== # STRIPE DATA COLLECTORS # ================== get_stripe_balance() { if check_stripe_cli; then stripe balance retrieve 2>/dev/null | jq -r '.available[0].amount // 0' | awk '{printf "%.2f", $1/100}' else echo "N/A" fi } get_recent_charges() { if check_stripe_cli && check_jq; then stripe charges list --limit 5 2>/dev/null | jq -r '.data[] | "\(.amount/100)|\(.currency)|\(.status)|\(.created)"' 2>/dev/null || echo "" else echo "" fi } get_customer_count() { if check_stripe_cli && check_jq; then stripe customers list --limit 100 2>/dev/null | jq '.data | length' 2>/dev/null || echo "0" else echo "0" fi } get_subscription_count() { if check_stripe_cli && check_jq; then stripe subscriptions list --limit 100 2>/dev/null | jq '.data | length' 2>/dev/null || echo "0" else echo "0" fi } get_mrr() { # Calculate MRR from active subscriptions if check_stripe_cli && check_jq; then stripe subscriptions list --status active --limit 100 2>/dev/null | \ jq '[.data[].items.data[].price.unit_amount] | add // 0' 2>/dev/null | \ awk '{printf "%.2f", $1/100}' || echo "0.00" else echo "0.00" fi } get_recent_payments() { if check_stripe_cli && check_jq; then stripe payment_intents list --limit 5 2>/dev/null | \ jq -r '.data[] | "\(.amount/100)|\(.currency)|\(.status)|\(.created)"' 2>/dev/null || echo "" else echo "" fi } # ================== # MOCK DATA (for demo when Stripe unavailable) # ================== generate_mock_balance() { echo "12847.50" } generate_mock_charges() { cat </dev/null || date -d "-${month} months" +"%b" 2>/dev/null || echo "M$month") local month_mrr=$(echo "$base_mrr + ($mrr - $base_mrr) * $month / 6" | bc | awk '{printf "%.0f", $1}') local bar_length=$(echo "$month_mrr / 100" | bc) printf " " c_gray; printf "%-5s" "$month_name"; c_reset printf " " c_green printf "%0.s▓" $(seq 1 $bar_length 2>/dev/null) c_reset printf " " c_cyan; printf "$%s" "$month_mrr"; c_reset printf "\n" done printf "\n" } draw_footer() { local mode="$1" local timestamp="$2" printf "\n" c_gray printf "═══════════════════════════════════════════════════════════════════════════════\n" if [[ "$mode" == "demo" ]]; then printf "Demo Mode (Mock Data) | Last updated: %s | Press Ctrl+C to exit\n" "$timestamp" else printf "Live Stripe Data | Last updated: %s | Press Ctrl+C to exit\n" "$timestamp" fi c_reset } draw_setup_notice() { c_clear c_yellow; c_bold printf "╔════════════════════════════════════════════════════════════════════════════════╗\n" printf "║ ⚠️ STRIPE CLI NOT CONFIGURED ║\n" printf "╚════════════════════════════════════════════════════════════════════════════════╝\n" c_reset printf "\n" printf "The Stripe CLI is not installed or not configured.\n" printf "\n" c_blue; printf "To use live data:\n"; c_reset printf " 1. Install Stripe CLI: brew install stripe/stripe-cli/stripe\n" printf " 2. Login: stripe login\n" printf " 3. Run this dashboard again\n" printf "\n" c_green; printf "Running in DEMO MODE with mock data...\n"; c_reset printf "\n" sleep 3 } # ================== # MAIN DASHBOARD # ================== run_dashboard() { local mode="live" local refresh_interval="${1:-10}" # Check dependencies if ! check_stripe_cli; then draw_setup_notice mode="demo" fi while true; do draw_header # Fetch or generate data local balance customers subscriptions mrr charges if [[ "$mode" == "demo" ]]; then balance=$(generate_mock_balance) customers=$(generate_mock_customers) subscriptions=$(generate_mock_subscriptions) mrr=$(generate_mock_mrr) charges=$(generate_mock_charges) else balance=$(get_stripe_balance) customers=$(get_customer_count) subscriptions=$(get_subscription_count) mrr=$(get_mrr) charges=$(get_recent_charges) fi # Draw sections draw_balance_card "$balance" draw_key_metrics "$customers" "$subscriptions" "$mrr" draw_recent_charges "$charges" draw_revenue_chart "$mrr" # Footer local timestamp=$(date "+%Y-%m-%d %H:%M:%S") draw_footer "$mode" "$timestamp" # Wait before refresh sleep "$refresh_interval" done } # ================== # CLI INTERFACE # ================== show_help() { cat <<'HELP' BlackRoad Revenue Dashboard USAGE: blackroad-revenue-dashboard.sh [OPTIONS] OPTIONS: --interval N Refresh interval in seconds (default: 10) --demo Force demo mode with mock data --once Run once and exit (no loop) --help Show this help EXAMPLES: blackroad-revenue-dashboard.sh # Live dashboard blackroad-revenue-dashboard.sh --demo # Demo mode blackroad-revenue-dashboard.sh --once # Single snapshot REQUIREMENTS: • Stripe CLI (brew install stripe/stripe-cli/stripe) • Authenticated with: stripe login • jq (brew install jq) METRICS SHOWN: • Available balance • Total customers • Active subscriptions • Monthly Recurring Revenue (MRR) • Annual Recurring Revenue (ARR) • Recent charges (last 5) • 6-month revenue trend Press Ctrl+C to exit live mode. HELP } # ================== # MAIN # ================== main() { local mode="auto" local interval=10 local once=false # Parse arguments while [[ $# -gt 0 ]]; do case "$1" in --interval) interval="$2" shift 2 ;; --demo) mode="demo" shift ;; --once) once=true shift ;; --help|-h) show_help exit 0 ;; *) echo "Unknown option: $1" show_help exit 1 ;; esac done # Run dashboard if $once; then # Single run draw_header local balance customers subscriptions mrr charges if [[ "$mode" == "demo" ]] || ! check_stripe_cli; then balance=$(generate_mock_balance) customers=$(generate_mock_customers) subscriptions=$(generate_mock_subscriptions) mrr=$(generate_mock_mrr) charges=$(generate_mock_charges) mode="demo" else balance=$(get_stripe_balance) customers=$(get_customer_count) subscriptions=$(get_subscription_count) mrr=$(get_mrr) charges=$(get_recent_charges) mode="live" fi draw_balance_card "$balance" draw_key_metrics "$customers" "$subscriptions" "$mrr" draw_recent_charges "$charges" draw_revenue_chart "$mrr" local timestamp=$(date "+%Y-%m-%d %H:%M:%S") c_gray printf "\n" if [[ "$mode" == "demo" ]]; then printf "Snapshot taken at %s (Demo Mode)\n" "$timestamp" else printf "Snapshot taken at %s (Live Data)\n" "$timestamp" fi c_reset else # Live monitoring run_dashboard "$interval" fi } main "$@"