Search.../

createOrder( )

Deprecated. This function will continue to work until September 4, 2024, but a newer version is available at wix-ecom-backend.Orders.createOrder().

We recommend you migrate to the new Wix eCommerce APIs as soon as possible.

Description

Migration Instructions

If this function is already in your code, it will continue to work. To stay compatible with future changes, migrate to wix-ecom-backend.Orders.createOrder().

To migrate to the new function:

  1. Add the new import statement:

    import { orders } from 'wix-ecom-backend';
    javascript | Copy Code
  2. Look for any code that uses wixStoresBackend.createOrder(), and replace it with orders.createOrder(). Update your code to work with the new createOrder() response properties.

  3. Test your changes to make sure your code behaves as expected.

Creates a new order.

The createOrder() function returns a Promise that resolves to an Order object when the order has been created.

Note: Do not pass important information from client-side code. Doing so opens a vulnerability that a malicious user can exploit to change information, such as a buyer’s personal details (address, email, etc.) or product price information. To learn more about how to keep your code secure, see Security Considerations When Working with Wix Code.

Syntax

function createOrder(orderInfo: OrderInfo): Promise<Order>

createOrder Parameters

NAME
TYPE
DESCRIPTION
orderInfo
OrderInfo

The information for the order being created.

Returns

Fulfilled - The created order. Rejected - Error message.

Return Type:

Promise<Order>
NAME
TYPE
DESCRIPTION
_id
string

Unique order ID.

_updatedDate
string

Date and time the order was updated.

buyerLanguage
string

The site's displayed language.

cartId
string

Shopping cart ID.

channelInfo
ChannelInfo

Channel information.

enteredBy
EnteredBy

Identity of the order's initiator.

billingInfo
BillingInfo

Billing information.

buyerInfo
BuyerInfo

Buyer information.

buyerNote
string

A note added by the buyer.

_dateCreated
string

Date and time the order was created.

currency
string

Order currency.

fulfillmentStatus
string

The order's current fulfillment status (whether the order received a tracking number or was delivered/picked up). One of:

  • "NOT_FULFILLED": Order is not yet fulfilled.
  • "FULFILLED": Order was fulfilled successfully.
  • "CANCELED": Order was canceled.
  • "PARTIALLY_FULFILLED": Order was partially fulfilled. For example, when only some of the order's items were fulfilled.
archived
boolean

Whether or not the order was archived.

activities
Array<Activities>

Log of updates related to the order.

number
number

Running order number.

paymentStatus
string

Current status of the payment. One of:

  • "NOT_PAID": Payment was not made.
  • "PAID": Order was successfully paid for.
  • "PARTIALLY_REFUNDED": Order was partially refunded.
  • "FULLY_REFUNDED": Order was refunded in full.
shippingInfo
OrderShippingInfo

Shipping information.

lineItems
Array<OrderLineItem>

Order items.

totals
Totals

Order totals.

weightUnit
string

The unit in which the order's weight is measured. Either "KG" or "LB". If not provided, the site's default weight unit is used.

customField
CustomField

Custom field information.

fulfillments
Array<Fulfillment>

Order fulfillment information.

discount
Discount

Discount information.

refunds
Array<Refund>

Refund information.

subscriptionInfo
SubscriptionInfo

Subscription information. Omitted unless the order is a subscription. Learn more about selling product subscriptions.

Related Content:

Was this helpful?

Create a new order

