We've now got some code inside of here to actually create a charge and build user's credit card.
They're not going to try to test this out manually if we test out manually however I want you to understand
only about the stripe API.
Right now if I go back over to my stripe dashboard here it is right here.
I'm currently operating my stripe account in what is called test mode.
So if you look at the very bottom left hand side you can see something down here that says viewing test
data and you'll see that little toggle around several different locations while your account is in test
mode.
You are not actually working with any real money whatsoever.
And so we can tried to make API requests.
We can pretend that we are building a user's credit card but in the end no money is moving around whatsoever.
It's only once we decide that we want to take our application public deploy it that we will want to
toggle off test mode which is a little bit of involved process involves verifying a banking account.
A couple of other steps which is something we're not going to go through because it really starts to
get into the money side of things.
So how are we going to actually test this out while our stripe account is in the test mode.
Well at a very practical level what we really need to do here is first create a ticket.
We then have to create an order and then we have to try to make a request to this payments and point
but how are we going to make a request this payment end point without a token.
Once again our account is in test mode right now our stripe account is in test mode while our account
is in test mode.
There is a very special token that we can provide that will always succeed with the stripe API.
In other words there's kind of like a secret escape hatch of sorts or a little shortcut a very specific
token that we can provide.
That is always going to lead to a successful charge.
And that is how we can test and make sure that our code here can successfully Bill a credit card.
We'll show you exactly what that token is in a moment.
First let's kind of do a little bit of setup.
We're going to create a ticket we'll create an order and then eventually create a payment over inside
of postman as usual.
I will first make sure that I am signed in.
Yep looks like I am then going to create a new ticket.
The post request to API tickets.
I'll send that off.
There's my I.D. I'm going to copy the I.D. I'll then create an order for this ticket.
So a post request to API orders on enter and my ticket idea right there send that off and here's my
new order and I'm going to take that I.D. And do keep in mind that we now have a 60 second window to
actually purchase this order.
So we do have to write out some code here rather quickly.
Chances are we'll go over that 60 second timer.
No problem.
We can just go through the process of creating another ticket and an order so I can open up a new tab
I can make a post request to HDD P.S. ticketing dot Dev flash API slash payments under headers on entering
content type of application.
Jason her body all enter raw.
I'll make sure Jason is left on the right.
And then remember we are required to provide an order I.D. and that token for the order I.D. I'll paste
in the order I.D. that I just copied a moment ago from our previous request to create the order and
then for the token normally this token value would come from the stripe library running inside of our
browser.
So this would be something that's going to take the user's actual credit card and give us back a token.
But in this case we have not done anything around the browser just yet.
This is where that little shortcut comes into play.
We're going to enter in a very special token here.
That is always going to work 100 percent of the time or stripe accounts that are in the test mode and
it's very special little token is T OK underscore visa.
So again this is always going to work.
We can bill it for just about whatever money we can imagine and the requested always exceed all right
so now we should be able to send this request off and chances are it's been over 60 seconds.
So I suspect that our order has probably expired by this point in time.
We could send the request anyways and see what happens.
And as a matter fact yep it looks like my order has been canceled because I have left that time out
window at 60 seconds right now.
Did you have to very quickly go through the process once again of creating a ticket and then order and
then I'll update the order.
I.D. it's going to make another ticket there's my I.D. I'll then make another order.
I'll take the order I.D. and then provide that to the agents API so now send this off and I get back.
Success true which in theory means that we have now successfully charged some amount of money the stripe
so that means that this call right here worked as expected to actually verify that worked as expected.
We should be able to go over to our stripe dashboard and take a look at all the different charges we
have created over time to back on the stripe dashboard on the left hand side.
I'll go to payments and I should see a payment right there for 15 dollars.
Yeah.
So that's the payment that I just created two seconds ago that deputy means that we were able to create
a charge and Bill some money to our users let's say this looks pretty good.
We've now verified that this works correctly.
Let's also make sure that it works incorrectly as well.
So let's try providing a different token and just see what happens
I will once again create a ticket.
Very quickly
I will create an order out of that ticket here's my order and I'll create a payment using that order
I.D. And this time around rather than using that little fake always works token I'll put in some gibberish
like so so if I now send this off I'll see an error of something went wrong and if I go to my eternal
window running scaffold I should see an error being thrown from the stripe library.
Yep.
Here's the error right here.
Now if you do not see an error right here that is totally ok however we will want to make sure that
we only see an error as a message right here.
And the reason I say that you might not see an error at your terminal is just in case you did not put
a console log into our final version of that era handle handler middleware that we put together okay.
Well I'd say this looks pretty good.
We are now able to build some money to a user.
And we've gone through it with some manual testing.
But we should probably try to add in some kind of automated test as well.
Let's take a look and figure out how we could do that in just a moment.