Fireship · @fireship
Selling Digital Content in Angular with Stripe Payments - Part 3
Uploaded July 16, 2017 · Length 7:21
Summary
Implementing digital content purchases with Stripe payments in Angular using Firebase.
- angular stripe payments
- firebase digital content
- stripe checkout angular
- angular stripe integration
- firebase cloud functions
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
welcome to part three of strike payments
- 0:02
with angular and firebase in the last
- 0:05
two episodes we integrated the stripe
- 0:06
check out and charge the card with
- 0:08
firebase cloud functions in this third
- 0:11
episode we're going to use that charge
- 0:12
to enable the user to purchase digital
- 0:15
content in our app in this example we
- 0:17
keep a balance on the user's account
- 0:19
which can be increased by making
- 0:21
payments or decreased by purchasing
- 0:23
content when a user has sufficient funds
- 0:26
on their account they can click a button
- 0:27
that will bring up a modal window to
- 0:29
confirm or cancel the purchase if they
- 0:32
click confirm their account balance is
- 0:34
automatically updated with the new
- 0:36
balance the database will be updated
- 0:39
with a purchases collection which tracks
- 0:41
the user ID and the item IDs that they
- 0:44
purchased the users current balance will
- 0:47
be tracked on their actual account with
- 0:48
a new property called balance which
- 0:50
takes a number let's start by updating
- 0:53
the cloud function we need it to update
- 0:56
both the charge as well as the users
- 0:57
balance in the same operation we want it
- 1:00
to be atomic meaning if the charge fails
- 1:02
the user balance update will fail also
- 1:04
and vice-versa the first step is to
- 1:07
create a balance variable defaults to
- 1:09
zero and then when we get the customer
- 1:11
record we'll update it with their
- 1:13
existing balance when we get the stripe
- 1:16
charge back we'll first check to make
- 1:17
sure it exists and we'll also check to
- 1:20
make sure that it's actually paid if
- 1:22
these conditions are met we create an
- 1:23
object where the key is a reference
- 1:25
point in the database and the value is
- 1:28
the data we want to update this allows
- 1:30
us to update multiple database locations
- 1:32
at the same time but be careful it
- 1:34
performs a set operation so make sure
- 1:37
you point to the very deepest node that
- 1:38
you want to update now we can use the
- 1:41
charge amount from stripe to increase
- 1:42
the users balance and then send these
- 1:44
updates together to the root of the
- 1:47
database back in the app we can see the
- 1:49
users balance is updated by the cloud
- 1:52
function when they make a payment now we
- 1:56
need to update the service to handle the
- 1:58
payment process in order to get the user


