Payment Integration
Set up Stripe to handle payments, subscriptions, and billing for your SaaS.
Introduction
Show me the money! ZapStart uses Stripe for payment processing, which makes it easy to handle one-time payments and subscriptions.
Setting Up Stripe
Let's get your Stripe account ready:
- Go to Stripe and create an account
- Complete the account creation and verification process (you may need to provide some business information along with your bank account details), this is covered in details in the ZapStart Company-Setup Guide.
- By default, you'll be in Test Mode, which is for development purposes.
- Configure your account settings for a professional appearance:
- In Settings > Public Details, add your website URL
- In Settings > Branding, upload your logo and set your brand colors
- In Settings > Customer Emails, enable notifications for successful payments and refunds
- In Settings > Customer Portal, activate the customer portal link (this is for subscription management)
- Set up fraud prevention measures:
- Search for "rules" in the dashboard search box
- Navigate to Fraud Prevention > Rules
- Ensure the first 3D Secure rule is enabled (required in many regions)
- Consider enabling the second rule as well (recommended for additional security)
- Configure settings to block payments if CVC verification fails
In Stripe's test mode, you can use test card numbers like 4242 4242 4242 4242
with any future expiration date and any 3-digit CVC.
Getting Your API Keys
Now, let's get the API keys needed for ZapStart:
- In the Stripe dashboard, ensure you're in the correct mode:
- Test Mode: For development (fake payments)
- Live Mode: For production (real payments)
- Go to Developers > API keys (note we're in the Test Mode)
- You'll see your:
- Publishable key (safe to use in frontend), we won't use this key in the frontend, but copy it to the .env file in the backend directory
- Secret key (must only be used in backend).
STRIPE_PUBLIC_KEY=your_publishable_key
STRIPE_SECRET_KEY=your_secret_key
Never commit your Stripe secret key to version control! Make sure your .env
file is in your .gitignore
.
Creating Products and Plans
Let's create a recurring subscription payment product in Stripe and configure your ZapStart application to use it:
Creating a Recurring Subscription Product
- In your Stripe Dashboard, go to Products (in the left sidebar)
- Click + Add product
- Configure your product:
- Name: Enter a descriptive name (e.g., "Pro Package")
- Description: Describe what customers get with this product
- Optionally add an image to represent your product
- In the Pricing section:
- Make sure Recurring is selected (not one-time)
- Enter the price amount (e.g., $20.00)
- Choose your currency (e.g., USD)
- Click Save product
- After saving, you'll be taken to the product detail page. click on the three dots on the right of the pricing table and click on the Copy Price ID
Make sure you're in the correct mode (Test or Live) when creating products. Test mode products can only be used in development, and live mode products only in production.
The creation of the one-time payment product is almost the same as the recurring subscription product, but with the one-time option selected.
Updating Your Configuration Files
Now that you have your Price ID, you need to update your configuration files:
1. Update Backend Configuration
Open backend/configBack.js
and make these changes:
- Set
oneTime: false
at the top of the file (if you want to use the one-time payment product, set it to true) - Find the
plans
object - Locate the
Pro
plan entry - Replace the
PRICE_ID
value with your Stripe Price ID
2. Update Frontend Configuration
Open frontend/configFront.js
and make these changes:
- Set
oneTime: false
at the top of the file (if you want to use the one-time payment product, set it to true) - Find the
stripe.plans
array - Locate the second object in the array (the paid plan, where
free: false
) - Update the
priceId
of the conditional values:- For development: Your test mode Price ID
- For production: Your live mode Price ID (you'll get this later when ready for production)
Using Different Price IDs for Environments
The frontend and backend config files let you specify different Price IDs for development and production. This allows you to use test payments in development and real payments in production.
Setting Up Stripe Webhooks
Webhooks let Stripe notify your app about events like successful payments, it will communicate with our backend webhook endpoint which is /api/subscription/webhook
:
For Local Development
- Install the Stripe CLI from here, go and follow the instructions for your specific platform:
https://docs.stripe.com/stripe-cli?install-method=homebrew - After you have installed the Stripe CLI, login to your Stripe account via the CLI:
stripe login
This will open your browser and ask you to authorize the CLI to access your account.
- Start listening for webhooks:
stripe listen --forward-to http://localhost:8000/api/webhooks/stripe
The CLI will display a webhook signing secret, copy it to the
STRIPE_WEBHOOK_SECRET=
in the .env file in the backend directory.
STRIPE_WEBHOOK_SECRET=your_webhook_signing_secret
Testing Payments Locally
Now that your Stripe keys are set up, it's time to test the payment flow:
- Make sure your backend server is running with the Stripe environment variables set, you may require to restart the server.
- Use Stripe's test card numbers for the checkout page:
4242 4242 4242 4242
- Successful payment4000 0000 0000 0002
- Card declined4000 0025 0000 3155
- Requires authentication (3D Secure)
We'll be testing the payment flow in the Build your startup tutorial, and for more info about the payment flow, please see the Payments Tutorial.
Production Setup
When you're ready to go live with real payments, you'll need to set up production webhooks:
- Turn OFF Test Mode in your Stripe Dashboard to switch to live mode
- In the Stripe dashboard, go to Developers > Webhooks
- Click Add endpoint
- Enter your webhook URL (e.g.,
https://api.yourdomain.com/api/webhooks/stripe
) - Select the events you want to receive:
checkout.session.completed
customer.subscription.deleted
invoice.paid
- You can add more events if you want to, but these are the most important ones.
- Click Add endpoint
- Retrieve the signing secret and update your production environment variables (you can find the secret and public keys in Developers > API keys):
STRIPE_PUBLIC_KEY=your_publishable_key STRIPE_SECRET_KEY=your_secret_key STRIPE_WEBHOOK_SECRET=your_webhook_signing_secret
- Create a product in production mode and copy the Price ID to the config files (backend/configBack.js and frontend/configFront.js)
- Optional: Configure your payout schedule:
- Go to Balance > Manage Payouts
- Set a specific monthly payout date if you prefer consolidated payments (e.g., the 10th of each month)
- Create products in production mode and copy the Price ID to the config files and update the pricing value in the frontend config file
Next Steps
Now that you've configured your JWT secrets, MongoDB, Google OAuth ,Email and Payment, you can continue setting up the rest:
- Fill in the Config files with the correct values