> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> 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`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# PlaceOrder

# Package: purchaseFlow

# Namespace: CartService

# Method link: https://dev.wix.com/docs/api-reference/business-solutions/e-commerce/purchase-flow/cart-v2/place-order.md

## Permission Scopes:
Write Carts V2 (PII): SCOPE.ECOM.WRITE-CARTS-V2_LIMITED

## Introduction

Completes checkout and creates an order.
This endpoint may charge the customer.

Read more about the [eCommerce Orders API](https://dev.wix.com/api/rest/wix-ecommerce/orders-api/introduction).

---

## REST API

### Schema

```
 Method: placeOrder
 Description: Completes checkout and creates an order. This endpoint may charge the customer.  Read more about the [eCommerce Orders API](https://dev.wix.com/api/rest/wix-ecommerce/orders-api/introduction).
 URL: https://www.wixapis.com/ecom/v2/carts/{cartId}/place-order
 Method: POST
 Method parameters:
   param name: delayCapture | type: delayCapture | description: Whether to authorize the payment and delay capture.  
   param name: priceVerificationToken | type: priceVerificationToken | description: Price verification token from `CalculateCart` response. Used to verify that prices shown to the customer haven't changed before checkout completes.  | validation: maxLength 3000
   param name: savePaymentMethod | type: savePaymentMethod | description: Whether to save the payment method on the order.  
 Return type: PlaceOrderResponse
  - name: orderId | type: string | description: Order GUID.  | validation: format GUID
  - name: paymentGatewayOrderId | type: string | description: Cashier payment gateway order GUID when money was charged. Omitted when no charge occurs (for example, a zero-total cart, a fully discounted order, or when another payment method such as a gift card covers the total).  | validation: maxLength 50
  - name: completed | type: boolean | description: Whether an order was created from this cart and the payment completed successfully.  

 Possible Errors:
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: INVALID_PRICE_VERIFICATION_TOKEN | Description: The `priceVerificationToken` is invalid.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: RECAPTCHA_VERIFICATION_FAILED | Description: The request includes a `paymentToken`, and the `recaptchaToken` is missing, invalid, or didn't pass verification.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: INVALID_CART | Description: The cart is invalid for placing an order.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: UNAVAILABLE_PAYMENT_METHOD | Description: The selected payment method isn't available.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: PAYMENT_ATTEMPT_EXPIRED | Description: The payment attempt expired.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: DEMO_ORDER_REQUIRED | Description: The cart's `demo` field is `false`, but test mode now applies to this cart. To place a demo order, call [Refresh Cart](https://dev.wix.com/docs/api-reference/business-solutions/e-commerce/purchase-flow/cart-v2/refresh-cart.md) to update the `demo` field, and then call [Place Order](https://dev.wix.com/docs/api-reference/business-solutions/e-commerce/purchase-flow/cart-v2/place-order.md) again.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: DEMO_ORDER_NOT_ALLOWED | Description: The cart's `demo` field is `true`, but test mode no longer applies to this cart. To place a regular order, call [Refresh Cart](https://dev.wix.com/docs/api-reference/business-solutions/e-commerce/purchase-flow/cart-v2/refresh-cart.md) to update the `demo` field, and then call [Place Order](https://dev.wix.com/docs/api-reference/business-solutions/e-commerce/purchase-flow/cart-v2/place-order.md) again.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: PLACE_ORDER_NOT_ALLOWED_FOR_DEMO_CART | Description: Placing an order isn't allowed for a demo cart.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: MEMBERS_ONLY_ITEM | Description: The cart contains a members-only item that the buyer can't purchase.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: EMPTY_PAYMENT_TOKEN | Description: The `paymentToken` is empty.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: PAYMENT_ALREADY_IN_PROGRESS | Description: A payment is already in progress for this cart.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: GIFT_CARD_REDEEM_ERROR | Description: The gift card couldn't be redeemed.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: INVALID_PAYMENT_STATUS | Description: The payment status is invalid for completing the order.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: INVALID_MEMBERSHIP | Description: The membership is invalid.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: MISSING_DELIVERY_METHOD | Description: The delivery method is missing.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: MISSING_DELIVERY_ADDRESS | Description: The delivery address is missing.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: DELIVERY_METHOD_NOT_APPLIED_TO_ALL_LINE_ITEMS | Description: The delivery method doesn't apply to all line items.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: DELIVERY_METHOD_NO_LONGER_AVAILABLE | Description: The delivery method is no longer available.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: UNCONFIRMED_SAVE_PAYMENT_METHOD | Description: Saving the payment method wasn't confirmed.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: SHIPPABLE_LINE_ITEM_CONTAINS_FREE_TRIAL_SUBSCRIPTION | Description: A shippable line item includes a free-trial subscription.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: SUBSCRIPTION_WITH_INVALID_FREQUENCY | Description: The subscription frequency is invalid.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: CANNOT_PAY_FOR_SUBSCRIPTION_WITH_GIFT_CARD | Description: A gift card can't be used to pay for a subscription.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: CANNOT_REDEEM_COUPON_WHEN_PURCHASING_GIFT_CARD | Description: A coupon can't be redeemed when purchasing a gift card.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: CANNOT_PAY_FOR_GIFT_CARD_WITH_GIFT_CARD | Description: A gift card can't be used to pay for a gift card purchase.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: CALCULATION_ERROR | Description: An error occurred while calculating the cart.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: VIOLATIONS_WITH_ERROR_SEVERITY | Description: Business validation returned violations with error severity.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: INVALID_THIRD_PARTY_CHECKOUT_TOKEN | Description: The third-party checkout token is invalid.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: CART_PRICES_OUT_OF_SYNC | Description: Cart prices are out of sync with the latest calculation.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: LINE_ITEMS_OUT_OF_STOCK | Description: One or more line items are out of stock.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: EMPTY_CART | Description: The cart is empty.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: SITE_NOT_ACCEPTING_PAYMENTS | Description: The site isn't accepting payments.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: CART_ALREADY_ORDERED | Description: Cart was already placed as an order.


```

### Examples

### Place Order
Places an order from the cart.

```curl
curl -X POST \
'https://www.wixapis.com/ecom/v2/carts/ca727402-f531-4bcf-ab09-db70ea0bd008/place-order' \
-H 'Authorization: <AUTH>' \
-H 'Content-Type: application/json' \
-d '{
  "priceVerificationToken": "JWS.eyJraWQiOiJyVmxqX19LcSIs..."
}'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.ecom.cartV2.placeOrder(cartId, options)
 Description: Completes checkout and creates an order. This endpoint may charge the customer.  Read more about the [eCommerce Orders API](https://dev.wix.com/api/rest/wix-ecommerce/orders-api/introduction).
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  cartId
 Method parameters: 
   param name: cartId | type: string | description: Cart GUID. | required: true | validation: format GUID
   param name: options | type: PlaceOrderOptions  none  
        - name: priceVerificationToken | type: string | description: Price verification token from `CalculateCart` response. Used to verify that prices shown to the customer haven't changed before checkout completes.  | validation: maxLength 3000
        - name: savePaymentMethod | type: boolean | description: Whether to save the payment method on the order.  
        - name: delayCapture | type: boolean | description: Whether to authorize the payment and delay capture.  
 Return type: PROMISE<PlaceOrderResponse>
  - name: orderId | type: string | description: Order GUID.  | validation: format GUID
  - name: paymentGatewayOrderId | type: string | description: Cashier payment gateway order GUID when money was charged. Omitted when no charge occurs (for example, a zero-total cart, a fully discounted order, or when another payment method such as a gift card covers the total).  | validation: maxLength 50
  - name: completed | type: boolean | description: Whether an order was created from this cart and the payment completed successfully.  

 Possible Errors:
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: INVALID_PRICE_VERIFICATION_TOKEN | Description: The `priceVerificationToken` is invalid.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: RECAPTCHA_VERIFICATION_FAILED | Description: The request includes a `paymentToken`, and the `recaptchaToken` is missing, invalid, or didn't pass verification.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: INVALID_CART | Description: The cart is invalid for placing an order.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: UNAVAILABLE_PAYMENT_METHOD | Description: The selected payment method isn't available.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: PAYMENT_ATTEMPT_EXPIRED | Description: The payment attempt expired.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: DEMO_ORDER_REQUIRED | Description: The cart's `demo` field is `false`, but test mode now applies to this cart. To place a demo order, call [Refresh Cart](https://dev.wix.com/docs/api-reference/business-solutions/e-commerce/purchase-flow/cart-v2/refresh-cart.md) to update the `demo` field, and then call [Place Order](https://dev.wix.com/docs/api-reference/business-solutions/e-commerce/purchase-flow/cart-v2/place-order.md) again.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: DEMO_ORDER_NOT_ALLOWED | Description: The cart's `demo` field is `true`, but test mode no longer applies to this cart. To place a regular order, call [Refresh Cart](https://dev.wix.com/docs/api-reference/business-solutions/e-commerce/purchase-flow/cart-v2/refresh-cart.md) to update the `demo` field, and then call [Place Order](https://dev.wix.com/docs/api-reference/business-solutions/e-commerce/purchase-flow/cart-v2/place-order.md) again.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: PLACE_ORDER_NOT_ALLOWED_FOR_DEMO_CART | Description: Placing an order isn't allowed for a demo cart.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: MEMBERS_ONLY_ITEM | Description: The cart contains a members-only item that the buyer can't purchase.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: EMPTY_PAYMENT_TOKEN | Description: The `paymentToken` is empty.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: PAYMENT_ALREADY_IN_PROGRESS | Description: A payment is already in progress for this cart.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: GIFT_CARD_REDEEM_ERROR | Description: The gift card couldn't be redeemed.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: INVALID_PAYMENT_STATUS | Description: The payment status is invalid for completing the order.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: INVALID_MEMBERSHIP | Description: The membership is invalid.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: MISSING_DELIVERY_METHOD | Description: The delivery method is missing.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: MISSING_DELIVERY_ADDRESS | Description: The delivery address is missing.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: DELIVERY_METHOD_NOT_APPLIED_TO_ALL_LINE_ITEMS | Description: The delivery method doesn't apply to all line items.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: DELIVERY_METHOD_NO_LONGER_AVAILABLE | Description: The delivery method is no longer available.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: UNCONFIRMED_SAVE_PAYMENT_METHOD | Description: Saving the payment method wasn't confirmed.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: SHIPPABLE_LINE_ITEM_CONTAINS_FREE_TRIAL_SUBSCRIPTION | Description: A shippable line item includes a free-trial subscription.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: SUBSCRIPTION_WITH_INVALID_FREQUENCY | Description: The subscription frequency is invalid.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: CANNOT_PAY_FOR_SUBSCRIPTION_WITH_GIFT_CARD | Description: A gift card can't be used to pay for a subscription.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: CANNOT_REDEEM_COUPON_WHEN_PURCHASING_GIFT_CARD | Description: A coupon can't be redeemed when purchasing a gift card.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: CANNOT_PAY_FOR_GIFT_CARD_WITH_GIFT_CARD | Description: A gift card can't be used to pay for a gift card purchase.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: CALCULATION_ERROR | Description: An error occurred while calculating the cart.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: VIOLATIONS_WITH_ERROR_SEVERITY | Description: Business validation returned violations with error severity.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: INVALID_THIRD_PARTY_CHECKOUT_TOKEN | Description: The third-party checkout token is invalid.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: CART_PRICES_OUT_OF_SYNC | Description: Cart prices are out of sync with the latest calculation.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: LINE_ITEMS_OUT_OF_STOCK | Description: One or more line items are out of stock.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: EMPTY_CART | Description: The cart is empty.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: SITE_NOT_ACCEPTING_PAYMENTS | Description: The site isn't accepting payments.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: CART_ALREADY_ORDERED | Description: Cart was already placed as an order.


```

### Examples

### Place an order from a cart
```javascript
import { cartV2 } from "@wix/ecom";

async function placeOrder() {
  const response = await cartV2.placeOrder(
    "ca727402-f531-4bcf-ab09-db70ea0bd008",
    {
      priceVerificationToken: "JWS.eyJraWQiOiJyVmxqX19LcSIs...",
    },
  );
}

/* Promise resolves to:
 * {
 *   "orderId": "cd695bbc-b41f-4b8e-9cdc-ce61074c9010",
 *   "paymentGatewayOrderId": "4eafea95-9c66-4ca2-8538-99c161254e6f",
 *   "completed": false
 * }
 */

```

### placeOrder (self-managed)
Self-managed SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md).

```javascript
import { createClient } from '@wix/sdk';
import { cartV2 } from '@wix/ecom';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed

const myWixClient = createClient ({
  modules: { cartV2 },
  // Include the auth strategy and host as relevant
});


async function placeOrder(cartId,options) {
  const response = await myWixClient.cartV2.placeOrder(cartId,options);
};
```

---