WEBVTT

00:03.910 --> 00:05.500
Hated everyone had their share.

00:05.500 --> 00:08.290
And finally, a lot of you have been waiting for this project.

00:08.290 --> 00:10.420
But let me spoil your surprise.

00:10.630 --> 00:12.550
It's not really a complicated project.

00:12.550 --> 00:13.380
It's really simple.

00:13.390 --> 00:16.240
Payment gateway is just complicated in people's brain.

00:16.240 --> 00:21.160
It's really easy now how you protect some of the information that can be, but really it's easy.

00:21.160 --> 00:26.380
So coming onto the point, Razorpay Razorpay actually offers you a whole lot of services, not just

00:26.380 --> 00:26.800
the payment.

00:26.800 --> 00:29.710
It has so many suite of product that they actually give us on.

00:29.710 --> 00:33.940
So the important thing is that you land up onto the correct documentation, which I've given you here,

00:33.940 --> 00:36.040
so you can just land up directly from there.

00:36.040 --> 00:40.180
So what we're going to do is we just simply click up here and which opens up the same page that I've

00:40.180 --> 00:42.040
already opened at multiple places.

00:42.040 --> 00:43.570
So I'll just keep the dashboard here.

00:43.570 --> 00:44.770
Dashboard is really important.

00:44.770 --> 00:47.950
You need to sign up for them to actually get in test mode and get all the keys.

00:47.950 --> 00:50.500
I'll show you from where you can get that really easy.

00:50.500 --> 00:55.480
So you can see they have a lot of information going in so you can go ahead and look for orders and payments

00:55.480 --> 00:56.170
and a whole lot of things.

00:56.170 --> 00:57.640
We are going to be working on orders.

00:57.640 --> 01:02.020
So any time you want to capture a payment that is called as order, so somebody has placed order of

01:02.020 --> 01:06.970
something, maybe for a course for a t shirt to buy a car or property, whatever that is.

01:06.970 --> 01:08.620
But that is called as orders.

01:08.620 --> 01:12.940
They have information about the payments as well that you can go ahead and look for all about the payments

01:12.940 --> 01:16.600
that what are the test card capture settings, international payments.

01:16.600 --> 01:18.490
There's a whole lot of things that you can do.

01:18.520 --> 01:22.330
We are going to be working on not the payments but actually on the orders.

01:22.330 --> 01:25.360
So here is some information about the orders that they are having.

01:25.360 --> 01:28.240
A couple of states created, attempted or paid.

01:28.240 --> 01:32.650
So maybe you are designing an application in which you store all of the attempted order as well.

01:32.650 --> 01:36.940
Maybe you want to revert and call back to the user that, hey, you have attempted an order, haven't

01:36.940 --> 01:38.470
completed that, so what's going on?

01:38.470 --> 01:39.910
So you can go ahead and do that.

01:39.910 --> 01:42.160
So this is how the whole information goes on.

01:42.160 --> 01:48.250
So order is this is the order state when it is being created, it is being authorized and paid and it

01:48.250 --> 01:49.870
can also go into the different states.

01:49.870 --> 01:52.330
It can be failed, it can be authorized and refunded.

01:52.330 --> 01:54.040
It can be captured, then refunded.

01:54.040 --> 01:57.790
So there's a nice diagram and flow really, really very simple.

01:58.390 --> 02:00.880
Now what we're going to work on is creating the orders.

02:00.880 --> 02:03.430
So obviously they say, hey, you cannot create the order from here.

02:03.430 --> 02:05.140
You need to go ahead and look for the API.

02:05.170 --> 02:09.250
That's exactly what makes us happy that we want to do everything through the APIs.

02:09.250 --> 02:10.870
So I click on this one again.

02:10.870 --> 02:13.570
A lot of information opens up that how you are going to do this.

02:13.570 --> 02:16.780
All I'm interested in is this one, so create an order.

02:16.780 --> 02:22.630
So the documentation is pretty phenomenal that if you look into this so and by the way, they also if

02:22.630 --> 02:27.160
you scroll a little bit, they give you the entire collection so you can download the entire post collection

