Hey, did everyone that they share in this video, we're going to be working on The Roots and we'll
be adding these roots on the dogs.
Pretty simple.
So we have created four of these methods and we need to just send them into the root itself.
So let's go ahead and close this one, this one, and let's open up.
Let's create a new file, not open up.
So in the roots or geez, we are going to create a new file.
Let's call this one as payment dot js and we'll borrow some code from the product itself.
So let's go ahead and say we will be needing express.
So copy that, paste that up here.
Express is needed.
We are also going to need the router, so copy that and paste that up here.
What else we are going to need?
We are going to need this middleware so as well copy that and paste that as well.
What else we are going to need?
We need to send the router as well.
So let's go ahead and copy that even and extract the router and that's all what we are going to need.
I guess that's pretty much it.
Now let's for the sake of saving some time, copy one router itself and let's modify that up here.
Okay.
So how this route is going to work first is somebody actually says, hey, give me the API keys for
Stripe or the Razer paste.
So we're going to go ahead and say slash stripe key.
And anybody who says that I want to have a get let's go ahead and import the methods as well.
So let's go ahead and say I want to say that const bring some methods and these methods are going to
come in from require one directory back inside the controllers not like that inside the codes and we
need to go one directory back inside the controllers and we have this payment controller.
Now the two methods that we have got it send Razorpay Ki and sen stripe ki.
Let's go ahead and paste them up here.
Send Razorpay ki and we got the sen stripe key.
So the only thing that we have to worry about is copy that and paste them up here.
So this one is my read.
This one is going to be handling this one.
So anybody says slash stripe.
KI We will give him the stripe.
KI Just like that.
But he should also be authenticated.
We don't need to make him admin.
In fact, in all of the payment, we don't need to make anybody as an admin.
So we're going to remove the custom role.
We won't be needing it.
So there we go.
Person should be logged in and we will send him the stripe key just like that.
And similar to that.
If somebody says, Hey, I need a razorpay key, then we are going to go ahead and send the Razorpay
Ki to him.
There we go.
Nice and easy.
No problem at all.
Now, these are the key routes.
Now we need to actually capture the payment as well.
So let's go ahead and make a copy of this one.
Move it up here.
And this one is going to be just a process, the payment.
So this one is going to be razorpay and another one razorpay payment.
Another one is going to be stripe payment.
So let's go ahead and call this one as Stripe payment.
And yeah, this seems okay anyways.
Not running out, not really getting good names for this one.
So this one is.
Let me go ahead and copy that.
Capture Stripe payment and capture razorpay payment.
These are good names, actually.
So capture stripe.
In fact, we're going to call this same capture stripe because I think this is a better name.
So Capture Stripe is going to be handled by the capture stripe just like that.
It should be logged in and this should be a post request because you are sending me data at least the
amount and we'll be sending this one.
So this one is going to be captured.
Razorpay.
CAPTCHA razorpay.
And if I am correct, this is going to be CAPTCHA razorpay.
Okay.
Nice.
Now copy that and paste them up here.
So he should be logged in and if he sends it up, we'll be processing this right from here.
So no big deal.
We have done with that.
Now this payment is all done.
Now we need to export this.
We are already exporting this router.
This router needs to go into JS, so the router import is going to work like that and we are going to
call this one as simply payment and this one is going to be slash roots, slash payment, slash payment.
Again, we cannot actually test them out because that's the reason why I got into the separate section.
An entire, entire chapter was dedicated to show you that how payments are being captured.
It takes a little bit while to set up on the front end, but our job at the back end is probably the
simplest one in this case.
The rest all is really complicated, but in this one it is easier.
Not because it is easier on our side because these SD cards were given to us by Razorpay and the stripe.
So we don't have to worry that much.
And that is it.
That is all you need to do.
And in case there are issues being transferred from the front end guy, we obviously can handle those
and we can actually debug the session as well in this.
Also, even in the simplest of the code, I expect that there might be some debugging session that happens,
but that needs to be happen after when the frontend guy comes in, he is using React View, Angular,
Razorpay or whatever he wants to use that comes after that.
So that's pretty much it from our end.
As of now, this part is all done, so payments are being captured.
Now once the payments are being captured now we need to work on how to place an order because without
capturing the payment we won't be placing the order.
So in the next section onwards, we are going to work on how to capture the orders or place the orders.