Copy Code
1/**************
2 * Page code *
3 **************/
4
5import { createOrder } from 'backend/orders';
6
7createOrder()
8 .then((order) => {
9 // Order created
10 const newOrderId = order._id;
11 const buyerEmail = order.buyerInfo.email;
12 })
13 .catch((error) => {
14 // Order not created
15 console.error(error);
16 });
17
18/*****************************
19 * Backend code - orders.jsw *
20 *****************************/
21
22import wixStoresBackend from 'wix-stores-backend';
23
24export function createOrder() {
25 return wixStoresBackend.createOrder(fullOrder);
26}
27
28
29const fullOrder = {
30 "buyerLanguage": "en",
31 "cartId": "055e1808-b236-48dc-94d5-45288e06ef9c",
32 "currency": "USD",
33 "weightUnit": "KG",
34 "billingInfo": {
35 "address": {
36 "formatted": "235 W 23rd St New York, NY 10011, USA",
37 "city": "New York",
38 "country": "US",
39 "addressLine": "235 W 23rd St",
40 "postalCode": "10011",
41 "subdivision": "NY"
42 },
43 "lastName": "Doe",
44 "firstName": "John",
45 "email": "john.doe@somedomain.com",
46 "phone": "+15555555555",
47 "company": "My company name",
48 "paymentMethod": "VISA",
49 "paymentGatewayTransactionId": "29A06193U6234935D",
50 "paymentProviderTransactionId": "7c03ca74-eaf5-4541-8678-9b857634fdcb"
51 },
52 "totals": {
53 "subtotal": 5,
54 "total": 5,
55 "shipping": 0
56 },
57 "channelInfo": {
58 "type": "WEB"
59 },
60 "paymentStatus": "PAID",
61 "shippingInfo": {
62 "deliverByDate": "2019-06-23T13:58:47.871Z",
63 "deliveryOption": "Free Shipping",
64 "shippingRegion": "Domestic",
65 "estimatedDeliveryTime": "4:30pm",
66 "shipmentDetails": {
67 "address": {
68 "formatted": "235 W 23rd St, New York, NY 10011, USA",
69 "city": "New York",
70 "country": "US",
71 "addressLine": "235 W 23rd St",
72 "postalCode": "10011",
73 "subdivision": "NY"
74 },
75 "lastName": "Doe",
76 "firstName": "John",
77 "email": "john.doe@somedomain.com",
78 "phone": "5555555555",
79 "company": "company name",
80 "shipmentPriceData": {
81 "price": 5,
82 "taxIncludedInPrice": false
83 }
84 }
85 },
86 "lineItems": [{
87 "customTextFields": [{
88 "title": "Notes for delivery",
89 "value": "Please leave at front door"
90 }],
91 "productId": "3fb6a3c8-988b-8755-04bd-5c59ae0b18ea",
92 "lineItemType": "PHYSICAL",
93 "mediaItem": {
94 "altText": "This is a description of the image",
95 "src": "wix:image://v1/689fa9...ccdc8a.jpg/file.jpg#originWidth=5760&originHeight=3840"
96 },
97 "name": "my product's name",
98 "options": [{
99 "option": "Size",
100 "selection": "Medium"
101 }],
102 "quantity": 1,
103 "sku": "36523641234523",
104 "weight": 1.42,
105 "translatedName": "Nombre traducido",
106 "discount": 0,
107 "tax": 5,
108 "priceData": {
109 "price": 5,
110 "taxIncludedInPrice": true
111 }
112 }],
113 "customField": {
114 "title": "Notes for delivery",
115 "translatedTitle": "Notas de entrega",
116 "value": "Please call when outside"
117 },
118 "discount": {
119 "appliedCoupon": {
120 "code": "47d259d6-7d1e-4ea5-a75c79ca9bb1",
121 "couponId": "d293d777-5aad-4f70-aa91-36c7c5f16740",
122 "name": "Summer sale"
123 }
124 }
125}
126
127/* Example of returned order object
128 *
129 * {
130 * "_id": "d5d43d01-d9a4-4cc2-b257-61184b881447",
131 * "_updatedDate": "2020-05-27T12:20:37.994Z",
132 * "buyerLanguage": "en",
133 * "cartId": "055e1808-b236-48dc-94d5-45288e06ef9c",
134 * "channelInfo": {
135 * "type": "WEB"
136 * },
137 * "enteredBy": {
138 * "id": "f6c2c0f9-4e9f-a58d-a02d-9af2497294d9",
139 * "identityType": "MEMBER"
140 * },
141 * "billingInfo": {
142 * "address": {
143 * "formatted": "My company name\n235 W 23rd St\nNew York, New York 10011\nUnited States\n+15555555555",
144 * "city": "New York",
145 * "country": "USA",
146 * "addressLine": "235 W 23rd St",
147 * "postalCode": "10011",
148 * "subdivision": "NY"
149 * },
150 * "firstName": "John",
151 * "lastName": "Doe",
152 * "email": "john.doe@somedomain.com",
153 * "phone": "+15555555555",
154 * "company": "My company name",
155 * "externalTransactionId": "7c03ca74-eaf5-4541-8678-9b857634fdcb",
156 * "paidDate": "2020-05-27T12:20:37.994Z",
157 * "paymentMethod": "VISA",
158 * "paymentGatewayTransactionId": "29A06193U6234935D",
159 * "paymentProviderTransactionId": "7c03ca74-eaf5-4541-8678-9b857634fdcb"
160 * },
161 * "buyerInfo": {
162 * "id": "f6c2c0f9-4e9f-a58d-a02d-9af2497294d9",
163 * "identityType": "MEMBER",
164 * "firstName": "John",
165 * "lastName": "Doe",
166 * "phone": "+15555555555",
167 * "email": "john.doe@somedomain.com"
168 * },
169 * "_dateCreated": "2020-05-27T12:20:37.966Z",
170 * "currency": "ILS",
171 * "fulfillmentStatus": "NOT_FULFILLED",
172 * "archived": false,
173 * "activities": [
174 * {
175 * "type": "ORDER_PLACED",
176 * "timestamp": "2020-05-27T12:20:37.966Z"
177 * },
178 * {
179 * "type": "ORDER_PAID",
180 * "timestamp": "2020-05-27T12:20:37.994Z"
181 * }
182 * ],
183 * "number": 10019,
184 * "paymentStatus": "PAID",
185 * "shippingInfo": {
186 * "deliveryOption": "Free Shipping",
187 * "estimatedDeliveryTime": "4:30pm",
188 * "shippingRegion": "Domestic",
189 * "shipmentDetails": {
190 * "address": {
191 * "formatted": "company name\n235 W 23rd St\nNew York, New York 10011\nUnited States\n5555555555",
192 * "city": "New York",
193 * "country": "USA",
194 * "addressLine": "235 W 23rd St",
195 * "postalCode": "10011",
196 * "subdivision": "NY"
197 * },
198 * "firstName": "John",
199 * "lastName": "Doe",
200 * "email": "john.doe@somedomain.com",
201 * "phone": "5555555555",
202 * "company": "company name",
203 * "tax": 0,
204 * "discount": 0,
205 * "priceData": null
206 * },
207 * "pickupDetails": null
208 * },
209 * "lineItems": [
210 * {
211 * "index": 1,
212 * "quantity": 1,
213 * "price": 5,
214 * "name": "my product's name",
215 * "translatedName": "Nombre traducido",
216 * "productId": "3fb6a3c8-988b-8755-04bd-5c59ae0b18ea",
217 * "totalPrice": 5,
218 * "lineItemType": "PHYSICAL",
219 * "options": [
220 * {
221 * "option": "Size",
222 * "selection": "Medium"
223 * }
224 * ],
225 * "customTextFields": [
226 * {
227 * "title": "Notes for delivery",
228 * "value": "Please leave at front door"
229 * }
230 * ],
231 * "weight": 1.42,
232 * "sku": "36523641234523",
233 * "discount": 0,
234 * "tax": 5,
235 * "taxIncludedInPrice": true,
236 * "priceData": {
237 * "price": 5,
238 * "totalPrice": 5,
239 * "taxIncludedInPrice": true
240 * },
241 * "mediaItem": {
242 * "altText": "This is a description of the image",
243 * "id": "fac9dc352bf7d54ed0458d64ce41a3ec.jpg",
244 * "src": "wix:image://v1/fac9dc352bf7d54ed0458d64ce41a3ec.jpg/file.jpg#originWidth=1348&originHeight=899",
245 * "type": "IMAGE"
246 * }
247 * }
248 * ],
249 * "totals": {
250 * "discount": 0,
251 * "quantity": 1,
252 * "shipping": 0,
253 * "subtotal": 5,
254 * "tax": 0,
255 * "total": 5,
256 * "weight": 1.42
257 * },
258 * "weightUnit": "KG",
259 * "customField": {
260 * "value": "Please call when outside",
261 * "title": "Notes for delivery",
262 * "translatedTitle": "Notas de entrega"
263 * },
264 * "discount": {
265 * "appliedCoupon": {
266 * "code": "47d259d6-7d1e-4ea5-a75c79ca9bb1",
267 * "couponId": "d293d777-5aad-4f70-aa91-36c7c5f16740",
268 * "name": "Summer sale"
269 * }
270 * }
271 * }
272 *
273 */
Create a new order using the minimum required fields

