So before we move on to completing an order and saving a transaction, there's a little glitch, actually
a fairly major glitch in our code that I'm sure you noticed.
And I just noticed that after I completed the most recent letter and we need to fix it.
So let's have a look and see what it is.
So right now, I have our application running and I'm looking at the virtual terminal page and I'm going
to charge, say, eight dollars and ninety nine cents to Jack Smith, whose e-mail is J at Smith dot
com.
And his credit card number is four to four to as usual.
And it's expiry date is 04.
Twenty nine.
And we'll give him a CVC of four four four.
So this should charge eight dollars and ninety nine cents to his account.
So we charge it.
And you can see the payment amount is eight hundred and ninety nine, which is exactly right, because
we're multiplying it by 10 to convert it to cents so we can avoid floating point errors.
And if I go to my stripe test dashboard and click on payments and refresh this page.
There is our eight dollars, 99 cents, that's perfect.
Now let's go back to our application and this time let's buy a widget.
So I'll buy one widget and you can see the price is ten dollars.
So I'll put in Mary Brown, whose email is Mary at Brown dot com and the same credit card number.
Zero for, say, twenty eight and some Khedive, and I'll charge it, look at the amount this time,
one followed by a whole bunch of zeros and if we go back here to our stripe dashboard and click again
on payments and refresh this page just so we get the most recent transaction, you'll see that poor
Mary was charged a thousand dollars for her ten dollar widget.
And there's a very simple reason for that.
But back to our code and we look at the terminal page.
We actually have our amount, which is fine, and we look at our strike days.
And when we calculate the amount, it's right here on line.
Forty eight in my code, this is strike dust, just partial HTML.
We get the amount and we multiply it by one hundred and that's fine for the virtual terminal page because
that's exactly what we want.
But that's not so great for the buying a widget.
So what I'm going to do is just change this to the value.
Of the field called amount.
OK, now if I reload my application and start it all over again now, I'll pay ten dollars for a widget,
but I'll pay a lot less for the amount that's entered into the terminal page so we can fix that really
easily.
We can go to our terminal page and we can find the amount part.
And I'm going to change this to charge amount and I'll change the ID to charge amount and I'll get rid
of the name attribute altogether because I don't need to post this with my form and that will take care
of it.
And I'll change this to charge about as well.
And then I'll go down to the script per toward defined J.S. and that I'll add a script tag and a closing
script tag and I'll simply add an event listener document jet element by idea and I'm going to look
for charge amount of or spell right or won't work and we'll use a function passing at the event
and I'll close everything up here so I don't forget and I'll do a simple test here.
If we don't target
value is not exactly equal to empty string and somebody entered an amount and I'll do something else.
I'll do something else.
And what I'll do here on line 64 is I will refer to an element I haven't added yet, but wire that in
a minute, document that element by ID and I'm going to look for an amount which I'll add is a hidden
field momentarily that will set its value equal to the target value times when one hundred, not one
thousand or will be back in the problematic area.
Otherwise, I'll set the value of the hidden field amount, which I'll add momentarily.
Equal to zero.
OK, and I will just come up here where my hidden fields are, and I'll add one, which I'll call them
out and I'll get the ID around.
OK, so that will solve the problem.
So this way, any time we enter information on the virtual terminal, we'll take the amount entered
and multiply by 100.
Otherwise we'll just take the amount that's on the Bye Once page, which is right here.
And as you can see, the amount for that can be fined about.
Right here that's taken from the database and the in the database, our widget prices are stored as
integers, so this solves that problem.
OK, time to move on.