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 *************************************/
4
5import { currentCart } from 'wix-ecom-backend';
6
7export 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 error
15 }
16}
17
18/*************
19 * Page code *
20 ************/
21
22import { myCreateCheckoutFromCurrentCartFunction } from 'backend/my-backend-file';
23
24// 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};
41
42myCreateCheckoutFromCurrentCartFunction(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 error
50 });
51
52/* Promise resolves to:
53 *
54 * {"checkoutId": "a43420aa-986b-456a-a2f7-7ea5c80e9007"}
55 *
56 */
57