Copy Code
1/**************
2 * Page code *
3 **************/
4
5import { createOrder } from 'backend/orders';
6
7createOrder()
8 .then((order) => {
9 // Order created
10 const newOrderId = order._id
11 })
12 .catch((error) => {
13 // Order not created
14 console.error(error);
15 });
16
17/*****************************
18 * Backend code - orders.jsw *
19 *****************************/
20
21import wixStoresBackend from 'wix-stores-backend';
22
23export function createOrder() {
24 return wixStoresBackend.createOrder(minimumOrder);
25}
26
27const minimumOrder = {
28 "lineItems": [
29 {
30 "quantity": 1,
31 "name": "my item",
32 "priceData": {
33 "price": 5
34 }
35 }
36 ],
37 "totals": {
38 "subtotal": 5,
39 "total": 5
40 },
41 "channelInfo": {
42 "type": "WEB"
43 },
44 "paymentStatus": "PAID",
45 "shippingInfo": {
46 "shipmentDetails": {
47 "address": {
48 "city": "New York",
49 "country": "US",
50 "addressLine": "235 W 23rd St",
51 "postalCode": "10011",
52 "subdivision": "NY"
53 }
54 }
55 },
56 "billingInfo": {
57 "address": {
58 "city": "New York",
59 "country": "US",
60 "addressLine": "235 W 23rd St",
61 "postalCode": "10011",
62 "subdivision": "NY"
63 }
64 }
65}
66
67/* Example of minimum returned order object
68 *
69 * {
70 * "_id": "d3e84af3-4597-9a18-36c8-1c6f176c0f52",
71 * "_updatedDate": "2020-07-30T08:34:36.088Z",
72 * "buyerLanguage": "en",
73 * "channelInfo": {
74 * "type": "WEB"
75 * },
76 * "billingInfo": {
77 * "address": {
78 * "formatted": "235 W 23rd St\nNew York, New York 10011\nUnited States",
79 * "city": "New York",
80 * "country": "US",
81 * "addressLine": "235 W 23rd St",
82 * "postalCode": "10011",
83 * "subdivision": "NY"
84 * }
85 * },
86 * "_dateCreated": "2020-07-30T08:34:36.061Z",
87 * "currency": "USD",
88 * "fulfillmentStatus": "NOT_FULFILLED",
89 * "archived": false,
90 * "activities": [
91 * {
92 * "type": "ORDER_PLACED",
93 * "timestamp": "2020-07-26T15:49:35.133Z"
94 * }
95 * ],
96 * "number": 10011,
97 * "paymentStatus": "NOT_PAID",
98 * "shippingInfo": {
99 * "deliveryOption": "",
100 * "shipmentDetails": {
101 * "address": {
102 * "formatted": "235 W 23rd St\nNew York, New York 10011\nUnited States",
103 * "city": "New York",
104 * "country": "USA",
105 * "addressLine": "235 W 23rd St",
106 * "postalCode": "10011",
107 * "subdivision": "NY"
108 * },
109 * "tax": 0,
110 * "discount": 0,
111 * "priceData": null
112 * },
113 * // pickupDetails are not included if shipping was selected as the delivery method
114 * "pickupDetails": null
115 * },
116 * "lineItems": [
117 * {
118 * "index": 1,
119 * "quantity": 1,
120 * "name": "my item",
121 * "lineItemType": "CUSTOM_AMOUNT_ITEM",
122 * "options": [],
123 * "customTextFields": [],
124 * "taxIncludedInPrice": false,
125 * "priceData": {
126 * "price": 5,
127 * "totalPrice": 0,
128 * "taxIncludedInPrice": false
129 * },
130 * "mediaItem": null,
131 * "weight": 0,
132 * "discount": 0,
133 * "tax": 0,
134 * }
135 * ],
136 * "totals": {
137 * "discount": 0,
138 * "quantity": 1,
139 * "shipping": 0,
140 * "subtotal": 5,
141 * "tax": 0,
142 * "total": 5,
143 * "weight": 0
144 * },
145 * "weightUnit": "KG",
146 * "customField": {
147 * "title": "Notes for delivery",
148 * "translatedTitle": "Notes for delivery",
149 * "value": "Please call when outside"
150 * },
151 * "fulfillments": [],
152 * "discount": null
153 * }
154 *
155 */