> For the complete documentation index, see [llms.txt](https://will-schneider.gitbook.io/react-saas/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://will-schneider.gitbook.io/react-saas/configure-stripe.md). Agents can also search and read this documentation through its [MCP server](https://will-schneider.gitbook.io/react-saas/~gitbook/mcp).

# Configure Stripe

{% embed url="<https://youtu.be/ANEcNPQKawU?si=USoyRRBNMBY2dzYA>" %}

#### Install Stripe Plugin in Firebase

1. Install the stripe plugin on your project and go through the options

<figure><img src="https://1699355075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu5ZFqXvi6XrDDrmKerRj%2Fuploads%2F0jD69cfog5pTRb9V988j%2Ffirebase-extension.png?alt=media&amp;token=68317cbe-62c6-4683-9238-d4bc60234446" alt="" width="563"><figcaption></figcaption></figure>

2. In Firebase select your billing account

<figure><img src="https://1699355075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu5ZFqXvi6XrDDrmKerRj%2Fuploads%2FniAUzN9OYniLOivX2lWH%2Fbilling-account.png?alt=media&amp;token=ef8360f2-2286-40be-96f5-40e7373dbd91" alt="" width="563"><figcaption></figcaption></figure>

3. In Firebase enable services needed

<figure><img src="https://1699355075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu5ZFqXvi6XrDDrmKerRj%2Fuploads%2Fg7ZTCq4Ps0K2tmrYdvPy%2Fenable-services.png?alt=media&amp;token=c3e4cc2a-6a82-41c5-bb84-f44d22b78389" alt="" width="563"><figcaption></figcaption></figure>

4. Login to your Stripe account
5. In Stripe create a restricted API key and copy it to use in Firebase:
   * stripe.com > developers > api keys > restricted keys
   * Select write access for:
     * Customers
     * Checkout Sessions
     * Customer Portal
   * Select Read-only access for:
     * Subscriptions
     * Prices

<figure><img src="https://1699355075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu5ZFqXvi6XrDDrmKerRj%2Fuploads%2FSKQUL0QVdcVUQvyeFuzv%2Fstipe-webhook.png?alt=media&amp;token=e483080c-5656-4e03-8595-383b03f1bc57" alt="" width="563"><figcaption></figcaption></figure>

* Click create and then copy the key
  * The key should look like: rk\_test\_\[token] or rk\_live\_\[token]

6. Go back to Firebase:
   * Using the Stripe secret from step 5: Firebase > Extension Configuration > Click Create secret
7. Recommendation set min warm instances to 1 (to avoid a slow user experience)

<figure><img src="https://1699355075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu5ZFqXvi6XrDDrmKerRj%2Fuploads%2FMblYmS8FLaTIYezBeSih%2Fwarm-instance.png?alt=media&amp;token=6c8a8afd-715c-47af-8e96-9f889f5ca70c" alt="" width="563"><figcaption></figcaption></figure>

3. Click **Install** extension

***

#### Configure Stripe Webhook and Billing Portal

1. In Firebase go to: Extensions > Run Payments with Stripe > Manage > How this extension works
2. In Firebase ensure your Firestore security rules are in place
   * Should have rules in place from getting started documentation
3. In Stripe go to Configure Stripe webhook

   * Use the extension endpoint URL from Firebase > How this extension works
   * Listen to **events** on your account
   * Select these 16 events as listed in the Firebase documentation:

   ```
       1.  checkout.session.completed
       2.  customer.subscription.created
       3.  customer.subscription.deleted
       4.  customer.subscription.updated
       5.  payment_intent.canceled
       6.  payment_intent.payment_failed
       7.  payment_intent.processing
       8.  payment_intent.succeeded
       9.  price.created
       10. price.deleted
       11. price.updated
       12. product.created
       13. product.deleted
       14. product.updated
       15. tax_rate.created
       16. tax_rate.updated
   ```

   * Click **Add endpoint** and copy the Signing secret
     * The Signing secret should look like: whsec\_\[token]
4. In Firebase goto Extensions > Run Payments with Stripe > Manage > Reconfigure extension > Stripe Webhook secret > Paste From Step #3 > Click Create secret > Save
   * This should take 3-5 minutes to save your updated configuration
5. Allow Users to Manage Their Billing
   * Simply go to billing portal in Stripe and configure what you want:
     * Dev: <https://dashboard.stripe.com/test/settings/billing/portal>
     * Prod: <https://dashboard.stripe.com/settings/billing/portal>
   * Need to click **Save changes** to enable the portal

***

#### Configure Stripe in The Code

1. In Stripe Create product and pricing information
2. Copy the pricingIDs from Stripe
3. Goto **stripe/config.ts** in the code then paste your **pricingIDs**
   * This controls which products are displayed in:
     * **components/payments/Pricing.tsx** : Pricing table on **/pricing** page
     * **components/dashboard/settings/Billing.tsx**: Manage your purchases on **/billing** page

***

#### Live Production Stripe Payments

1. Make sure you have tested and reviewed the application with fake payments
2. Make sure you have applied and been approved for live payments in Stripe
3. Repeat all the steps above with live Stripe keys in the production Firebase project
   * Make sure to add the production pricingIDs to **stripe/config.ts** under prod\_products
