Overview
The Stripe Payments API uses Stripe API keys for authentication. All requests to Stripe’s servers are authenticated using your secret key, which is configured in your environment variables. The API itself does not require authentication for incoming requests - it acts as a backend proxy to Stripe’s services.Obtaining Stripe API Keys
Log into Stripe Dashboard
Navigate to your Stripe Dashboard and sign in to your account.
Choose your environment
Stripe provides two sets of keys:
- Test mode keys (recommended for development): Start with
sk_test_ - Production mode keys (for live transactions): Start with
sk_live_
Always use test mode keys during development. Test mode keys interact with Stripe’s test environment and won’t charge real cards.
Required Environment Variables
The API requires the following environment variables to be configured in your.env file:
Core Variables
.env
Variable Descriptions
| Variable | Required | Description |
|---|---|---|
STRIPE_SECRET_KEY | Yes | Your Stripe secret API key for authenticating with Stripe’s servers |
STRIPE_WEBHOOK_SECRET | Yes* | Webhook signing secret for verifying webhook events from Stripe |
PORT | No | Port number for the API server (defaults to 3000) |
PUBLIC_API_URL | No | Public URL for the API (used in Swagger docs) |
NODE_ENV | No | Environment mode: development, production, or test |
STRIPE_WEBHOOK_SECRET is only required if you’re using the /api/webhooks/stripe endpoint to receive webhook events.Legacy Fallback
.env
VUE_APP_STRIPE_SECRET as a fallback. However, using STRIPE_SECRET_KEY is strongly recommended.
How Authentication Works
Stripe SDK Configuration
The API initializes the Stripe SDK with your secret key at startup. Here’s how it works (fromsrc/config/stripe.js:1):
The API will fail to start if neither
STRIPE_SECRET_KEY nor VUE_APP_STRIPE_SECRET is defined in your environment.Request Flow
- Client sends HTTP request to your API (e.g.,
POST /api/customers) - API receives request and validates input parameters
- API calls Stripe SDK methods with your configured secret key
- Stripe SDK authenticates the request using your secret key
- Stripe processes the request and returns a response
- API formats and returns the response to the client
Webhook Authentication
Webhook endpoints use a different authentication mechanism for security. When Stripe sends webhook events to your/api/webhooks/stripe endpoint, it includes a signature in the stripe-signature header.
From src/api/webhooks/stripeWebhook.js:3:
constructEvent method verifies that the webhook was actually sent by Stripe and hasn’t been tampered with.
Obtaining Webhook Secrets
To get your webhook signing secret:Copy signing secret
Click Reveal under “Signing secret” to view your webhook secret. It starts with
whsec_Configure your endpoint URL
Set your webhook endpoint URL to:For local development with webhook testing, use Stripe CLI to forward events:
Security Best Practices
Environment Variables
Store all secrets in
.env files and never commit them to version control. Add .env to your .gitignore.Use Test Keys
Always use test mode keys (
sk_test_*) during development. Only use live keys in production.Rotate Keys Regularly
Periodically rotate your API keys, especially if you suspect they may have been exposed.
Verify Webhooks
Always verify webhook signatures using
STRIPE_WEBHOOK_SECRET to prevent spoofing attacks.Server-Side Only
Never use secret keys in client-side code. This API should run on your backend servers only.
HTTPS in Production
Always use HTTPS in production to encrypt data in transit. Stripe requires HTTPS for webhook endpoints.
Environment-Specific Configuration
Development
Production
Troubleshooting
API fails to start
If you see the errorMissing STRIPE_SECRET_KEY or VUE_APP_STRIPE_SECRET in environment variables, ensure:
- Your
.envfile exists in the project root STRIPE_SECRET_KEYis defined and has a value- Your
.envfile has the correct format (no quotes around values) - You’ve restarted the server after modifying
.env
Webhook signature verification fails
If webhooks returnWebhook signature verification failed, check:
STRIPE_WEBHOOK_SECRETmatches the secret shown in your Stripe Dashboard- The webhook endpoint URL in Stripe matches your actual endpoint
- You’re using the raw request body (the API handles this automatically)
- The signing secret is for the correct Stripe account and environment (test vs live)
Next Steps
API Reference
Explore all available endpoints and parameters
Webhook Events
Learn how to handle Stripe webhook events