useCheckoutSession
hook provides access to the current checkout session data and functionality to update it. It gives you access to both the parsed, platform-agnostic checkout session data and the raw session data from the e-commerce platform.
Import
Usage
Return Value
Returns an object with:session: CheckoutSession<Extensions>
- The parsed, platform-agnostic checkout session conforming to your custom schemarawSession: unknown
- The original session data from the e-commerce platform (VTEX, Shopify, etc.) in raw/unparsed formupdateSession: (session: CheckoutSession<Extensions>, rawSession: unknown) => void
- Function to update both the parsed and raw session datasessionValidity?: ValidationSuccess | ValidationFailure
- Results from the last validation check of the session data
Session Validation
ThesessionValidity
object contains the results of validating the checkout session against a ZodSchema. This schema-based validation ensures that all required data is present and formatted correctly.
Understanding sessionValidity
sessionValidity
uses a ZodSchema to validate the structure and content of your checkout session- It helps identify missing or invalid information in customer details, shipping addresses, payment methods, etc.
- This validation is crucial for determining whether a user can proceed to checkout or needs to provide more information
Validating Address Information
A common use case is checking if some information is complete before redirecting the user to the next stepExample
Notes
- Use type parameters with
useCheckoutSession<YourExtensions>()
when you have custom properties in your checkout session