This project is inactive and is no longer being maintained.
This example includes Firebase Cloud Functions to create payments in native Android and iOS (coming soon) applications.
Features:
- Android client
- iOS SwiftUI client
- Functions
- Create a customer object when a users signs up via Firebase Authentication and add a customer entry to Cloud Firestore: createStripeCustomer
- Callable functions to create a short-lived ephemeral keys for the SDK's prebuilt UI components: createEphemeralKey
- Function to create a PaymentIntent when a new payment doc is added to Cloud Firestore: createStripePayment
- Webhook handler function to keep Cloud Firestore in sync with Stripe: handleWebhookEvents
- When a user is deleted from Firebase Authentication, delete thir data in Cloud Firestore and their customer object in Stripe: cleanupUser
Please note that when 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 instead. See Apple's and Google's guidelines for more information.
- Create a Firebase Project using the Firebase Developer Console
- Enable billing on your project by switching to the Blaze or Flame plan. See pricing for more details. This is required to be able to do requests to non-Google services.
- Enable Google & Email sign-in in your authentication provider settings.
- Install Firebase CLI Tools if you have not already and log in with
firebase login
. - Configure this sample to use your project using
firebase use --add
and select your project. - Install dependencies locally by running:
cd functions; npm install; cd -
- Add your Stripe API Secret Key to Firebase config:
firebase functions:config:set stripe.secret=<YOUR STRIPE SECRET KEY>
- Deploy your project using
cd functions; npm run deploy; cd -
- Run
firebase open functions
to open the Firebase console. - Copy the URL for the
handleWebhookEvents
functions (e.g. https://region-project-name.cloudfunctions.net/handleWebhookEvents) - Create a new webhook endpoint with the URL in the Stripe Dashboard
- Copy the signing secret (whsec_xxx) and add it to Firebase config:
firebase functions:config:set stripe.webhooksecret=<YOUR WEBHOOK SECRET>
- Redeploy the
handleWebhookEvents
function:firebase deploy --only functions:handleWebhookEvents
Once you’re ready to go live, you will need to exchange your test keys for your live keys. See the Stripe docs for further details.
- Update your Stripe secret config:
firebase functions:config:set stripe.secret=<YOUR STRIPE LIVE SECRET KEY>
- Set your live publishable key in your respective client integration.
- Follow the Setting up webhooks from above for live mode.
- Redeploy the functions for the changes to take effect
cd functions; npm run deploy; cd -
.