This sample shows how to create Stripe customers and charge them when the Realtime Database is written to.
Further reading:
- Stripe Node API: https://stripe.com/docs/api/node
- Firebase SDK: https://firebase.google.com/docs/functions
See file functions/index.js for the code.
The dependencies are listed in functions/package.json.
To test this integration:
- 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.
- 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.token=<YOUR STRIPE API KEY>
- Optional: change your default currency
firebase functions:config:set stripe.currency=GBP
- Deploy your project using
firebase deploy
- Test the Stripe integration by:
- Add a new user account in the Firebase Console, this should create a new Stripe customer record
- Set a payment method for the customer in the Stripe Console (you'd normally do this in your front-end with a Stripe SDK)
- Write some amount to the RTDB under
/users/{userId}/charges/{pushId}