piekarnikgosipl/dev.sh
2026-11-09 18:58:23 +01:00

35 lines
846 B
Bash
Executable file

#!/bin/bash
LOG_FILE=$(mktemp)
trap "rm -f $LOG_FILE; kill $(jobs -p) 2>/dev/null" EXIT
if [ -f .env ]; then
export $(cat .env | xargs)
fi
export DEV_ENV="TRUE"
echo "Starting Stripe CLI listener..."
stripe listen --events checkout.session.completed,checkout.session.async_payment_succeeded --forward-to localhost:8000/webhook > "$LOG_FILE" 2>&1 &
WEBHOOK_SECRET=""
for i in {1..10}; do
if grep -q "whsec_" "$LOG_FILE"; then
# Extract the exact whsec_ token
WEBHOOK_SECRET=$(grep -oE 'whsec_[a-zA-Z0-9]+' "$LOG_FILE" | head -n 1)
break
fi
sleep 0.5
done
if [ -z "$WEBHOOK_SECRET" ]; then
echo "Error: can't get the webhook secret from Stripe CLI"
cat "$LOG_FILE"
exit 1
fi
echo "Successfully captured webhook secret: $WEBHOOK_SECRET"
export WEBHOOK_SECRET
go tool templ generate
go run .