Search...
createCheckoutFromCurrentCart( )
Creates a checkout from the current cart.
Description
The createCheckoutFromCurrentCart()
function returns a Promise that resolves to the new checkout's ID when it's created.
If a checkout was already created from the current cart, that checkout will be updated with any new information from the cart.
Syntax
function createCheckoutFromCurrentCart(options: CreateCheckoutFromCurrentCartOptions): Promise<CreateCheckoutResponse>
createCheckoutFromCurrentCart Parameters
NAME
TYPE
DESCRIPTION
options
Optional
CreateCheckoutFromCurrentCartOptions
Checkout creation options.
Returns
Return Type:
Promise<
CreateCheckoutResponse
>NAME
TYPE
DESCRIPTION
checkoutId
string
The newly created checkout's ID.
Was this helpful?
Create a checkout from the current cart
Copy Code
1/**************************************2 * Backend code - my-backend-file.jsw *3 *************************************/45import { currentCart } from 'wix-ecom-backend';67export async function myCreateCheckoutFromCurrentCartFunction(options) {8 try {9 const checkoutId = await currentCart.createCheckoutFromCurrentCart(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 { myCreateCheckoutFromCurrentCartFunction } from 'backend/my-backend-file';2324// Sample options object:25const options = {26 "channelType": "WEB",27 "email": "janedoe@example.com",28 "shippingAddress": {29 "addressLine1": "235 West 23rd Street",30 "addressLine2": "3rd floor",31 "city": "New York",32 "country": "US",33 "postalCode": "10011",34 "streetAddress": {35 "name": "West 23rd Street",36 "number": "235"37 },38 "subdivision": "US-NY"39 }40};4142myCreateCheckoutFromCurrentCartFunction(options)43 .then((checkoutId) => {44 console.log('Success! Checkout created, checkoutId:', checkoutId);45 return checkoutId;46 })47 .catch((error) => {48 console.error(error);49 // Handle the error50 });5152/* Promise resolves to:53 *54 * {"checkoutId": "a43420aa-986b-456a-a2f7-7ea5c80e9007"}55 *56 */57