Oh boy am I giddy.
We're about to pay.
We're about to pay with a credit card and process the payment on Stripe.
That is the whole point of this part of the course.
And so the way that we're going to achieve this is we're going to implement
the Stripe SDK software development kit in our Firebase functions.
That's how we're going to do this.
And so the payment gateway that we're
talking about here, right?
We have our checkout, we have our payment button.
But our payment button right now isn't connected to anything.
It's just console log.
We want to change that console log into a
console charge.
Okay, bad joke.
Bad dad joke.
But you know what I mean, right?
We want to pay.
And we want to be able to see our
payments on the payments screen.
We want to see this happen.
We want all of this good stuff, right?
And so right now what we're seeing is
that some of the payments that I've done in the other app, right?
The production app, have trickled through.
And so what we're going to look at now is
how exactly we're going to get this payment fee.
Process of Stripe payment.
Now if we go to the Node .js
implementation of Stripe, on October 24th, 2013, they officially launched what
was, I believe, the official Stripe Node .js package.
Okay, so obviously it's been updated since then and improved.
But during that time period, right?
2013 to now, that's 8 years.
A lot of improvements must have happened.
So this package is the package that we're
going to use to talk on our behalf to Stripe.
So you know what to do.
We go over to Meals to Go.
We cd into our functions folder and we do
yarn add stripe.
And by doing this inside of the functions
folder, what we're achieving here is the ability to bootstrap, just like Stripe
client in the front end, a Stripe client in the back end.
Now they're different.
They're different because on the front
end, it's a limited subset of the Stripe SDK that's available to us.
But on the back end in our Firebase functions, we have a whole world open to us.
We can do anything.
It's kind of like Charlie and the
Chocolate Factory.
It's up to your imagination.
So with that said, what we need to do now is create that Stripe client.
So over here we have our Google client, obviously.
And what we want to do now is const
stripeClient is equal to the require of Stripe.
But what we're going to do with this is
we're going to say functions .config .stripe .key.
And that is what we're going to use.
Now if you're unaware of how to add a
configuration key or you don't remember how to do this, please refer back to the
Google videos in order to get this running locally if you've lost the
ability or you forget which functions we ran and so forth.
But the key that you're going to want to set on the stripe .key, if we go over
here and we go into developers and then we go into API keys, what you're going to
want to do is you're going to want to take the secret key.
This is the key that you're going to want to copy paste into your stripe .key.
And so once you've done that, then you want to, of course, take those secrets
and put them locally.
And again, we showed that in the Google
Firebase config series when we were doing our Google implementation.
So just refer back to those videos if you're having a hard time remembering.
And so just as a quick reminder, once you've set up your Firebase key, you can
do Firebase functions .config .get and you can do this little sign over here, right?
The greater than sign.
And so if you run this whole line,
rather, I'll show it on one line.
If you run Firebase functions .config
.get greater than and then to .runtime .config, this is going to take all of the
config that is in your Firebase functions and put them in a local file.
And that way you can run it locally.
So now what we need to do is quickly
restart our Firebase functions.
And now we have a stripe client that is bootstrapped.
Now, the other thing that I want to do is I quickly want to rename all of these
clients to Google client because we want to create a clear separation here between
the Google client and the stripe client that we're passing in.
And then what we want to do is we want to export a new function and we want to call
it pay.
And then when we export pay, we're going
to do something called a pay request.
And we're going to use the stripe client.
Now, pay request is going to come from, well, you guessed it, pay.
So .slash pay.
And so over here in our Firebase
functions, we're going to create a new folder and we're going to call that pay.
And in pay, we're going to put an index .js and we're going to export const pay request.
Rather, no, we don't want to use that type of syntax.
We're going to do module .exports.
So we're going to do module .exports.
And module .exports .payrequest.
And then what we're going to do, and you
can see here I get tripped up between the different
types of syntax I need to use between different libraries.
It happens.
All of these different types of
infrastructure can expect different types of syntax.
So over here, we're using the module syntax.
So what we're getting is request,
response, and then we're getting the stripe client.
And so with that now, we can go ahead and we can do a res .send.
This is my payment gateway.
And with that comes the ability for us to
be able to, well, response .send, first of all.
With that comes the ability for us to talk to our response gateway.
Now if we look over here, if we go to meals to go pay, we'll see this is my
payment gateway.