πŸ’³Stripe

Stripe Setup Tutorial

Fast Phoenix integrates seamlessly with Stripe to handle subscriptions and payments. Follow these steps to configure Stripe for your project.


Step 1: Prepare Your Environment Variables

Fast Phoenix uses environment variables to manage Stripe configuration. Open your .env file and ensure the following variables are set:

# Stripe API Configuration
STRIPE_API_KEY=sk_test_your_stripe_api_key
STRIPE_SIGNING_SECRET=your_signing_secret
STRIPE_API_BASE_URL=http://localhost:4000

# Product and Pricing IDs
STRIPE_PRO_PRICE_ID=price_pro_id
STRIPE_PRO_PRICE=30
STRIPE_ENTERPRISE_PRICE_ID=price_enterprise_id
STRIPE_ENTERPRISE_PRICE=100

STRIPE_PORTAL_ID=portal_test_id

Replace the placeholder values with your actual Stripe credentials and product/pricing details.


Step 2: Create Products and Prices in Stripe

  1. Log in to Stripe Dashboard Access your Stripe Dashboardarrow-up-right.

  2. Create Two Products

    • Pro Plan

      • Name: Pro

      • Price: $30

      • Billing: Monthly

    • Enterprise Plan

      • Name: Enterprise

      • Price: $100

      • Billing: Monthly

  3. Copy Product Price IDs After creating the products, navigate to the pricing details and copy the Price IDs for each product. Replace the STRIPE_PRO_PRICE_ID and STRIPE_ENTERPRISE_PRICE_ID values in your .env file with these IDs.


Step 3: Set Up Stripe Webhooks

Stripe uses webhooks to notify your application about important events like successful payments.

  1. Run Your Application Start your local development server:

  2. Install Stripe CLI Download and install the Stripe CLIarrow-up-right to set up webhook forwarding.

  3. Forward Events to Your Application Use the Stripe CLI to forward webhook events to your local server:

    Copy the generated signing secret and update your .env file’s STRIPE_SIGNING_SECRET.

  4. Set Up Webhook Endpoint in Stripe For Prod

    • Navigate to the Webhooks section of the Stripe Dashboard.

    • Add a new endpoint pointing to https://your-domain.com/webhooks/stripe for production.


Step 4: Test Your Setup

  1. Test Subscription Creation Use Stripe's test card numbers (e.g., 4242 4242 4242 4242) to simulate subscriptions.


Step 5: Optional - Enable Customer Portal

  1. In the Stripe Dashboard, enable the Customer Portalarrow-up-right.

  2. Copy the Customer Portal URL and save it in your .env as STRIPE_PORTAL_ID.


Extra:

We have written a stripe_helpers.ex module that creates checkout sessions for new subscribers and upgrading/downgrading subscribers, and a request helper function for hitting up Stripe's API. For example:

Your Stripe setup is now complete! You can start accepting payments, managing subscriptions, and leveraging Fast Phoenix’s built-in features to streamline your billing processes. πŸš€

Last updated