DeployFrame Docs

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

  1. Visit https://stripe.com
  2. Click "Start now" or "Create account"
  3. Enter your email address and set a password
  4. Click "Create account"

Complete Basic Information

After creating your account, provide the requested basic information:

  1. Your full name
  2. Business name (you can use a placeholder for testing)
  3. 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

  1. Log in to the Stripe Dashboard
  2. Ensure you're in Test mode (toggle in the top-right corner)
  3. Click "Developers" in the left sidebar
  4. 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:

# Stripe Integration
STRIPE_API_PUBLIC_KEY=pk_test_your_publishable_key
STRIPE_API_SECRET_KEY=sk_test_your_secret_key

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:

# Load environment variables from .env file
set -a && source ./cdk/.env && set +a

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 NameMonthly PriceYearly PriceMonthly CreditsDescription
BASIC$0.00$0.0020Free tier (created by default)
PRO$9.99$99.99300Professional AI features
MEGA$29.99$299.991,000Enhanced AI features
ULTRA$69.99$699.993,000Premium AI features

Credit Packs

Pack NameCreditsPrice
Small Pack100$6.99
Medium Pack500$24.99
Large Pack1,000$39.99
Jumbo Pack2,000$69.99

Setup Process

The setup process is divided into two steps:

  1. Creating subscription plans and credit packs - This sets up all the products and pricing in your Stripe account
  2. 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

Install Required Dependencies

First, install the Stripe Python SDK:

pip install stripe

Create Subscription Plans and Credit Packs

Run the setup script from the root directory with the plans command:

# Extract app_name from cdk.json to use with the script
APP_NAME=$(jq -r '.context.app_name' ./cdk/cdk.json)
echo "Using app name: $APP_NAME"
 
# Run the setup script using environment variables
python ./tools/setup_stripe.py plans --config ./tools/stripe_config.json --api-key $STRIPE_API_SECRET_KEY --app-name $APP_NAME

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:

  1. Log in to the Stripe Dashboard
  2. Go to "Products" in the left sidebar
  3. Ensure that the PRO, MEGA, ULTRA plans and Credit Packs products are listed
  4. 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:

# Extract the app_name from cdk.json
APP_NAME=$(jq -r '.context.app_name' ./cdk/cdk.json)
echo "Using app_name from cdk.json: $APP_NAME"
 
# Set the export name pattern using the extracted APP_NAME
EXPORT_NAME="${APP_NAME}-${STAGE}-stripe-webhook-url"
 
# Retrieve the Stripe webhook URL by export name
WEBHOOK_BASE_URL=$(aws cloudformation list-exports \
  --query "Exports[?Name=='$EXPORT_NAME'].Value" \
  --output text)
 
# Append the required path
WEBHOOK_URL="${WEBHOOK_BASE_URL}stripe-webhook"
echo "Stripe Webhook URL: $WEBHOOK_URL"

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:

# Run the setup script using environment variables
python ./tools/setup_stripe.py webhook --config ./tools/stripe_config.json --url $WEBHOOK_URL --api-key $STRIPE_API_SECRET_KEY

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:

# Stripe Integration
STRIPE_API_PUBLIC_KEY=pk_test_your_publishable_key
STRIPE_API_SECRET_KEY=sk_test_your_secret_key
STRIPE_WEBHOOK_SECRET_KEY=whsec_your_webhook_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:

# Reload environment variables
set -a && source ./cdk/.env && set +a

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:

cd cdk
cdk deploy --all --require-approval never
cd ..

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:

# Extract the app_name from cdk.json
APP_NAME=$(jq -r '.context.app_name' ./cdk/cdk.json)
echo "Using app_name from cdk.json: $APP_NAME"
 
# Set the export name pattern using the extracted APP_NAME
EXPORT_NAME="${APP_NAME}-${STAGE}-amplify-app-id"
 
# Retrieve the Amplify App ID by export name
AMPLIFY_APP_ID=$(aws cloudformation list-exports \
  --query "Exports[?Name=='$EXPORT_NAME'].Value" \
  --output text)
  
echo "Amplify App ID: $AMPLIFY_APP_ID"
 
# Start the build using the extracted App ID
aws amplify start-job \
  --app-id $AMPLIFY_APP_ID \
  --branch-name dev \
  --job-type RELEASE

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:

  1. Navigate to the "Subscription" page
  2. Verify that premium plans (PRO, MEGA, ULTRA) are now displayed with their pricing options
  3. Confirm that the "Subscribe" buttons are active for these plans

Check Credit Packs Availability

Before Stripe integration, no credit packs were available for purchase:

  1. Navigate to the "Purchase Credits" page
  2. Verify that credit packs (Small, Medium, Large, Jumbo) are now displayed
  3. Confirm that the "Purchase" buttons are active

Test Subscription Flow

Test the subscription process:

  1. Navigate to the "Subscription" page
  2. Select a premium plan (e.g., PRO plan)
  3. Click the "Subscribe" button
  4. You should be redirected to the Stripe Checkout page
  5. Enter test card information:
    • Card number: 4242 4242 4242 4242
    • Expiration date: Any future date
    • CVC: Any 3 digits
    • Name and address: Any values
  6. Complete the checkout process
  7. You should be redirected back to your application

Verify Subscription Change

Verify that your subscription was successfully processed:

  1. Check that you're redirected to the dashboard page
  2. Confirm that your credit balance has increased to the amount associated with the new plan
  3. 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:

  1. Navigate to the "Purchase Credits" page
  2. Select a credit pack
  3. Complete the checkout process with the test card
  4. Verify that your credit balance increases by the appropriate amount

Verify in Stripe Dashboard

Check that everything is properly recorded in Stripe:

  1. Log in to the Stripe Dashboard
  2. Go to "Customers" to see your test user
  3. Verify that the subscription is active
  4. 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.