02:27.160 --> 02:30.190
to play around and all these fields and everything has pre-filled.

02:30.190 --> 02:32.430
So you can just check out that how things actually works.

02:32.440 --> 02:34.060
On what response you get.

02:34.060 --> 02:38.230
This is phenomenal and you can just open this entire collection in The Postman.

02:38.230 --> 02:41.530
This is like really well, the best thing they can give coming back.

02:41.800 --> 02:43.810
So creating the order, just click on this one.

02:43.810 --> 02:45.130
So this is how you create the order.

02:45.130 --> 02:50.080
You need to send a post request to slash orders, but this is not actually the URL you need to look

02:50.080 --> 02:53.350
on to the right side and look for the whatever the language you are working on.

02:53.350 --> 02:55.510
In this case, we are working with the Node.js.

02:55.510 --> 03:01.780
So this is all of the information that is required to capture the payment, the required field or currency

03:01.780 --> 03:02.530
to be passed on.

03:02.530 --> 03:05.740
And the amount notice the amount is in the smallest currency in it.

03:05.740 --> 03:10.450
In our case in India it is paisa or pesa, whatever you call this one.

03:10.450 --> 03:14.440
So this is all being kind of a divided by 100.

03:14.440 --> 03:16.990
So this is actually a price for ₹500.

03:16.990 --> 03:18.550
Multiply by header you get the idea.

03:18.550 --> 03:19.540
This is basic.

03:19.630 --> 03:22.240
So this is how we go ahead and create that.

03:22.240 --> 03:26.770
Now again, you can pass on more fields, like you can pass on notes or partial payment as true and

03:26.770 --> 03:28.510
false and all of that information.

03:28.510 --> 03:30.310
We are not that much interested in that.

03:30.310 --> 03:32.530
We just want to have this much of information.

03:32.530 --> 03:33.700
So I'll come back here first.

03:33.700 --> 03:37.300
Let's go ahead and create a simple folder and try to go with that.

03:37.300 --> 03:39.880
So I'm going to go ahead and create a new folder.

03:39.880 --> 03:42.700
So let me just do all of this via my terminal.

03:42.820 --> 03:45.130
So I'll go to desktop.

03:45.130 --> 03:50.410
And on that I'll, I, I will go into AE back and I can see all of my projects are here.

03:50.410 --> 03:52.240
So let's go ahead and create another directory.

03:52.240 --> 03:55.060
Call this one as Razorpay.

03:56.400 --> 03:57.300
Razorpay.

03:57.450 --> 03:59.190
Yeah, that's that's fine, actually.

03:59.820 --> 04:02.280
And now let's go ahead and further down the road.

04:02.580 --> 04:04.620
Let's move into this directory first.

04:06.550 --> 04:08.680
And inside that and PM in it.

04:09.010 --> 04:13.120
DASH Why, of course, because we don't want to answer all these questions again.

04:13.120 --> 04:19.270
And further, let me just clean the screen and we're going to say, hey, I want to install Express,

04:19.270 --> 04:21.010
obviously, because we need to create the route.

04:21.010 --> 04:26.590
And Razorpay, of course, is a library well-maintained, well thought out, well optimized, no need

04:26.590 --> 04:26.890
to worry.

04:26.890 --> 04:29.020
It is officially from the razorpay itself.

04:29.020 --> 04:32.140
So we're going to go ahead and install all these libraries up here.

04:32.160 --> 04:37.030
Shouldn't take much of the time and it says, hey, there is.

04:37.690 --> 04:40.930
Okay, so it looks like there is something wrong with the library.

04:42.280 --> 04:42.820
Anyways.

04:42.820 --> 04:44.740
I'll check that later on that what?

04:44.740 --> 04:46.090
Probably some type or something.

04:46.090 --> 04:49.780
Let's open this up into code editor so that we can actually analyze it better.

04:50.020 --> 04:54.100
Maybe, maybe there is something wrong up here with my spellings or something.

04:54.100 --> 04:58.240
Usually not so express is there razor paste there looks fine.

