Author: Stripe (https://stripe.com)
Description: Controls access to paid content by syncing your subscriptions with Firebase Authentication.
Details: Use this extension to create subscriptions for your users with the Stripe payments platform and manage access control via Firebase Authentication.
Users can sign-up for your digital goods and paid content with Stripe Checkout and manage their subscriptions with the Stripe customer portal.
This extension syncs customers' subscription status with your Cloud Firestore and adds custom claims using Firebase Authentication for convenient access control in your application.
The design for Stripe Checkout and the customer portal can be customized in your Stripe Dashboard branding settings. See this example which is customized to match the Firebase color scheme:
This extension is meant for the web platform. If you're developing native mobile applications and want to sell digital products or services within your app, (e.g. subscriptions, in-game currencies, game levels, access to premium content, or unlocking a full version), you must use the app store's in-app purchase APIs. See Apple's and Google's guidelines for more information.
Before installing this extension, set up the following Firebase services in your Firebase project:
- Cloud Firestore to store customer & subscription details.
- Follow the steps in the documentation to create a Cloud Firestore database.
- Firebase Authentication to enable different sign-up options for your users.
- Enable the sign-in methods in the Firebase console that you want to offer your users.
Then, in the Stripe Dashboard:
- Create a new restricted key with write access for the "Customers", "Checkout Sessions" and "Customer portal" resources, and read-only access for the "Subscriptions" resource.
This extension uses the following Firebase services which may have associated charges:
- Cloud Firestore
- Cloud Functions
- Firebase Authentication
This extension also uses the following third-party services:
- Stripe Billing (pricing information)
You are responsible for any costs associated with your use of these services.
To install this extension, your Firebase project must be on the Blaze (pay-as-you-go) plan. You will only be charged for the resources you use. Most Firebase services offer a free tier for low-volume use. Learn more about Firebase billing.
Starting August 17 2020, you will be billed a small amount (typically less than $0.10) when you install or reconfigure this extension. See the Cloud Functions for Firebase billing FAQ for a detailed explanation.
Configuration Parameters:
-
Cloud Functions deployment location: Where do you want to deploy the functions created for this extension? You usually want a location close to your database. For help selecting a location, refer to the location selection guide.
-
Products and pricing plans collection: What is the path to the Cloud Firestore collection where the extension should store Stripe pricing plans?
-
Customer details and subscriptions collection: What is the path to the Cloud Firestore collection where the extension should store Stripe customer details? This can be the location of an existing user collection, the extension will not overwrite your existing data but rather merge the Stripe data into your existing
uid
docs. -
Sync new users to Stripe customers and Cloud Firestore: Do you want to automatically sync new users to customer objects in Stripe? If set to 'Sync', the extension will create a new customer object in Stripe and add a new doc to the customer collection in Firestore when a new user signs up via Firebase Authentication. If set to 'Do not sync' (default), the extension will create the customer object "on the fly" with the first checkout session creation.
-
Stripe API key with restricted access: What is your Stripe API key? We recommend creating a new restricted key with write access only for the "Customers", "Checkout Sessions" and "Customer portal" resources. And read-only access for the "Subscriptions" resource.
-
Stripe webhook secret: This is your signing secret for a Stripe-registered webhook. This webhook can only be registered after installation. Leave this value untouched during installation, then follow the postinstall instructions for registering your webhook and configuring this value.
Cloud Functions:
-
createCustomer: Creates a Stripe customer object when a new user signs up.
-
createCheckoutSession: Creates a Checkout session to collect the customer's payment details.
-
createPortalLink: Creates links to the customer portal for the user to manage their payment & subscription details.
-
handleWebhookEvents: Handles Stripe webhook events to keep subscription statuses in sync and update custom claims.
-
onUserDeleted: Deletes the Stripe customer object and cancels all their subscriptions when the user is deleted in Firebase Authentication.
-
onCustomerDataDeleted: Deletes the Stripe customer object and cancels all their subscriptions when the customer doc in Cloud Firestore is deleted.
Access Required:
This extension will operate with the following project IAM roles:
-
firebaseauth.admin (Reason: Allows the extension to set custom claims for users.)
-
datastore.user (Reason: Allows the extension to store customers & subscriptions in Cloud Firestore.)