Search...
createCheckout( )
Creates a checkout from a cart.
Description
The createCheckout()
function returns a Promise that resolves to the new checkout's ID when it's created.
If a checkout was already created from the specified cart, that checkout will be updated with any new information from the cart.
Note:
options.channelType
is a required field.
Syntax
function createCheckout(_id: string, options: CreateCheckoutOptions): Promise<CreateCheckoutResponse>
createCheckout Parameters
NAME
TYPE
DESCRIPTION
_id
string
Cart ID.
options
Optional
CreateCheckoutOptions
Checkout creation options.
Returns
Fulfilled - ID of the newly created checkout.
Return Type:
Promise<
CreateCheckoutResponse
>NAME
TYPE
DESCRIPTION
checkoutId
string
The newly created checkout's ID.
Was this helpful?
Create a checkout from a cart
Copy Code
1/**************************************2 * Backend code - my-backend-file.web.js *3 *************************************/45import { Permissions, webMethod } from 'wix-web-module';6import { cart } from 'wix-ecom-backend';78export const myCreateCheckoutFunction = webMethod(Permissions.Anyone, async (cartId, options) => {9 try {10 const checkoutId = await cart.createCheckout(cartId, options);11 console.log('Success! Checkout created, checkoutId:', checkoutId);12 return checkoutId;13 } catch (error) {14 console.error(error);15 // Handle the error16 }17});1819/*************20 * Page code *21 ************/2223import { myCreateCheckoutFunction } from 'backend/my-backend-file.web';2425// Sample cartId:26const cartId = '96a61a4b-6b61-47d1-a039-0213a8230ccd';2728// Sample options object:29const options = {30 // channelType is a required field31 "channelType": "WEB",32 "email": "janedoe@example.com",33 "shippingAddress": {34 "addressLine1": "235 West 23rd Street",35 "addressLine2": "3rd floor",36 "city": "New York",37 "country": "US",38 "postalCode": "10011",39 "streetAddress": {40 "name": "West 23rd Street",41 "number": "235"42 },43 "subdivision": "US-NY"44 }45};4647myCreateCheckoutFunction(cartId, options)48 .then((checkoutId) => {49 console.log('Success! Checkout created, checkoutId:', checkoutId);50 return checkoutId;51 })52 .catch((error) => {53 console.error(error);54 // Handle the error55 });5657/* Promise resolves to:58 *59 * {"checkoutId": "a43420aa-986b-456a-a2f7-7ea5c80e9007"}60 *61 */