Fireship · @fireship
Process Stripe Payments with Firebase Cloud Functions - Part 2
Uploaded July 11, 2017 · Length 4:53
Summary
how to integrate stripe payments with firebase cloud functions in angular 4
- stripe payments
- firebase cloud functions
- angular 4
- payment gateway
- firebase database
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
welcome to part two of stripe payments
- 0:02
with angular 4 and firebase in part 1 we
- 0:06
collected the payment token from stripe
- 0:08
and in this episode we're going to build
- 0:10
a fire based cloud function that will
- 0:12
actually charge the card hole stripe
- 0:14
transactions need to occur on a real
- 0:16
back-end server and that's exactly what
- 0:18
we're going to use cloud functions for
- 0:21
the first step is to initialize cloud
- 0:23
functions if they're not already set up
- 0:25
in your project run firebase in it and
- 0:27
then CD into that functions directory
- 0:30
then run NPM install stripe with the
- 0:33
save flag to save it to the local
- 0:36
project your package dot JSON file
- 0:39
should look something like this and from
- 0:42
here we need to set an environment
- 0:43
variable with our stripe API key run
- 0:47
firebase functions config set stripe
- 0:50
test key followed by your own stripe API
- 0:53
key check out the link in the
- 0:54
description to just copy and paste this
- 0:56
command now we can start building the
- 0:58
function in the index.jsp file first
- 1:01
step is to import the firebase functions
- 1:04
library as well as the admin database
- 1:05
and for stripe we'll initialize it with
- 1:09
our API key using that environment
- 1:11
variable we just set the name of the
- 1:13
function will be striped charge and
- 1:15
we'll use the on right database callback
- 1:18
to trigger this function in other words
- 1:21
whenever a new payment is written to the
- 1:23
database this function will be invoked
- 1:24
it has an event object that has the data
- 1:28
from that node in the database which is
- 1:30
the payment along with the token so we
- 1:33
can get that by calling event data eval
- 1:35
and we'll also set variables for the
- 1:38
user ID as well as the payment ID just
- 1:41
to make our code a little more concise
- 1:42
and then we want the function to return
- 1:44
null if there is no payment or if the
- 1:47
payment already has a charge from there
- 1:49
we'll chain together a bunch of promises
- 1:51
the first one being the user in the
- 1:52
database this isn't completely necessary
- 1:54
but it's a good idea if you have
- 1:56
recurring charges or if you want to save
- 1:58
customer data in the database we call


