Author: Invertase (https://invertase.io)
Description: Controls access to paid content by syncing your one-time and recurring payments with Firebase Authentication.
Details: Use this extension as a backend for your Stripe payments.
The extension supports multiple use cases:
- Process one-time payments with Stripe Checkout on the web.
- Create subscriptions for your users and manage access control via Firebase Authentication.
- Process payments & set up payment methods with the mobile payment sheet on Android, iOS, or with React Native.
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:
If you're building on the web platform, you can use this extension for any of your payment use cases.
If you're developing native mobile applications and you're selling 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.
For all other scenarios you can use the stripe-android, stripe-ios, stripe-react-native, or flutter_stripe SDKs.
You can use the @stripe/firestore-stripe-payments
JavaScript package to easily access this extension from web clients. This client SDK provides
TypeScript type definitions and high-level convenience APIs for most common operations client
applications would want to implement using the extension.
Use a package manager like NPM to install the above package, and use it in conjunction with the Firebase Web SDK.
This extension emits events, which allows you to listen to and run custom logic at different trigger points during the functioning of the extension. For example you can listen to events when a product has been added via the product.created
event, or whenever a payment has succeeded through the invoice.payment_succeeded
event.
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" and "Prices" resources.
This extension uses the following Firebase services which may have associated charges:
- Cloud Firestore
- Cloud Functions
- Cloud Secret Manager
- Firebase Authentication
- If you enable events Eventarc fees apply.
This extension also uses the following third-party services:
- Stripe Payments (pricing information)
- Stripe Billing (when using subscriptions. 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. -
Stripe configuration collection: What is the path to the Cloud Firestore collection where the extension should store Stripe configuration?
-
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.
-
Automatically delete Stripe customer objects: Do you want to automatically delete customer objects in Stripe? When a user is deleted in Firebase Authentication or in Cloud Firestore and set to 'Auto delete' the extension will delete their customer object in Stripe which will immediately cancel all subscriptions for the user.
-
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" and "Prices" resources.
-
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.
-
Minimum instances for createCheckoutSession function: Set the minimum number of function instances that should be always be available to create Checkout Sessions. This number can be adjusted to reduce cold starts and increase the responsiveness of Checkout Session creation requests. Suggested values are 0 or 1. Please note this setting will likely incur billing costss, see the Firebase documentation for more information.
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.)