#!/usr/bin/env sh
# Forward Stripe billing webhook events to the local API.
# Copy the signing secret printed by the CLI into backend/.env as STRIPE_BILLING_WEBHOOK_SECRET.
#
# Usage (from repo root):
#   sh backend/scripts/stripe-billing-webhook-listen.sh
#
# Requires: Stripe CLI (https://stripe.com/docs/stripe-cli)

set -e

PORT="${PORT:-5000}"
FORWARD_URL="http://localhost:${PORT}/api/v1/billing/webhooks/stripe"

echo "Forwarding billing webhooks to ${FORWARD_URL}"
echo "Set STRIPE_BILLING_WEBHOOK_SECRET in backend/.env to the whsec_ value shown below."
echo ""

stripe listen --forward-to "${FORWARD_URL}"
