> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # Method name: createOrder(_id: string, options: CreateOrderOptions) # Method package: wixEcomBackend # Method menu location: wixEcomBackend --> checkout --> createOrder # Method Link: https://dev.wix.com/docs/velo/apis/wix-ecom-backend/checkout/create-order.md # Method Description: Creates an order from a specified checkout. 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()`](https://www.wix.com/velo/reference/wix-pay-frontend/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](https://www.wix.com/velo/reference/wix-ecom-backend/checkout/getcheckout) 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. # Method Code Examples: *** Note: do not assume any prop names or enum values other than the ones in the example. ## Create an order from a checkout ```javascript /************************************** * Backend code - my-backend-file.jsw * *************************************/ import { checkout } from 'wix-ecom-backend'; export async function myCreateOrderFromCheckoutFunction(checkoutId) { try { const createOrderResponse = await checkout.createOrder(checkoutId); console.log('Success! Created an order from the checkout'); return createOrderResponse; } catch (error) { console.error(error); // Handle the error } } /************* * Page code * ************/ import { myCreateOrderFromCheckoutFunction } from 'backend/my-backend-file'; // Sample checkoutId: const checkoutId = '23a7b29a-3c14-4ef1-9353-f4b714b13217'; myCreateOrderFromCheckoutFunction(checkoutId) .then((createOrderResponse) => { const orderId = createOrderResponse.orderId; const paymentGatewayOrderId = createOrderResponse.paymentGatewayOrderId; console.log('Success! Created an order from the checkout'); return createOrderResponse; }) .catch((error) => { console.error(error); // Handle the error }); /* Promise resolves to: * * { * "orderId": "02843248-495f-45c0-a5d6-e913f647c9f2", * "paymentGatewayOrderId": "f30440f4-413a-4382-bc38-7280b155a5ed" * } * */ ``` ## Create an order from a checkout (export from backend code) ```javascript /************************************** * Backend code - my-backend-file.web.js * *************************************/ import { Permissions, webMethod } from 'wix-web-module'; import { checkout } from 'wix-ecom-backend'; export const myCreateOrderFromCheckoutFunction = webMethod(Permissions.Anyone, async (checkoutId) => { try { const createOrderResponse = await checkout.createOrder(checkoutId); console.log('Success! Created an order from the checkout'); return createOrderResponse; } catch (error) { console.error(error); // Handle the error } }); /************* * Page code * ************/ import { myCreateOrderFromCheckoutFunction } from 'backend/my-backend-file.web'; // Sample checkoutId: const checkoutId = '23a7b29a-3c14-4ef1-9353-f4b714b13217'; myCreateOrderFromCheckoutFunction(checkoutId) .then((createOrderResponse) => { const orderId = createOrderResponse.orderId; const paymentGatewayOrderId = createOrderResponse.paymentGatewayOrderId; console.log('Success! Created an order from the checkout'); return createOrderResponse; }) .catch((error) => { console.error(error); // Handle the error }); /* Promise resolves to: * * { * "orderId": "02843248-495f-45c0-a5d6-e913f647c9f2", * "paymentGatewayOrderId": "f30440f4-413a-4382-bc38-7280b155a5ed" * } * */ ``` ---