Search.../

createOrder( )

Developer Preview

Creates an order from a specified checkout.

Description

The createOrder() function returns a Promise that resolves to the new order's ID and paymentGatewayOrderID when the order is created. Pass the paymentGatewayOrderId as the paymentId param to the startPayment() function to allow a customer to pay for their order.

Note: The following requirements must be met for an order to be created from a checkout.

  • A checkout cannot have calculation errors. Pass the checkout._id to Get Checkout and take a look at the calculationErrors field.
  • A checkout must have at least 1 line item.
  • All of the line Items have an availability.status of "AVAILABLE" or "PARTIALLY_AVAILABLE".
  • If there is a payment to be made, meaning that priceSummary.total is greater than 0, the billingInfo.address field must be provided.
  • When a checkout has line items to be shipped, the shippingInfo.shippingDestination.address and shippingInfo.selectedCarrierServiceOption fields must be provided.
  • When a checkout has line items for pickup, the shippingInfo.selectedCarrierServiceOption.logistics.pickupDetails field must be provided.

Syntax

function createOrder(_id: string): Promise<CreateOrderResponse>

createOrder Parameters

NAME
TYPE
DESCRIPTION
_id
string

Checkout ID.

Returns

Return Type:

Promise<
CreateOrderResponse
>
NAME
TYPE
DESCRIPTION
orderId
string

ID of the newly created order.

paymentGatewayOrderId
string

Payment gateway order ID.

For online orders, pass this value as the paymentId parameter to the Wix Pay startPayment() function so your customer can pay for the order.

This field will be returned if money needs to be charged. In some cases, money cannot be charged:

  • When the total price (the priceSummary.total.amount field in the checkout/order objects) is 0. For example, in the case of a free item or an item with a 100% discount.
  • If the total price is not 0, but the payment is covered by alternative payment methods, such as a gift card.
subscriptionId
string

ID of newly created subscription. Learn more about your site's Subscriptions.

Was this helpful?

Create an order from a checkout

Copy Code
1/**************************************
2 * Backend code - my-backend-file.jsw *
3 *************************************/
4
5import { checkout } from 'wix-ecom-backend';
6
7export async function myCreateOrderFromCheckoutFunction(checkoutId) {
8 try {
9 const createOrderResponse = await checkout.createOrder(checkoutId);
10 console.log('Success! Created an order from the checkout');
11 return createOrderResponse;
12 } catch (error) {
13 console.error(error);
14 // Handle the error
15 }
16}
17
18/*************
19 * Page code *
20 ************/
21
22import { myCreateOrderFromCheckoutFunction } from 'backend/my-backend-file';
23
24// Sample checkoutId:
25const checkoutId = '23a7b29a-3c14-4ef1-9353-f4b714b13217';
26
27myCreateOrderFromCheckoutFunction(checkoutId)
28 .then((createOrderResponse) => {
29 const orderId = createOrderResponse.orderId;
30 const paymentGatewayOrderId = createOrderResponse.paymentGatewayOrderId;
31
32 console.log('Success! Created an order from the checkout');
33 return createOrderResponse;
34 })
35 .catch((error) => {
36 console.error(error);
37 // Handle the error
38 });
39
40/* Promise resolves to:
41 *
42 * {
43 * "orderId": "02843248-495f-45c0-a5d6-e913f647c9f2",
44 * "paymentGatewayOrderId": "f30440f4-413a-4382-bc38-7280b155a5ed"
45 * }
46 *
47 */
Create an order from a checkout (export from backend code)

Copy Code
1/**************************************
2 * Backend code - my-backend-file.web.js *
3 *************************************/
4
5import { Permissions, webMethod } from 'wix-web-module';
6import { checkout } from 'wix-ecom-backend';
7
8export const myCreateOrderFromCheckoutFunction = webMethod(Permissions.Anyone, async (checkoutId) => {
9 try {
10 const createOrderResponse = await checkout.createOrder(checkoutId);
11 console.log('Success! Created an order from the checkout');
12 return createOrderResponse;
13 } catch (error) {
14 console.error(error);
15 // Handle the error
16 }
17});
18
19/*************
20 * Page code *
21 ************/
22
23import { myCreateOrderFromCheckoutFunction } from 'backend/my-backend-file.web';
24
25// Sample checkoutId:
26const checkoutId = '23a7b29a-3c14-4ef1-9353-f4b714b13217';
27
28myCreateOrderFromCheckoutFunction(checkoutId)
29 .then((createOrderResponse) => {
30 const orderId = createOrderResponse.orderId;
31 const paymentGatewayOrderId = createOrderResponse.paymentGatewayOrderId;
32
33 console.log('Success! Created an order from the checkout');
34 return createOrderResponse;
35 })
36 .catch((error) => {
37 console.error(error);
38 // Handle the error
39 });
40
41/* Promise resolves to:
42 *
43 * {
44 * "orderId": "02843248-495f-45c0-a5d6-e913f647c9f2",
45 * "paymentGatewayOrderId": "f30440f4-413a-4382-bc38-7280b155a5ed"
46 * }
47 *
48 */