Stripe Setup
Configure Stripe for payment processing in your AI SaaS platform
Stripe Setup
Now that you have your core infrastructure deployed, it's time to set up Stripe for payment processing and subscription management. This guide will walk you through creating a Stripe account, obtaining the necessary API keys, and configuring subscription plans using the provided Python script.
Creating a Stripe Account
Sign Up for Stripe
- Visit https://stripe.com
- Click "Start now" or "Create account"
- Enter your email address and set a password
- Click "Create account"
Complete Basic Information
After creating your account, provide the requested basic information:
- Your full name
- Business name (you can use a placeholder for testing)
- Country or region
You don't need to complete the full account verification for testing. Use Stripe in test mode with minimal information.
Getting API Keys and Updating Your Environment
You'll need three API keys from Stripe to integrate with your AI SaaS platform. We'll update your .env
file with these keys as we obtain them.
Access Your API Keys
- Log in to the Stripe Dashboard
- Ensure you're in Test mode (toggle in the top-right corner)
- Click "Developers" in the left sidebar
- Click "API keys"
Update Your Environment Variables with API Keys
You'll need these API keys:
- Publishable key: Starts with
pk_test_
- Secret key: Starts with
sk_test_
Click "Reveal test key" to see your secret key.
Now, from the root directory of your project, open the .env
file in the CDK directory and update the Stripe API keys:
Replace the placeholder values with your actual Stripe keys.
Load Your Environment Variables
After updating the .env
file, load these variables into your current shell session:
Subscription Plans and Credit Packs Overview
The AI SaaS Boilerplate includes a Python script to simplify setting up your Stripe subscription plans and credit packs. Before running the script, here's an overview of what will be configured:
Subscription Plans
Plan Name | Monthly Price | Yearly Price | Monthly Credits | Description |
---|---|---|---|---|
BASIC | $0.00 | $0.00 | 20 | Free tier (created by default) |
PRO | $9.99 | $99.99 | 300 | Professional AI features |
MEGA | $29.99 | $299.99 | 1,000 | Enhanced AI features |
ULTRA | $69.99 | $699.99 | 3,000 | Premium AI features |
Credit Packs
Pack Name | Credits | Price |
---|---|---|
Small Pack | 100 | $6.99 |
Medium Pack | 500 | $24.99 |
Large Pack | 1,000 | $39.99 |
Jumbo Pack | 2,000 | $69.99 |
Setup Process
The setup process is divided into two steps:
- Creating subscription plans and credit packs - This sets up all the products and pricing in your Stripe account
- Configuring the webhook - This is done after you have your API endpoint URL from your deployment
Step 1: Setting Up Subscription Plans and Credit Packs
Create Subscription Plans and Credit Packs
Run the setup script from the root directory with the plans
command:
This will create all the subscription plans and credit packs in your Stripe account.
Verify the Setup
The script will automatically verify that all products and prices were created correctly. You can also manually verify by checking the Stripe Dashboard:
- Log in to the Stripe Dashboard
- Go to "Products" in the left sidebar
- Ensure that the PRO, MEGA, ULTRA plans and Credit Packs products are listed
- Click on each product to verify the prices and metadata
Step 2: Setting Up the Webhook
After deploying your core infrastructure and configuring subscription plans, you need to set up a webhook to receive events from Stripe.
Get Your API Endpoint URL
From the root directory, retrieve the API endpoint URL for your Stripe webhook:
This command automatically retrieves the webhook endpoint URL from your CloudFormation deployment and appends the required path.
Create the Webhook
Run the setup script with the webhook
command and provide your webhook URL:
The command uses the webhook URL we retrieved in the previous step along with your Stripe secret key.
Update Environment with the Webhook Secret
When the script completes, it will display a webhook signing secret that starts with whsec_
.
Open the .env
file in the CDK directory again and add this secret:
The webhook signing secret is displayed only once. Make sure to save it in your .env
file immediately.
After updating, reload your environment variables:
Redeploying with Stripe Integration
Now that you have configured all the necessary Stripe settings, you need to redeploy your infrastructure to apply the changes.
Redeploy Your Infrastructure
From the root directory, run:
This will update your Lambda functions and other resources with the new Stripe credentials.
Trigger Frontend Rebuild
To ensure the frontend picks up the new Stripe configuration, trigger a new build:
Verifying Stripe Integration
After deploying with your Stripe configuration, it's important to verify that the payment processing and subscription management functionality is working correctly.
Access Your Deployed Application
Navigate to your application URL. This is the Amplify app URL you retrieved earlier during the core deployment verification steps.
Sign In to Your Account
Sign in with the test account you created during core deployment verification.
Verify Subscription Plans Are Available
Before Stripe integration, only the BASIC plan was available. Now you should see premium plans:
- Navigate to the "Subscription" page
- Verify that premium plans (PRO, MEGA, ULTRA) are now displayed with their pricing options
- Confirm that the "Subscribe" buttons are active for these plans
Check Credit Packs Availability
Before Stripe integration, no credit packs were available for purchase:
- Navigate to the "Purchase Credits" page
- Verify that credit packs (Small, Medium, Large, Jumbo) are now displayed
- Confirm that the "Purchase" buttons are active
Test Subscription Flow
Test the subscription process:
- Navigate to the "Subscription" page
- Select a premium plan (e.g., PRO plan)
- Click the "Subscribe" button
- You should be redirected to the Stripe Checkout page
- Enter test card information:
- Card number: 4242 4242 4242 4242
- Expiration date: Any future date
- CVC: Any 3 digits
- Name and address: Any values
- Complete the checkout process
- You should be redirected back to your application
Verify Subscription Change
Verify that your subscription was successfully processed:
- Check that you're redirected to the dashboard page
- Confirm that your credit balance has increased to the amount associated with the new plan
- Navigate to the "Subscription" page to verify that your current plan has been updated to the selected plan
Test Credit Pack Purchase (Optional)
Test purchasing additional credits:
- Navigate to the "Purchase Credits" page
- Select a credit pack
- Complete the checkout process with the test card
- Verify that your credit balance increases by the appropriate amount
Verify in Stripe Dashboard
Check that everything is properly recorded in Stripe:
- Log in to the Stripe Dashboard
- Go to "Customers" to see your test user
- Verify that the subscription is active
- Check that the payment was recorded correctly
Next Steps
Now that you have successfully set up and verified Stripe integration, proceed to Google OAuth Setup to configure social authentication for your platform.