Hey, did everyone.
Thanks here and welcome to another section.
Now, so far what we have seen.
This is to be honestly the majority of what you'll be doing as a developer.
Now, surely there can be more complexity that comes up.
There might be more features, but this is majorly over all of the mongoose and MongoDB that works through.
Now, one additional layer that comes up is handling the third party libraries or third party SDK is
one of them is our topic.
In fact, two of them is our next topic, which is working on the payment system.
Now, the way how you work with the payment system, maybe there are some other third party services
or SDK that come in.
You simply go ahead, read their docs and just basically just follow them.
And it's pretty easy.
We have already discussed quite a lot about the Razorpay, but still we are going to inject that also.
But we will also be working on the stripe as well.
We haven't talked much in depth about the stripe, so we're going to do that in this video.
Let's go ahead and talk on that one.
So obviously, first, you will need an account on Stripe.
It's free, so go ahead and create one.
This is my dummy account that I use for all of the tutorial that I do up here, as well as in the in-person
bootcamps as well.
Now here you can see there is a simply publishable key's and secret available directly, but you can
actually go into the developers and click on the API keys and they revamp their website quite a lot.
So just go ahead, look for developers, an API key somewhere and you'll be able to find that and you
can just click on it and it will copy that.
And similarly for the secret key.
Now the most important thing inside our code base, we have this dot E and V file and these keys need
to go here.
Absolutely no exception at all.
So we're going to go ahead and say, this is my stripe and this is going to be API key and another one
is going to be Stripe secret.
There we go.
Let's go ahead and put an equal sign and there we go.
So this is the first one, which is my API key.
And let's not forget our this test key as well, which is the secret.
So this publishable key can go anywhere.
This is like a public key and you can go ahead and add it on to the front end and wherever you like.
The secret here actually always remains on our back end, so we are going to go ahead and reveal this
one.
And of course, I do change them quite often.
So no big deal.
We're going to go ahead, copy this and we're going to go ahead and paste that up here.
So there we go.
Now my application is all good enough, so it is having both the keys available.
Similarly, we will be adding the Razorpay keys and all of that.
So we're going to hide that now.
So this part is all done and this is basically all we need from this page.
And you can go back on to home page and see that how many payments have come in and all of that.
So these are all part of the test being done from the previous courses or some other kind of tutorials
that I was making.
Okay.
Moving on now we need to go ahead and look into the documentation of Stripe.
So let's go ahead and see that how we can capture the payment, just like in the razorpay we did that
exactly same.
So it offers a whole bunch of services.
What we are interested is in online payment and we want to just accept the payment.
So at the time of accepting a payment, let's go ahead and see that how we can do that.
Of course I want to do that on the Web.
The rest of the others are available as well.
And I want to set up this stripe.
And again, yours might be selected on Ruby or Python or something.
We are interested in Node.js.
So step one is install the stripe.
And again, in case you did notice earlier as well that yes, Stripe is already included.
So Stripe and the Razorpay both are included.
So we don't need to do this a step.
We have already worked on that.
Now next thing is you really want to study this diagram here that how and what happens when the entire
payment flow actually goes on.
This will help you to understand the entire architecture of the application.
I highly recommend to spend probably 5 to 10 minutes onto this one once you are done with that.
These are all the code that we are going to be writing and we'll be using.
So first is obviously you require the stripe and provide all the configuration just right up here as
soon as you call it.
And after that, you have to simply say payment intent is going to be a red stripe payment intent and
it's going to create it requires amount and the currency.
And then you can add the payment method types as well.
Maybe you want to accept a card, maybe you want to use P two for I don't know what that is.
I don't really mention this one.
So by default this is being handled by the frontend engineers itself that what kind of payment methods
you accept.
We usually just go ahead and say, hey, just go ahead and take these two things.
That's it.
And you can go ahead and check more onto this.
They give you more example about how to create the app.
You have to simply get the secret or something like this in case you want to check that up.
There is a server side rendering as well available.
We won't be needing that.
We just needed that method that how to capture the payment and that's pretty much it.
Now if you scroll a little bit up here, you will also notice that they also said that, okay, once
you have taken the payment, then what to do next, what kind of data you are going to receive.
So they say they are the parameters that you receive, the payment intent and payment intent client
secret as what you'll be getting.
And you can study more about this payment intent object up here.
So this is the entire client secret that you receive.
Let's.
Go ahead and click on that.
And it's going to give you the entire object.
You can study that.
So this is the entire payment intent object that we actually go ahead and get receive up here.
So there is a lot that you can do, provide invoices and currencies and a whole bunch of other things.
Majority of the time, people like to store this client, underscore secret into their database so that
they know that this is actually a valid kind of a transaction that has happened.
Maybe optionally, they want to store the ID of that payment as well.
So again, you can extract as many objects as you want to or you can send it on to the front end, guys,
that, hey, this is all being processed.
This is all what we have done.
So told you, it's really simple.
Not a big deal at all.
You just need to file up just one method and simply go ahead and grab that.
Now the important thing is the key and the secret.
Now public key goes on to the front end.
The secret key always remain to us.
So it's up to you that how you want to transfer that publishable key?
You can either transfer it via sending it directly to your front end developer and say, Hey, just
put this key.
Or you can make a method that whenever somebody requests that method, I'll just transfer the key.
So again, both are exactly same.
No big deal at all.
Let's go ahead and catch up in the next video and actually configure the stripe.