04:58.240 --> 04:59.110
Everything.

04:59.530 --> 05:02.710
Anyways, we'll work on this part in a minute.

05:02.710 --> 05:03.640
So let's go up here.

05:03.640 --> 05:07.510
And now what we're going to do is we're going to create a simple methods and basic file.

05:07.600 --> 05:14.980
So let me open up my index JS And we won't be installing Node or anything we don't need for this one.

05:14.980 --> 05:19.420
So we're going to go ahead and simply say start this one will change to Node.

05:19.420 --> 05:24.070
Please run index to us because this is a bare minimum project, not even bare minimum.

05:24.070 --> 05:25.480
This is absolute basic.

05:25.920 --> 05:29.950
Okay, so how we're going to go ahead and work on with that, we're going to go ahead and say first,

05:29.950 --> 05:37.720
we need express and that is going to be coming up from require express.

05:37.720 --> 05:39.160
Hopefully I type that correct.

05:39.160 --> 05:42.850
And then we need to go ahead and create an app from Express.

05:44.520 --> 05:45.690
Express.

05:45.690 --> 05:46.260
There we go.

05:46.260 --> 05:47.450
App is being created.

05:47.460 --> 05:52.710
We're going to go ahead and later on the app, listen, I'm not even going to create a port because

05:52.710 --> 05:57.180
it's really the basic project up here and we're going to go like this.

05:59.420 --> 06:12.530
And say console dot log and we'll be saying that server is running at Port 4000 just like our favorite

06:12.530 --> 06:12.980
port.

06:13.670 --> 06:18.440
So this is all basics and I want to create a one route so that I can see at least something is running

06:18.440 --> 06:20.570
or I have done some kind of typo or not.

06:20.570 --> 06:27.080
So let's go ahead and run it on to the slash or the root and we'll be having a request response just

06:27.080 --> 06:28.220
like we always do.

06:28.760 --> 06:36.080
And we'll be saying, resort, send and let's go ahead and send a simple hi and let's see if this is

06:36.080 --> 06:37.460
all working or not.

06:37.550 --> 06:41.930
I have to go up here and say end PM, start and let's see.

06:41.930 --> 06:45.440
Port is running in 4000, at least in theory it should be running up.

06:45.440 --> 06:49.500
Let's go ahead and say localhost, 4000 and a tiny little high.

06:49.560 --> 06:52.240
Okay, I'll take that as a one OC.

06:52.850 --> 06:55.580
So once this is all done, that means our setup is all done.

06:55.580 --> 06:59.480
Let's go ahead and first again, this one is going to be a little longer of a video because I want to

06:59.480 --> 07:01.370
just at least do something up here.

07:01.430 --> 07:09.290
So let's use to use come on up, dot use because we'll be receiving some of the stuff from the body.

07:09.290 --> 07:14.390
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

07:14.390 --> 07:16.370
ENCODE and all of that long discussion.

07:16.370 --> 07:17.690
So we have already done that.

07:18.170 --> 07:18.360
Okay.

07:18.440 --> 07:20.900
So this needs to go at the top before the roots are coming in.

07:20.900 --> 07:22.190
So that is nice.

07:22.280 --> 07:25.310
And now after this home route, let's go ahead and create a route.

07:25.310 --> 07:31.910
So app app dot, obviously the post road because some sensitive data or sensitive information is coming

07:32.000 --> 07:33.050
from that route.

07:33.080 --> 07:34.820
Now, you can call this one as anything.

07:34.820 --> 07:36.350
I'm going to call this one as order.

07:36.350 --> 07:38.030
My order, your order.

07:38.030 --> 07:40.640
Whatever you like to call that, it can be any route at all.

07:40.910 --> 07:45.170
And then further down the road, we're going to go ahead and say, hey, request and response, go ahead

07:45.170 --> 07:46.340
and work like that.

07:47.030 --> 07:49.040
So how are we going to go that first?

07:49.040 --> 07:53.660
The most important thing about the payment gateways and payment system that you need to worry about

