Okay, so now we have our order page.
The next step is to add the route, to update the order as paid, and then we'll take care of the whole
PayPal button and connecting the PayPal API.
So let's go to our back end and let's go to Controllers Order controller and we should have an update
to paid.
So right here update order to paid.
So it's going to be.
Why do I have get here?
This should be a put request, I believe.
Um, let me just check something real quick.
Yeah, that should be a put request.
I don't know why I have get there.
So let's change that to put.
And this should also be put.
Canned, then we're going to get rid of that.
And first thing we need to do is get the order.
So let's say order equals await order, find by ID, pass in the ID, and then we'll say if order,
then we're going to just basically take the order and set is paid to true.
And then there's a couple other fields that we want to add paid at which we're going to set to the current
date and time, and then the payment result is going to be an object with the ID status, update time
and email address.
This stuff is actually going to come from PayPal, okay?
After it's paid and then we're going to just save it in the database and then put it into a variable
and then respond with a 200 and pass in the updated order and then we'll just do an else.
So if else, then it's going to be a 404 because obviously that there is no order.
So it's not found.
Okay.
So we'll save that now.
We have to you basically have to register for a PayPal API.
So log in, go to developer dot paypal.com and log in.
You log in with your regular PayPal account, but from here you can basically switch this to sandbox
and then you can create test accounts.
So if you go to testing tools and then sandbox accounts, I believe you already have one, a business
and a personal set up.
So basically your business is going to be the the account that gets the money from your app through
your application.
The personal is what you use to pay with.
Okay.
So that way you're not dealing with actual money when you're testing your app.
So just make sure you have a business and personal.
If you don't, then just create it.
Then you want to go to apps and credentials and then click Create app.
And I'm just going to call this pro shop and we're going to choose merchant.
And then for your sandbox account, you can choose one of your business accounts.
I'm just going to keep the default and then let's click Create App.
And then we'll get after that, we'll get our client ID.
So this is really important.
You want to grab this?
Let's copy it to our clipboard and then we're going to go into our env dot env and we're going to add
PayPal.
So we want PayPal underscore client underscore ID, and then you're going to paste in.
Your PayPal client ID and save.
All right.
And then I believe that's all we have to do here.
There are like different features and stuff.
I'm just going to leave the default.
Yeah.
So we should be all set.
I'll just click.
Yeah, we should be all set as far as this goes.
Now we need to add the PayPal route in our back end.
So you want to go to your server.js.
And you can look at look this stuff up in the docs if you want as well, the PayPal API docs, but we're
going to go under where we have the routes mapped to our files.
So right here and we're just going to say app dot get and the endpoint.
Is going to be.
This is very important.
It has to be a slash API slash config slash PayPal.
All right.
And then.
Um, actually, we don't even need curly braces because what we're returning, we're just going to respond
so we can say res dot send.
And what we want to send is our client ID.
So in curly braces, we'll say client ID and then set that to our environment variable, which is process
dot env.
Dot PayPal client ID.
And we'll save that.
And the reason for this is because we can't put our client ID in the front end.
You don't want it on the client side because you don't want people getting that.
So we're storing it in our Env file and then we're creating a route so PayPal can then get that client
ID and then use it.
Okay.
Now, I think we should be all set as far as the back end goes.
So in the next video, we'll start to implement the front end and papal.
We're actually going to use a package called React Papal or React Papal.
JS So we'll do that next.