Search...
createCheckout( )
Creates a checkout from the current site visitor’s 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.
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.jsw *3 *************************************/45import { cart } from 'wix-ecom-backend';67export async function myCreateCheckoutFunction(cartId, options) {8 try {9 const checkoutId = await cart.createCheckout(cartId, options);10 console.log('Success! Checkout created, checkoutId:', checkoutId);11 return checkoutId;12 } catch (error) {13 console.error(error);14 // Handle the error15 }16}1718/*************19 * Page code *20 ************/2122import { myCreateCheckoutFunction } from 'backend/my-backend-file';2324// Sample cartId:25const cartId = '96a61a4b-6b61-47d1-a039-0213a8230ccd';2627// Sample options object:28const options = {29 "channelType": "WEB",30 "email": "janedoe@example.com",31 "shippingAddress": {32 "addressLine1": "235 West 23rd Street",33 "addressLine2": "3rd floor",34 "city": "New York",35 "country": "US",36 "postalCode": "10011",37 "streetAddress": {38 "name": "West 23rd Street",39 "number": "235"40 },41 "subdivision": "US-NY"42 }43};4445myCreateCheckoutFunction(cartId, options)46 .then((checkoutId) => {47 console.log('Success! Checkout created, checkoutId:', checkoutId);48 return checkoutId;49 })50 .catch((error) => {51 console.error(error);52 // Handle the error53 });5455/* Promise resolves to:56 *57 * {"checkoutId": "a43420aa-986b-456a-a2f7-7ea5c80e9007"}58 *59 */60