Hated everyone had their share.
And finally, a lot of you have been waiting for this project.
But let me spoil your surprise.
It's not really a complicated project.
It's really simple.
Payment gateway is just complicated in people's brain.
It's really easy now how you protect some of the information that can be, but really it's easy.
So coming onto the point, Razorpay Razorpay actually offers you a whole lot of services, not just
the payment.
It has so many suite of product that they actually give us on.
So the important thing is that you land up onto the correct documentation, which I've given you here,
so you can just land up directly from there.
So what we're going to do is we just simply click up here and which opens up the same page that I've
already opened at multiple places.
So I'll just keep the dashboard here.
Dashboard is really important.
You need to sign up for them to actually get in test mode and get all the keys.
I'll show you from where you can get that really easy.
So you can see they have a lot of information going in so you can go ahead and look for orders and payments
and a whole lot of things.
We are going to be working on orders.
So any time you want to capture a payment that is called as order, so somebody has placed order of
something, maybe for a course for a t shirt to buy a car or property, whatever that is.
But that is called as orders.
They have information about the payments as well that you can go ahead and look for all about the payments
that what are the test card capture settings, international payments.
There's a whole lot of things that you can do.
We are going to be working on not the payments but actually on the orders.
So here is some information about the orders that they are having.
A couple of states created, attempted or paid.
So maybe you are designing an application in which you store all of the attempted order as well.
Maybe you want to revert and call back to the user that, hey, you have attempted an order, haven't
completed that, so what's going on?
So you can go ahead and do that.
So this is how the whole information goes on.
So order is this is the order state when it is being created, it is being authorized and paid and it
can also go into the different states.
It can be failed, it can be authorized and refunded.
It can be captured, then refunded.
So there's a nice diagram and flow really, really very simple.
Now what we're going to work on is creating the orders.
So obviously they say, hey, you cannot create the order from here.
You need to go ahead and look for the API.
That's exactly what makes us happy that we want to do everything through the APIs.
So I click on this one again.
A lot of information opens up that how you are going to do this.
All I'm interested in is this one, so create an order.
So the documentation is pretty phenomenal that if you look into this so and by the way, they also if
you scroll a little bit, they give you the entire collection so you can download the entire post collection
to play around and all these fields and everything has pre-filled.
So you can just check out that how things actually works.
On what response you get.
This is phenomenal and you can just open this entire collection in The Postman.
This is like really well, the best thing they can give coming back.
So creating the order, just click on this one.
So this is how you create the order.
You need to send a post request to slash orders, but this is not actually the URL you need to look
on to the right side and look for the whatever the language you are working on.
In this case, we are working with the Node.js.
So this is all of the information that is required to capture the payment, the required field or currency
to be passed on.
And the amount notice the amount is in the smallest currency in it.
In our case in India it is paisa or pesa, whatever you call this one.
So this is all being kind of a divided by 100.
So this is actually a price for ₹500.
Multiply by header you get the idea.
This is basic.
So this is how we go ahead and create that.
Now again, you can pass on more fields, like you can pass on notes or partial payment as true and
false and all of that information.
We are not that much interested in that.
We just want to have this much of information.
So I'll come back here first.
Let's go ahead and create a simple folder and try to go with that.
So I'm going to go ahead and create a new folder.
So let me just do all of this via my terminal.
So I'll go to desktop.
And on that I'll, I, I will go into AE back and I can see all of my projects are here.
So let's go ahead and create another directory.
Call this one as Razorpay.
Razorpay.
Yeah, that's that's fine, actually.
And now let's go ahead and further down the road.
Let's move into this directory first.
And inside that and PM in it.
DASH Why, of course, because we don't want to answer all these questions again.
And further, let me just clean the screen and we're going to say, hey, I want to install Express,
obviously, because we need to create the route.
And Razorpay, of course, is a library well-maintained, well thought out, well optimized, no need
to worry.
It is officially from the razorpay itself.
So we're going to go ahead and install all these libraries up here.
Shouldn't take much of the time and it says, hey, there is.
Okay, so it looks like there is something wrong with the library.
Anyways.
I'll check that later on that what?
Probably some type or something.
Let's open this up into code editor so that we can actually analyze it better.
Maybe, maybe there is something wrong up here with my spellings or something.
Usually not so express is there razor paste there looks fine.
Everything.
Anyways, we'll work on this part in a minute.
So let's go up here.
And now what we're going to do is we're going to create a simple methods and basic file.
So let me open up my index JS And we won't be installing Node or anything we don't need for this one.
So we're going to go ahead and simply say start this one will change to Node.
Please run index to us because this is a bare minimum project, not even bare minimum.
This is absolute basic.
Okay, so how we're going to go ahead and work on with that, we're going to go ahead and say first,
we need express and that is going to be coming up from require express.
Hopefully I type that correct.
And then we need to go ahead and create an app from Express.
Express.
There we go.
App is being created.
We're going to go ahead and later on the app, listen, I'm not even going to create a port because
it's really the basic project up here and we're going to go like this.
And say console dot log and we'll be saying that server is running at Port 4000 just like our favorite
port.
So this is all basics and I want to create a one route so that I can see at least something is running
or I have done some kind of typo or not.
So let's go ahead and run it on to the slash or the root and we'll be having a request response just
like we always do.
And we'll be saying, resort, send and let's go ahead and send a simple hi and let's see if this is
all working or not.
I have to go up here and say end PM, start and let's see.
Port is running in 4000, at least in theory it should be running up.
Let's go ahead and say localhost, 4000 and a tiny little high.
Okay, I'll take that as a one OC.
So once this is all done, that means our setup is all done.
Let's go ahead and first again, this one is going to be a little longer of a video because I want to
just at least do something up here.
So let's use to use come on up, dot use because we'll be receiving some of the stuff from the body.
So we need to make sure that Express is aware that I'm about to use a JSON in case you want to use URL
ENCODE and all of that long discussion.
So we have already done that.
Okay.
So this needs to go at the top before the roots are coming in.
So that is nice.
And now after this home route, let's go ahead and create a route.
So app app dot, obviously the post road because some sensitive data or sensitive information is coming
from that route.
Now, you can call this one as anything.
I'm going to call this one as order.
My order, your order.
Whatever you like to call that, it can be any route at all.
And then further down the road, we're going to go ahead and say, hey, request and response, go ahead
and work like that.
So how are we going to go that first?
The most important thing about the payment gateways and payment system that you need to worry about
is these payment routes are designed just to detect the money, nothing else.
They should be designed like that way.
Now, some of you might argue that we want to really check more things into this route.
Maybe somebody has manipulated the information about the payment on the way and the product was ₹500.
And he he's only sending us the data of ₹50 to buy that product.
Yes, there's a great point here, but what I want to say is that you can actually process all that
information while creating the order.
The job of this particular request is whatever the information comes in, it just deducts that payment
further down the road while creating the order.
You can actually match that the amount that is being sent to us.
Why after the processing is the exact amount that we sent it up or not, so we can match that information
there and further down the road can take the action that whether some things were manipulated on the
go or not.
But the ideal case scenario is that the payment gateway route should only be responsible for detecting
the payment.
That's it.
Nothing less, nothing more.
So that's exactly what we are doing.
You can send more information, but we won't be processing it that way.
So this is usually the ideal case.
So let's go ahead and say that you send me some amount, I go ahead and receive this.
Since this is a post route, I don't need to worry anything and I can go ahead and say, Hey, this
is the amount that I have to deduct now, I don't know further down the road how to do it.
So let's go ahead and study the API itself that we just studied.
So there we go.
Let's go ahead and break it down.
In fact, let's bring the entire Node.js code and see how this is going to work on on our code.
So let's paste this one up here.
Okay?
So let's just first see.
So I just saved it and automatically formatted the code for me.
So let's just say this is all what we got.
So instance is sending me this new Razorpay instance needs to be created.
It will ask you to provide the key and the secret.
I'll show you where that is, but it's a really easy thing.
And then first you need to create options, the amount that you are going to deduct.
Now, in this case, the amount that we are going to deduct needs to come from the body itself.
So we're going to go ahead and say, hey, this is the amount, so let's go ahead and send this one.
Instead of this, we are going to replace the amount.
So whatever you are sending me from the body itself, we'll have this amount.
But chances are high that you'll be sending me the amount as 50 or 100.
I need to multiply that by 100 so it actually converts into rupees and you don't collect just 50 passes
instead of ₹50.
So that is that currency for us is the INR, but it supports other currency as well, that is, except
we are going to keep it safe as it is.
But you can use your nano IDs or your IDs to generate a unique ID for each of these receptors.
Finally, it go ahead and say, hey, after this, we can go ahead and just create an instance order
and we can create this order.
Now this is all going nice and we can provide these options like this and function.
I won't be doing it that way actually.
I want to store or hold this reference.
I don't want to go into this one, so I'll just remove this part.
I'll just do it again.
And by the way, you can actually go ahead and keep it safe.
Let me just comment this so that it remains safe.
So what I want to do is I want to go ahead and create a simple.
Variable my order.
So this is the order available.
I'm holding everything there.
So I simply take this instance which are just about created, and I just go ahead and say, Hey, in
this instance, let's go ahead and use that instance dot orders.
And then we simply go ahead and simply go ahead and use this method which is given to us by create.
Again, reminding you this instance was created up here, I'm using the same instance and creating the
order.
I'm just holding the reference, that's all I'm doing.
And here they are passing these options.
So obviously I need to pass them as well.
Okay, now if this is all going to be successful, then all things will go.
But this will not be an instant.
So I'll have to use an A weight.
Since I'm using the weight, this entire method needs to go into a sync mode.
So there we go.
Nice and easy.
Okay.
Once this is all done, that means now I'm holding the reference.
I'm going to go ahead and return the response.
So I'm going to go ahead and say, Hey, Ress, let's go ahead and return you JSON so we can return
the status as well.
So let's go ahead and return the status as well.
I want to return a status of 200 or we can go ahead for 201 as well because new thing was created.
But I'll just go for 200 and in the JSON, we are going to pass on this information.
So in the response of this one as a JSON format onto the same route, I'm going to go ahead and give
it a simple success of true.
I also want to send him what amount was deducted so that I'm receiving from the body itself so that
I'll send as amount.
There we go.
So that he can compare further down the road, whoever is in the front end or further in the my order
section, further down on the other routes.
And I will also say that, hey, this is the order that I got and I will send you my order information.
Again, it totally depends on you how you are crafting your application.
So this is the basics of how you do it, but this is not all.
Usually in the back end you see this much of part only.
But I'll actually go one step further.
We'll show you a little bit tiny of the front end part as well, so that we can actually make a payment
and we need to insert the keys as well.
Let's go ahead and do that in the next video.