Search.../

createCheckoutFromCurrentCart( )

Creates a checkout from the current site visitor’s 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.

Note: options.channelType is a required field.

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.web.js *
3 *************************************/
4
5import { Permissions, webMethod } from 'wix-web-module';
6import { currentCart } from 'wix-ecom-backend';
7
8export const myCreateCheckoutFromCurrentCartFunction = webMethod(Permissions.Anyone, async (options) => {
9 try {
10 const checkoutId = await currentCart.createCheckoutFromCurrentCart(options);
11 console.log('Success! Checkout created, checkoutId:', checkoutId);
12 return checkoutId;
13 } catch (error) {
14 console.error(error);
15 // Handle the error
16 }
17});
18
19/*************
20 * Page code *
21 ************/
22
23import { myCreateCheckoutFromCurrentCartFunction } from 'backend/my-backend-file.web';
24
25// Sample options object:
26const options = {
27 // channelType is a required field
28 "channelType": "WEB",
29 "email": "janedoe@example.com",
30 "shippingAddress": {
31 "addressLine1": "235 West 23rd Street",
32 "addressLine2": "3rd floor",
33 "city": "New York",
34 "country": "US",
35 "postalCode": "10011",
36 "streetAddress": {
37 "name": "West 23rd Street",
38 "number": "235"
39 },
40 "subdivision": "US-NY"
41 }
42};
43
44myCreateCheckoutFromCurrentCartFunction(options)
45 .then((checkoutId) => {
46 console.log('Success! Checkout created, checkoutId:', checkoutId);
47 return checkoutId;
48 })
49 .catch((error) => {
50 console.error(error);
51 // Handle the error
52 });
53
54/* Promise resolves to:
55 *
56 * {"checkoutId": "a43420aa-986b-456a-a2f7-7ea5c80e9007"}
57 *
58 */