Last Updated: 19 September 2024 | Change Log
Create sessionState
Create a sessionState
by sending your customer's card details.
sessionState
A sessionState
is a unique identifier for your customer's card details, which is generated by the SDK.
Using the sessionState
Once you've received the sessionState
, use the sessionState
to generate a verified token to take a payment.
Getting the sessionState
Submitting the form
To create a sessionState
you need to submit your customer's card details.
Here's an example of what you must do to generate a sessionState
.
JavaScript
Prevent default submit
function (error, checkout) { if (error) { console.error(error); return; } form.addEventListener("submit", function (event) { event.preventDefault(); checkout.generateSessionState(function (error, sessionState) { if (error) { console.error(error); return; } // session state for card details alert(sessionState); }); }); }
Event listener
The form.addEventListener("wp:field:change", function (event)...
function waits for your customer to click the submit button.
The event.preventDefault()
stops the form from being submitted. Invoking this action is optional.
Generate sessionState
To generate a sessionState
you must invoke the checkout.generateSessionState
method.
Create a Verified token
Once you've received a sessionState
you must create a verified token to take a payment.
Next steps