07:53.660 --> 07:58.520
is these payment routes are designed just to detect the money, nothing else.

07:58.520 --> 08:00.350
They should be designed like that way.

08:00.350 --> 08:04.640
Now, some of you might argue that we want to really check more things into this route.

08:04.640 --> 08:11.750
Maybe somebody has manipulated the information about the payment on the way and the product was ₹500.

08:11.750 --> 08:15.710
And he he's only sending us the data of ₹50 to buy that product.

08:15.890 --> 08:20.990
Yes, there's a great point here, but what I want to say is that you can actually process all that

08:20.990 --> 08:22.820
information while creating the order.

08:22.820 --> 08:28.640
The job of this particular request is whatever the information comes in, it just deducts that payment

08:28.640 --> 08:31.040
further down the road while creating the order.

08:31.040 --> 08:34.610
You can actually match that the amount that is being sent to us.

08:34.610 --> 08:40.490
Why after the processing is the exact amount that we sent it up or not, so we can match that information

08:40.490 --> 08:45.050
there and further down the road can take the action that whether some things were manipulated on the

08:45.050 --> 08:45.890
go or not.

08:45.890 --> 08:51.620
But the ideal case scenario is that the payment gateway route should only be responsible for detecting

08:51.620 --> 08:52.130
the payment.

08:52.130 --> 08:52.790
That's it.

08:52.790 --> 08:54.200
Nothing less, nothing more.

08:54.200 --> 08:55.880
So that's exactly what we are doing.

08:56.030 --> 08:59.510
You can send more information, but we won't be processing it that way.

08:59.510 --> 09:01.130
So this is usually the ideal case.

09:01.130 --> 09:04.610
So let's go ahead and say that you send me some amount, I go ahead and receive this.

09:04.610 --> 09:08.480
Since this is a post route, I don't need to worry anything and I can go ahead and say, Hey, this

09:08.480 --> 09:12.260
is the amount that I have to deduct now, I don't know further down the road how to do it.

09:12.260 --> 09:15.860
So let's go ahead and study the API itself that we just studied.

09:15.860 --> 09:17.540
So there we go.

09:18.020 --> 09:19.430
Let's go ahead and break it down.

09:19.430 --> 09:25.100
In fact, let's bring the entire Node.js code and see how this is going to work on on our code.

09:25.100 --> 09:26.720
So let's paste this one up here.

09:27.290 --> 09:27.530
Okay?

09:27.620 --> 09:29.030
So let's just first see.

09:29.330 --> 09:32.480
So I just saved it and automatically formatted the code for me.

09:32.480 --> 09:34.130
So let's just say this is all what we got.

09:34.130 --> 09:38.450
So instance is sending me this new Razorpay instance needs to be created.

09:38.450 --> 09:40.760
It will ask you to provide the key and the secret.

09:40.760 --> 09:43.280
I'll show you where that is, but it's a really easy thing.

09:43.280 --> 09:46.910
And then first you need to create options, the amount that you are going to deduct.

09:46.940 --> 09:51.020
Now, in this case, the amount that we are going to deduct needs to come from the body itself.

09:51.020 --> 09:55.040
So we're going to go ahead and say, hey, this is the amount, so let's go ahead and send this one.

09:55.040 --> 09:57.230
Instead of this, we are going to replace the amount.

09:57.230 --> 10:01.160
So whatever you are sending me from the body itself, we'll have this amount.

10:01.160 --> 10:05.030
But chances are high that you'll be sending me the amount as 50 or 100.

10:05.030 --> 10:11.600
I need to multiply that by 100 so it actually converts into rupees and you don't collect just 50 passes

10:11.600 --> 10:12.860
instead of ₹50.

10:13.010 --> 10:17.320
So that is that currency for us is the INR, but it supports other currency as well, that is, except

10:17.330 --> 10:19.610
we are going to keep it safe as it is.

10:19.610 --> 10:25.340
But you can use your nano IDs or your IDs to generate a unique ID for each of these receptors.

