Hey, did everyone that they share and this video we're going to work on the controllers, which will
be associated for simply capturing the payment using Stripe.
But before we move on there, I would like to bring your attention to one very important thing.
This is all related to on which in which country actually you are located in.
If you are located in India and you have made the currency as type of USD, this is not going to be
allowed.
Neither the euro is going to bail out.
You have to make sure that the currency is INR for the Indian account that are associated with the stripe.
In case you are watching it from outside of India, then you can make it a dollar or a euro.
But again, it is very important for Indians to understand that our payment system works a little bit,
behaves a little bit different than the rest of the other world.
So having it an INR is really important.
And on top of that it will open up an intent that it is going to be a success or is it going to be a
failure?
Let's go ahead and check it out.
That how this is going to work.
So first and foremost is let's go back up here and create some of the controllers.
So let's go ahead and close this one.
All the keys and everything are here.
Let's go ahead and create a controller for that.
So all of the payments related information are going to go into payment controller.
Controller G is of course.
There we go.
All we need here is actually big promise and nothing more than that.
So big promise.
No, it's not going to suggest so I'll bring it from the product controller.
Do we need anything else since we are not working on any model or anything like that.
So we don't need that.
We just need a big promise.
So what we're going to do now, the first thing is that if somebody makes a request to us that, Hey,
I want to grab the public key, I should be able to give him the public key.
Now, this is not really compulsory.
This is not really necessary.
We're going to call this one s send stripe keys or key, rather.
That would be accurate.
So we're going to go ahead and say, hey, this one is going to be wrapped around the big promise just
like that.
And this is going to we don't need a sync code in this case.
But still, since we are following the routine, let's go ahead and say request, response and the next.
There we go, just like that.
Now all we are going to do is directly anybody makes a get request on this, we are going to go ahead
and simply send a resort status of 200.
We don't need even need to send a success or any message like that.
We're going to go ahead and directly send a JSON response like this.
And in this JSON response, we are going to go ahead and say, hey, your stripe key is actually coming
from process Dot and V and let's go ahead and see what did we call this one?
So this is processed or D and V, so this is the stripe key.
And again, remember and my bad, I forgot to add an equal sign there.
So there we go.
So let's go ahead and save this one and go ahead and say that process dot E and V dot strip key.
So that's it.
That's all.
And again, I know this, this sounds really weird that why even we are doing it.
In fact, I don't do it in much of the cases.
I directly like to inject these keys because it's totally safe to give this key.
Don't panic out in case this secret actually goes up.
That's the time to panic, not anything else.
So totally.
This is not really a method to work on it.
This is really the simplest of all.
The one.
Okay, so let's go ahead and make a copy of this one.
So this is kind of a boring stuff that we have done.
Let's go ahead and now capture the payment.
So this one is going to be simply, hey, anybody who wants to capture the payment, so this is going
to be that out.
So we're going to say capture stripe payment.
Now why I'm calling it as capture stripe payments, because we will be having a raise or pay payment
as well and we'll be similarly sending the reserve keys as well.
So this is how it's going to work now for capturing the Razorpay payment.
First we need to bring in the Razer pay.
Let's go ahead and see how to do that from the documentation as well.
So we're going to go ahead and say, hey, we need to bring up like this.
Let's go ahead and at the very top, let's go ahead and say this comes up like this and this is a stripe
is going to be required.
And then it says, hey, I need a key value up here.
This is actually a your secret key.
So let's go ahead and remove that.
And the good thing that I like about is it says ask for secret key and pay for public key.
So let's go ahead and say we are going to say process dot, E and V dot and we need to change this one
into the stripe secret.
So let's copy this and there we go.
So now as just exactly as a stripe said, we have worked exactly on that.
Let's go ahead and C move on there.
So let's copy the next step.
This is the exact step that we need to go ahead and copy that.
Let's go ahead and remove everything from the inside, from capturing the stripe payment.
This is how we are going to work on that.
So we basically need to actually capture this payment intent and send and work on with that.
In fact, we don't need this line at all.
Let's go ahead and cut this out, make sure this changes to inner this is really, really important.
But I cannot actually go ahead and just put an amount like this.
This is going to be a hardcoded value.
The amount will be sent to us by request, body, dot amount.
Now again, as I mentioned, the whole job of this entirety of the thing is to simply go ahead and just
capture the amount, capture the payment, whatever the amount is being mentioned further down the road,
you can actually match the values that whatever is being sent to us is only that the thing which is
being captured, or maybe you want to match it, some of the products and all of the logic that goes
into the order itself.
Not here.
Okay, now optionally what you can do, although you don't need it, but this is optional.
So I'm going to go ahead and add an optional here that you can actually make sure that the integration
check can also be done.
So there are a lot of meta properties in this one.
I'm going to go ahead and say, hey, metadata.
And there we go.
This one is known as the integration check.
So integration underscore check and this is actually a good thing.
You'll find a lot of documentation actually talk about this that go ahead and provide some of the metadata
as well.
Payment, that's it.
And this is something that you're going to find on StackOverflow and everywhere.
Again, this is optional.
You don't need this.
And that's basically it.
You have got this payment intent and we already studied that.
This payment intent is actually a big, gigantic object.
So payment intent object and you can extract any value that you like.
As I said, this client secret is one of the favorite values and this ID is one of the favorite values.
You can either dump and load the entirety of this object onto the front end or whoever is handling the
remaining of the process.
But I won't be doing it.
I would rather be just grabbing this client secret.
But again, it's up to you.
You want to send the entirety of the object, go ahead and do that.
Now, once this is all done, that means payment has been captured.
Otherwise, it's going to give you a response that, hey, payment was not captured and the the metadata
is not being going to be created there.
So let's go ahead go ahead and say it as status.
And this is going to be a status of 200 if everything goes right.
And then we're going to go ahead and say JSON and inside that an object.
So we're going to go ahead and success is going to be true.
And once the success is true, let's go ahead and simply go ahead and send a client underscore secret.
And that client underscore secret will be coming from the same payment intent.
Feel free to load or unload the entirety of that.
It's up to you.
Or maybe you want to send an ID as well.
So let me write that you you can optionally send ID as well.
And I'm pretty sure that by this point of the time since you have watched the entirety of the course,
it shouldn't be a big deal.
So totally you capturing the payment is like really as simple as it could be.
And that's it.
We have done with the payment.
That's all what it takes.
Now let's go ahead and move on and simply work with the Razorpay APIs as well and how we can create
a method from the Razorpay as well.
Let's go ahead and catch up in the next video.