|
| 1 | +#!/usr/bin/env bash |
| 2 | +# start_stripe_listener.sh |
| 3 | +# Script to easily run stripe listen in the background for local development. |
| 4 | + |
| 5 | +LOG_FILE="stripe_listen.log" |
| 6 | +PID_FILE=".stripe_listen.pid" |
| 7 | + |
| 8 | +# Check if already running |
| 9 | +if [ -f "$PID_FILE" ]; then |
| 10 | + OLD_PID=$(cat "$PID_FILE") |
| 11 | + if ps -p $OLD_PID > /dev/null; then |
| 12 | + echo "Stripe listener is already running with PID $OLD_PID." |
| 13 | + echo "Stop it first with: ./stop_stripe_listener.sh" |
| 14 | + exit 1 |
| 15 | + else |
| 16 | + # Process died but pid file remains, clean up |
| 17 | + rm "$PID_FILE" |
| 18 | + fi |
| 19 | +fi |
| 20 | + |
| 21 | +echo "Starting Stripe CLI listener..." |
| 22 | + |
| 23 | +# If STRIPE_TEST_SECRET_KEY is not in environment, fail and exit |
| 24 | +if [ -z "$STRIPE_TEST_SECRET_KEY" ]; then |
| 25 | + echo "STRIPE_TEST_SECRET_KEY is not set. Please set it in your environment." |
| 26 | + exit 1 |
| 27 | +fi |
| 28 | + |
| 29 | +# Run stripe listen in the background |
| 30 | +# We use nohup so that closing the terminal doesn't kill it |
| 31 | +nohup stripe listen \ |
| 32 | + --api-key "${STRIPE_TEST_SECRET_KEY}" \ |
| 33 | + --events checkout.session.completed,payment_intent.succeeded,payment_intent.payment_failed,invoice.created \ |
| 34 | + --forward-to 127.0.0.1:5000/stripe_webhook \ |
| 35 | + --forward-connect-to 127.0.0.1:5000/stripe_webhook > "$LOG_FILE" 2>&1 & |
| 36 | + |
| 37 | +PID=$! |
| 38 | +echo $PID > "$PID_FILE" |
| 39 | + |
| 40 | +echo "✅ Stripe listener started in background (PID: $PID)." |
| 41 | +echo "📁 Logs are being written to $LOG_FILE" |
| 42 | +echo "🛑 To stop, run: ./stop_stripe_listener.sh" |
| 43 | +echo "" |
| 44 | +echo "Note: If the logs in $LOG_FILE show 'Please authenticate', run 'stripe login' interactive to refresh your token." |
| 45 | +echo "To view the logs, run: tail -f $LOG_FILE" |
0 commit comments