10:27.170 --> 10:32.990
Finally, it go ahead and say, hey, after this, we can go ahead and just create an instance order

10:32.990 --> 10:34.490
and we can create this order.

10:34.520 --> 10:39.350
Now this is all going nice and we can provide these options like this and function.

10:39.530 --> 10:42.020
I won't be doing it that way actually.

10:42.020 --> 10:44.570
I want to store or hold this reference.

10:44.570 --> 10:47.690
I don't want to go into this one, so I'll just remove this part.

10:47.690 --> 10:48.650
I'll just do it again.

10:48.650 --> 10:51.770
And by the way, you can actually go ahead and keep it safe.

10:51.770 --> 10:54.800
Let me just comment this so that it remains safe.

10:55.550 --> 10:58.670
So what I want to do is I want to go ahead and create a simple.

10:59.650 --> 11:01.450
Variable my order.

11:01.450 --> 11:02.830
So this is the order available.

11:02.830 --> 11:04.090
I'm holding everything there.

11:04.150 --> 11:09.730
So I simply take this instance which are just about created, and I just go ahead and say, Hey, in

11:09.730 --> 11:16.330
this instance, let's go ahead and use that instance dot orders.

11:16.330 --> 11:20.980
And then we simply go ahead and simply go ahead and use this method which is given to us by create.

11:21.610 --> 11:26.830
Again, reminding you this instance was created up here, I'm using the same instance and creating the

11:26.830 --> 11:27.130
order.

11:27.130 --> 11:29.290
I'm just holding the reference, that's all I'm doing.

11:29.440 --> 11:31.150
And here they are passing these options.

11:31.150 --> 11:33.220
So obviously I need to pass them as well.

11:34.600 --> 11:38.350
Okay, now if this is all going to be successful, then all things will go.

11:38.350 --> 11:40.060
But this will not be an instant.

11:40.060 --> 11:42.070
So I'll have to use an A weight.

11:42.490 --> 11:46.840
Since I'm using the weight, this entire method needs to go into a sync mode.

11:47.410 --> 11:48.220
So there we go.

11:48.220 --> 11:49.150
Nice and easy.

11:50.490 --> 11:50.740
Okay.

11:50.760 --> 11:53.760
Once this is all done, that means now I'm holding the reference.

11:53.760 --> 11:56.200
I'm going to go ahead and return the response.

11:56.200 --> 12:01.320
So I'm going to go ahead and say, Hey, Ress, let's go ahead and return you JSON so we can return

12:01.320 --> 12:02.310
the status as well.

12:02.310 --> 12:04.260
So let's go ahead and return the status as well.

12:04.920 --> 12:11.460
I want to return a status of 200 or we can go ahead for 201 as well because new thing was created.

12:12.210 --> 12:16.650
But I'll just go for 200 and in the JSON, we are going to pass on this information.

12:16.920 --> 12:23.340
So in the response of this one as a JSON format onto the same route, I'm going to go ahead and give

12:23.340 --> 12:26.910
it a simple success of true.

12:27.720 --> 12:32.880
I also want to send him what amount was deducted so that I'm receiving from the body itself so that

12:32.880 --> 12:34.410
I'll send as amount.

12:35.730 --> 12:36.600
There we go.

12:36.600 --> 12:41.700
So that he can compare further down the road, whoever is in the front end or further in the my order

12:41.700 --> 12:43.710
section, further down on the other routes.

12:43.710 --> 12:49.500
And I will also say that, hey, this is the order that I got and I will send you my order information.

12:49.680 --> 12:53.160
Again, it totally depends on you how you are crafting your application.

12:53.160 --> 12:56.760
So this is the basics of how you do it, but this is not all.

12:56.790 --> 12:59.490
Usually in the back end you see this much of part only.

12:59.820 --> 13:01.920
But I'll actually go one step further.

13:01.920 --> 13:06.360
We'll show you a little bit tiny of the front end part as well, so that we can actually make a payment

13:06.360 --> 13:08.070
and we need to insert the keys as well.

13:08.100 --> 13:10.140
Let's go ahead and do that in the next video.
