feat: allow script to work with both test and live Stripe keys
- Accept both sk_test_ and sk_live_ API keys - Show mode indicator (TEST/LIVE) in output - Adjust webhook URL based on mode (localhost for test, towerops.net for live) - Add warning when using test mode - Useful for testing billing setup before going live
This commit is contained in:
parent
13631595a7
commit
2a61626135
1 changed files with 28 additions and 8 deletions
|
|
@ -2,7 +2,7 @@
|
|||
set -e
|
||||
|
||||
echo "=============================================="
|
||||
echo "Stripe Production Billing Setup"
|
||||
echo "Stripe Billing Setup"
|
||||
echo "=============================================="
|
||||
echo ""
|
||||
echo "This script will create:"
|
||||
|
|
@ -10,14 +10,25 @@ echo " 1. A billing meter for device usage tracking"
|
|||
echo " 2. A metered price ($1/device/month)"
|
||||
echo ""
|
||||
|
||||
# Get Stripe live API key
|
||||
read -r -p "Enter your Stripe LIVE secret key (sk_live_...): " STRIPE_KEY
|
||||
# Get Stripe API key (test or live)
|
||||
read -r -p "Enter your Stripe secret key (sk_test_... or sk_live_...): " STRIPE_KEY
|
||||
|
||||
if [[ ! $STRIPE_KEY =~ ^sk_live_ ]]; then
|
||||
echo "Error: API key must start with 'sk_live_' for production"
|
||||
if [[ ! $STRIPE_KEY =~ ^sk_(test|live)_ ]]; then
|
||||
echo "Error: API key must start with 'sk_test_' or 'sk_live_'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Show warning if using test mode
|
||||
if [[ $STRIPE_KEY =~ ^sk_test_ ]]; then
|
||||
echo ""
|
||||
echo "⚠️ Using TEST mode - this will create test resources"
|
||||
echo ""
|
||||
else
|
||||
echo ""
|
||||
echo "✓ Using LIVE mode - this will create production resources"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Fetching your products..."
|
||||
PRODUCTS=$(curl -s https://api.stripe.com/v1/products \
|
||||
|
|
@ -113,15 +124,24 @@ echo "✓ Price created successfully!"
|
|||
echo " Price ID: $PRICE_ID"
|
||||
echo " Amount: \$1.00/device/month"
|
||||
|
||||
# Determine mode for output
|
||||
if [[ $STRIPE_KEY =~ ^sk_test_ ]]; then
|
||||
MODE="TEST"
|
||||
WEBHOOK_URL="http://localhost:4000/api/v1/webhooks/stripe"
|
||||
else
|
||||
MODE="LIVE"
|
||||
WEBHOOK_URL="https://towerops.net/api/v1/webhooks/stripe"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "=============================================="
|
||||
echo "SETUP COMPLETE!"
|
||||
echo "SETUP COMPLETE! ($MODE MODE)"
|
||||
echo "=============================================="
|
||||
echo ""
|
||||
echo "Next steps:"
|
||||
echo ""
|
||||
echo "1. Set up your webhook endpoint in Stripe Dashboard:"
|
||||
echo " URL: https://towerops.net/api/v1/webhooks/stripe"
|
||||
echo "1. Set up your webhook endpoint in Stripe Dashboard ($MODE mode):"
|
||||
echo " URL: $WEBHOOK_URL"
|
||||
echo " Events to subscribe to:"
|
||||
echo " - customer.subscription.created"
|
||||
echo " - customer.subscription.updated"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue