So let's keep working on our JavaScript and first of all, on line one hundred and twenty seven on my
page, labeled or named Brons Dash Plan Page HTML, I love the art of stripe and I added that before
I posted the source code and I was just sloppy on my part.
My apologies.
So we're working on this function stripe payment method handler and we're handling the situation where
there's no error.
In other words, we've got our payment method.
So what we're going to do now is, as the comment says, create a customer and subscribe to a plan.
Now, obviously, we're going to be calling some things that don't exist on the back end yet, but let's
get started writing it and we'll take care of the backend before too long.
So first of all, if we want to create a customer and we're going to create a payload and send Jason
to the back end, so I'll create a payload variable that payload equal and it'll be a JavaScript object
and I'll put a few things in here.
So the plan, for example, that's something we definitely want to know.
What plan are we subscribing the person to?
And of course, because we have that now in the widget variable, we can simply put in single quotes,
dollar sign widget DOT plan ID and then close off our single quotes.
We also want the payment method, payment method, payment underscore method, and that is going to
be equal to from the result that was handed to this function dot payment method.
We're getting this from strike, of course.
And we also want the email and I suggest document get element by ID and we're looking for cardholder
email value in the last four digits of the credit card.
And that's from result dot payment method, lowercase P. payment method, dot card to last for.
And that's probably enough for now.
So that's our payload
now, just as we did last time, will create some request options to request options.
And that will be equal to a JavaScript object and our method will be post.
And our headers will be equal to an object with two elements.
The first one is accept, and the value is applications, Jason, and the second one is content type.
Which is also application, Jason.
And our body will be Jason Stringfield and we're stratifying fine pillow, OK, once we have our payload
and our request options now we can call, fetch and we'll call a non-existent URL on the back end fetch.
And again, it's going to be using API.
So we have the correct prefix to our URL and we'll make this API slash, create dash customer dash and
dash subscribe dash to dash plant.
It's long, but it's very descriptive and it tells me exactly what's going on and we'll put a request
to options in there.
Then we'll call then and get our response and we'll convert it to Jason.
Response to Jason.
Then we'll have a function data and we'll just for right now, we'll say console log data has.
Console the log data.
We can't do anything until we get the actual back end written.
We also want to say hi to our processing button processing class list, dot and dash, none bootstraps
hide this class.
And after that, we will say set in verse in our form and we'll have to change those.
But, well, we'll do that and then we'll submit the form.
And all of that requires some work on the back end.
But this is a good start.
So in the next lecture, we'll start working on the back end that you, Earle, fetch whatever the approval
is opposed to create customer unsubscribed plan.
We'll get started on that in the next election.