> 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

> **Deprecated.** This method is deprecated. Replacement: https://dev.wix.com/docs/api-reference/business-solutions/pricing-plans/plans-v3/create-plan.md Planned removal date: 2025-12-31.

# CreatePlan

# Package: pricingPlans

# Namespace: PlansServiceV2

# Method link: https://dev.wix.com/docs/api-reference/business-solutions/pricing-plans/plans-deprecated/create-plan?apiView=SDK.md

## Permission Scopes:
Manage Pricing Plans: SCOPE.DC-PAIDPLANS.MANAGE-PLANS

## Introduction

Creates a pricing plan. The specified `plan` object must contain a pricing model. A pricing model can be 1 of the following:
- **A subscription**: A subscription with recurring payments and how often the plan occurs. Subscriptions can have free trial days.
- **A plan that doesn't renew**: A single payment for a specific duration that doesn't renew.
- **An unlimited plan**: A single payment for an unlimited amount of time (until canceled).
Pricing plans are available to the Wix user in the Pricing Plans section in a site's dashboard.

---

## REST API

### Schema

```
 Method: createPlan
 Description: Creates a pricing plan. The specified `plan` object must contain a pricing model. A pricing model can be 1 of the following: - **A subscription**: A subscription with recurring payments and how often the plan occurs. Subscriptions can have free trial days. - **A plan that doesn't renew**: A single payment for a specific duration that doesn't renew. - **An unlimited plan**: A single payment for an unlimited amount of time (until canceled). Pricing plans are available to the Wix user in the Pricing Plans section in a site's dashboard.
 URL: https://www.wixapis.com/pricing-plans/v2/plans
 Method: POST
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  plan, plan.name, plan.pricing
 Method parameters: 
   param name: plan | type: Plan | description: Information about the pricing plan. | required: true 
        - name: name | type: string | description: Plan name. | required: true | validation: minLength 1, maxLength 50
        - name: description | type: string | description: Plan description.  | validation: maxLength 450
        - name: perks | type: StringList | description: List of text strings that promote what is included with this plan. For example, "Plenty of parking" or "Free gift on your birthday."  
           - name: values | type: array<string> | description:   | validation: maxItems 500, minLength 1, maxLength 1400
        - name: pricing | type: Pricing | description: Plan price, payment schedule, and expiration. | required: true 
           - ONE-OF: 
              - name: subscription | type: Recurrence | description: Pricing model indicating that the plan has recurring payments. This type of subscription is not a "Wix subscription," which encompasses various types of subscriptions, such as Wix Stores subscriptions, Wix invoice subscriptions, and all pricing plan models.  
                 - name: cycleDuration | type: Duration | description: Number of payment cycles the subscription is valid for. `0` for unlimited plans or for plans that are valid until canceled.  
                    - name: count | type: integer | description: Number of days, months, weeks, or years in a single payment cycle. Currently limited to support only `1`.  | validation: minimum 1, format int32
                    - name: unit | type: PeriodUnit | description: Unit of time for the cycle duration.  
                             - enum:
                             -     UNDEFINED: Not defined.
                             -     DAY: Time unit is a day.
                             -     WEEK: Time unit is a week.
                             -     MONTH: Time unit is a month.
                             -     YEAR: Time unit is a year.
                 - name: cycleCount | type: integer | description: Length of a payment cycle. For example, 1 month to have monthly payments. Multiply `cycleDuration`'s `count` by `cycleCount` to get the subscription duration. Currently, only a value of `1` is supported.  | validation: minimum 0, maximum 2000, format int32
              - name: singlePaymentForDuration | type: Duration | description: Pricing model indicating a single payment per cycle and the length of the cycle. The cycle is the duration of the plan, not a payment cycle.  
              - name: singlePaymentUnlimited | type: boolean | description: Pricing model indicating the plan is paid in a single payment. The plan is valid until canceled.  
           - name: price | type: Money | description: Amount for a single payment. For subscriptions, this is the amount to pay each payment cycle and it is required. For plans that are not recurring plans, it is the single payment amount for the whole subscription.  
              - name: value | type: string | description: Monetary amount. Decimal string with a period as a decimal separator. For example, `'3.99'`. Can't be negative.  | validation: decimalValue {"lt":"1000000000000","gte":"0.000","maxScale":3}
              - name: currency | type: string | description: Currency code. Three-letter currency code in [ISO-4217 alphabetic](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) format. For example, `'USD'`.  | validation: format CURRENCY
           - name: freeTrialDays | type: integer | description: Free trial period for the plan in days. Available only for recurring plans, meaning plans whose pricing model is `subscription`. Set to `0` to remove the free trial.  | validation: minimum 0, maximum 999, format int32
        - name: public | type: boolean | description: Whether the plan is public (visible to site visitors and members).  
        - name: maxPurchasesPerBuyer | type: integer | description: Number of times the same buyer can purchase the plan. Currently limited to support: - Empty value or a value of `0`, meaning no limitation. - Value of `1`, meaning limited to 1 purchase per buyer.  | validation: minimum 0, maximum 1, format int32
        - name: allowFutureStartDate | type: boolean | description: Whether the buyer can start the plan at a later date. Defaults to false.  
        - name: buyerCanCancel | type: boolean | description: Whether the buyer is allowed to cancel their plan. Defaults to false. If false, calling Request Cancellation returns an error.  
        - name: termsAndConditions | type: string | description: Any terms and conditions that apply to the plan. This information is displayed during checkout.  | validation: maxLength 3000
        - name: formId | type: string | description: GUID of the form associated with the plan at checkout.  Learn more about [forms](https://support.wix.com/en/article/wix-forms-an-overview).  | validation: format GUID
 Return type: CreatePlanResponse
  - name: plan | type: Plan | description: Created plan.  
     - name: id | type: string | description: Plan GUID.  | read-only: true | validation: format GUID
     - name: name | type: string | description: Plan name.  | validation: minLength 1, maxLength 50
     - name: description | type: string | description: Plan description.  | validation: maxLength 450
     - name: perks | type: StringList | description: List of text strings that promote what is included with this plan. For example, "Plenty of parking" or "Free gift on your birthday."  
        - name: values | type: array<string> | description:   | validation: maxItems 500, minLength 1, maxLength 1400
     - name: pricing | type: Pricing | description: Plan price, payment schedule, and expiration.  
        - ONE-OF: 
           - name: subscription | type: Recurrence | description: Pricing model indicating that the plan has recurring payments. This type of subscription is not a "Wix subscription," which encompasses various types of subscriptions, such as Wix Stores subscriptions, Wix invoice subscriptions, and all pricing plan models.  
              - name: cycleDuration | type: Duration | description: Number of payment cycles the subscription is valid for. `0` for unlimited plans or for plans that are valid until canceled.  
                 - name: count | type: integer | description: Number of days, months, weeks, or years in a single payment cycle. Currently limited to support only `1`.  | validation: minimum 1, format int32
                 - name: unit | type: PeriodUnit | description: Unit of time for the cycle duration.  
                         - enum:
                         -     UNDEFINED: Not defined.
                         -     DAY: Time unit is a day.
                         -     WEEK: Time unit is a week.
                         -     MONTH: Time unit is a month.
                         -     YEAR: Time unit is a year.
              - name: cycleCount | type: integer | description: Length of a payment cycle. For example, 1 month to have monthly payments. Multiply `cycleDuration`'s `count` by `cycleCount` to get the subscription duration. Currently, only a value of `1` is supported.  | validation: minimum 0, maximum 2000, format int32
           - name: singlePaymentForDuration | type: Duration | description: Pricing model indicating a single payment per cycle and the length of the cycle. The cycle is the duration of the plan, not a payment cycle.  
           - name: singlePaymentUnlimited | type: boolean | description: Pricing model indicating the plan is paid in a single payment. The plan is valid until canceled.  
        - name: price | type: Money | description: Amount for a single payment. For subscriptions, this is the amount to pay each payment cycle and it is required. For plans that are not recurring plans, it is the single payment amount for the whole subscription.  
           - name: value | type: string | description: Monetary amount. Decimal string with a period as a decimal separator. For example, `'3.99'`. Can't be negative.  | validation: decimalValue {"lt":"1000000000000","gte":"0.000","maxScale":3}
           - name: currency | type: string | description: Currency code. Three-letter currency code in [ISO-4217 alphabetic](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) format. For example, `'USD'`.  | validation: format CURRENCY
        - name: freeTrialDays | type: integer | description: Free trial period for the plan in days. Available only for recurring plans, meaning plans whose pricing model is `subscription`. Set to `0` to remove the free trial.  | validation: minimum 0, maximum 999, format int32
     - name: public | type: boolean | description: Whether the plan is public (visible to site visitors and members).  
     - name: archived | type: boolean | description: Whether the plan is archived. Archived plans are not visible and can't be purchased anymore, but existing purchases remain in effect.  | read-only: true 
     - name: primary | type: boolean | description: Whether the plan is marked as primary.  | read-only: true 
     - name: hasOrders | type: boolean | description: Whether the plan has any orders (including pending and unpaid orders).  | read-only: true 
     - name: createdDate | type: string | description: Date plan was created.  | read-only: true | validation: format date-time
     - name: updatedDate | type: string | description: Date plan was last updated.  | read-only: true | validation: format date-time
     - name: slug | type: string | description: URL-friendly version of plan name. Unique across all plans in the same site.  | read-only: true | validation: minLength 1, format URL_SLUG
     - name: maxPurchasesPerBuyer | type: integer | description: Number of times the same buyer can purchase the plan. Currently limited to support: - Empty value or a value of `0`, meaning no limitation. - Value of `1`, meaning limited to 1 purchase per buyer.  | validation: minimum 0, maximum 1, format int32
     - name: allowFutureStartDate | type: boolean | description: Whether the buyer can start the plan at a later date. Defaults to false.  
     - name: buyerCanCancel | type: boolean | description: Whether the buyer is allowed to cancel their plan. Defaults to false. If false, calling Request Cancellation returns an error.  
     - name: termsAndConditions | type: string | description: Any terms and conditions that apply to the plan. This information is displayed during checkout.  | validation: maxLength 3000
     - name: formId | type: string | description: GUID of the form associated with the plan at checkout.  Learn more about [forms](https://support.wix.com/en/article/wix-forms-an-overview).  | validation: format GUID

 Possible Errors:
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: client_data_is_invalid | Description: Client data format is invalid.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: invalid_duration_unit | Description: Duration unit is invalid for this type of plan.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: INVALID_SINGLE_PAYMENT_WITHOUT_DURATION | Description: For single-payment pricing, the plan must be either unlimited or have a set duration.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: SINGLE_PAYMENT_FREE_TRIAL_UNSUPPORTED | Description: Free trials are not supported for single-payment plans.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: SINGLE_PAYMENT_CYCLE_COUNT_INVALID | Description: The number of cycles must be greater than 0.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: SINGLE_PAYMENT_DURATION_TOO_SHORT | Description: The duration must be at least 7 days.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: RECURRING_PLAN_CYCLE_COUNT_INVALID | Description: The number of cycles cannot be a negative number or 1.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: RECURRING_PLAN_CYCLE_DURATION_TOO_SHORT | Description: The cycle length must be at least 7 days.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: RECURRING_PLAN_PAYMENT_PRICE_MISSING | Description: The price must be defined when setting pricing options for recurring payments.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: PERIOD_AMOUNT_OUT_OF_RANGE | Description: The total plan length in specified units is out of range.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: PLAN_FEE_NAME_BLANK | Description: The plan fee name must not be empty.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: PLAN_NAME_BLANK | Description: The plan name must not be empty.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: PRICING_PLANS_NOT_INSTALLED | Description: The user does not have the Wix Pricing Plans app installed on the site.


```

### Examples

### CreatePlan
```curl
~~~cURL
curl -X POST \
  https://www.wixapis.com/pricing-plans/v2/plans
  --data-binary '{
        "plan": {
            "name": "VIP monthly",
            "pricing": {
                "subscription": {
                    "cycleDuration": {
                        "count": 1,
                        "unit": "MONTH"
                    }
                "cycleCount": 3                    
                },
                "price": {
                    "value": "23",
                    "currency": "USD"
                }
            }
        }
  }'
  -H 'Authorization: <AUTH>'
~~~
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.pricingPlans.plans.createPlan(plan)
 Description: Creates a pricing plan. The specified `plan` object must contain a pricing model. A pricing model can be 1 of the following: - **A subscription**: A subscription with recurring payments and how often the plan occurs. Subscriptions can have free trial days. - **A plan that doesn't renew**: A single payment for a specific duration that doesn't renew. - **An unlimited plan**: A single payment for an unlimited amount of time (until canceled). Pricing plans are available to the Wix user in the Pricing Plans section in a site's dashboard.
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  plan, plan.name, plan.pricing, plan.pricing.singlePaymentForDuration.count, plan.pricing.subscription.cycleCount, plan.pricing.subscription.cycleDuration, plan.pricing.subscription.cycleDuration.count
 Method parameters: 
   param name: plan | type: Plan | description: Information about the pricing plan. | required: true 
        - name: name | type: string | description: Plan name. | required: true | validation: minLength 1, maxLength 50
        - name: description | type: string | description: Plan description.  | validation: maxLength 450
        - name: perks | type: StringList | description: List of text strings that promote what is included with this plan. For example, "Plenty of parking" or "Free gift on your birthday."  
           - name: values | type: array<string> | description:   | validation: maxItems 500, minLength 1, maxLength 1400
        - name: pricing | type: Pricing | description: Plan price, payment schedule, and expiration. | required: true 
           - ONE-OF: - required: true
              - name: subscription | type: Recurrence | description: Pricing model indicating that the plan has recurring payments. This type of subscription is not a "Wix subscription," which encompasses various types of subscriptions, such as Wix Stores subscriptions, Wix invoice subscriptions, and all pricing plan models.  
                 - name: cycleDuration | type: Duration | description: Number of payment cycles the subscription is valid for. `0` for unlimited plans or for plans that are valid until canceled.  
                    - name: count | type: integer | description: Number of days, months, weeks, or years in a single payment cycle. Currently limited to support only `1`.  | validation: minimum 1, format int32
                    - name: unit | type: PeriodUnit | description: Unit of time for the cycle duration.  
                             - enum:
                             -     UNDEFINED: Not defined.
                             -     DAY: Time unit is a day.
                             -     WEEK: Time unit is a week.
                             -     MONTH: Time unit is a month.
                             -     YEAR: Time unit is a year.
                 - name: cycleCount | type: integer | description: Length of a payment cycle. For example, 1 month to have monthly payments. Multiply `cycleDuration`'s `count` by `cycleCount` to get the subscription duration. Currently, only a value of `1` is supported.  | validation: minimum 0, maximum 2000, format int32
              - name: singlePaymentForDuration | type: Duration | description: Pricing model indicating a single payment per cycle and the length of the cycle. The cycle is the duration of the plan, not a payment cycle.  
              - name: singlePaymentUnlimited | type: boolean | description: Pricing model indicating the plan is paid in a single payment. The plan is valid until canceled.  
           - name: price | type: Money | description: Amount for a single payment. For subscriptions, this is the amount to pay each payment cycle and it is required. For plans that are not recurring plans, it is the single payment amount for the whole subscription.  
              - name: value | type: string | description: Monetary amount. Decimal string with a period as a decimal separator. For example, `'3.99'`. Can't be negative.  | validation: decimalValue {"lt":"1000000000000","gte":"0.000","maxScale":3}
              - name: currency | type: string | description: Currency code. Three-letter currency code in [ISO-4217 alphabetic](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) format. For example, `'USD'`.  | validation: format CURRENCY
           - name: freeTrialDays | type: integer | description: Free trial period for the plan in days. Available only for recurring plans, meaning plans whose pricing model is `subscription`. Set to `0` to remove the free trial.  | validation: minimum 0, maximum 999, format int32
        - name: public | type: boolean | description: Whether the plan is public (visible to site visitors and members).  
        - name: maxPurchasesPerBuyer | type: integer | description: Number of times the same buyer can purchase the plan. Currently limited to support: - Empty value or a value of `0`, meaning no limitation. - Value of `1`, meaning limited to 1 purchase per buyer.  | validation: minimum 0, maximum 1, format int32
        - name: allowFutureStartDate | type: boolean | description: Whether the buyer can start the plan at a later date. Defaults to false.  
        - name: buyerCanCancel | type: boolean | description: Whether the buyer is allowed to cancel their plan. Defaults to false. If false, calling Request Cancellation returns an error.  
        - name: termsAndConditions | type: string | description: Any terms and conditions that apply to the plan. This information is displayed during checkout.  | validation: maxLength 3000
        - name: formId | type: string | description: GUID of the form associated with the plan at checkout.  Learn more about [forms](https://support.wix.com/en/article/wix-forms-an-overview).  | validation: format GUID
 Return type: PROMISE<Plan>
  - name: _id | type: string | description: Plan GUID.  | read-only: true | validation: format GUID
  - name: name | type: string | description: Plan name.  | validation: minLength 1, maxLength 50
  - name: description | type: string | description: Plan description.  | validation: maxLength 450
  - name: perks | type: StringList | description: List of text strings that promote what is included with this plan. For example, "Plenty of parking" or "Free gift on your birthday."  
     - name: values | type: array<string> | description:   | validation: maxItems 500, minLength 1, maxLength 1400
  - name: pricing | type: Pricing | description: Plan price, payment schedule, and expiration.  
     - ONE-OF: 
        - name: subscription | type: Recurrence | description: Pricing model indicating that the plan has recurring payments. This type of subscription is not a "Wix subscription," which encompasses various types of subscriptions, such as Wix Stores subscriptions, Wix invoice subscriptions, and all pricing plan models.  
           - name: cycleDuration | type: Duration | description: Number of payment cycles the subscription is valid for. `0` for unlimited plans or for plans that are valid until canceled.  
              - name: count | type: integer | description: Number of days, months, weeks, or years in a single payment cycle. Currently limited to support only `1`.  | validation: minimum 1, format int32
              - name: unit | type: PeriodUnit | description: Unit of time for the cycle duration.  
                     - enum:
                     -     UNDEFINED: Not defined.
                     -     DAY: Time unit is a day.
                     -     WEEK: Time unit is a week.
                     -     MONTH: Time unit is a month.
                     -     YEAR: Time unit is a year.
           - name: cycleCount | type: integer | description: Length of a payment cycle. For example, 1 month to have monthly payments. Multiply `cycleDuration`'s `count` by `cycleCount` to get the subscription duration. Currently, only a value of `1` is supported.  | validation: minimum 0, maximum 2000, format int32
        - name: singlePaymentForDuration | type: Duration | description: Pricing model indicating a single payment per cycle and the length of the cycle. The cycle is the duration of the plan, not a payment cycle.  
        - name: singlePaymentUnlimited | type: boolean | description: Pricing model indicating the plan is paid in a single payment. The plan is valid until canceled.  
     - name: price | type: Money | description: Amount for a single payment. For subscriptions, this is the amount to pay each payment cycle and it is required. For plans that are not recurring plans, it is the single payment amount for the whole subscription.  
        - name: value | type: string | description: Monetary amount. Decimal string with a period as a decimal separator. For example, `'3.99'`. Can't be negative.  | validation: decimalValue {"lt":"1000000000000","gte":"0.000","maxScale":3}
        - name: currency | type: string | description: Currency code. Three-letter currency code in [ISO-4217 alphabetic](https://en.wikipedia.org/wiki/ISO_4217#Active_codes) format. For example, `'USD'`.  | validation: format CURRENCY
     - name: freeTrialDays | type: integer | description: Free trial period for the plan in days. Available only for recurring plans, meaning plans whose pricing model is `subscription`. Set to `0` to remove the free trial.  | validation: minimum 0, maximum 999, format int32
  - name: public | type: boolean | description: Whether the plan is public (visible to site visitors and members).  
  - name: archived | type: boolean | description: Whether the plan is archived. Archived plans are not visible and can't be purchased anymore, but existing purchases remain in effect.  | read-only: true 
  - name: primary | type: boolean | description: Whether the plan is marked as primary.  | read-only: true 
  - name: hasOrders | type: boolean | description: Whether the plan has any orders (including pending and unpaid orders).  | read-only: true 
  - name: _createdDate | type: Date | description: Date plan was created.  | read-only: true 
  - name: _updatedDate | type: Date | description: Date plan was last updated.  | read-only: true 
  - name: slug | type: string | description: URL-friendly version of plan name. Unique across all plans in the same site.  | read-only: true | validation: minLength 1, format URL_SLUG
  - name: maxPurchasesPerBuyer | type: integer | description: Number of times the same buyer can purchase the plan. Currently limited to support: - Empty value or a value of `0`, meaning no limitation. - Value of `1`, meaning limited to 1 purchase per buyer.  | validation: minimum 0, maximum 1, format int32
  - name: allowFutureStartDate | type: boolean | description: Whether the buyer can start the plan at a later date. Defaults to false.  
  - name: buyerCanCancel | type: boolean | description: Whether the buyer is allowed to cancel their plan. Defaults to false. If false, calling Request Cancellation returns an error.  
  - name: termsAndConditions | type: string | description: Any terms and conditions that apply to the plan. This information is displayed during checkout.  | validation: maxLength 3000
  - name: formId | type: string | description: GUID of the form associated with the plan at checkout.  Learn more about [forms](https://support.wix.com/en/article/wix-forms-an-overview).  | validation: format GUID

 Possible Errors:
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: client_data_is_invalid | Description: Client data format is invalid.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: invalid_duration_unit | Description: Duration unit is invalid for this type of plan.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: INVALID_SINGLE_PAYMENT_WITHOUT_DURATION | Description: For single-payment pricing, the plan must be either unlimited or have a set duration.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: SINGLE_PAYMENT_FREE_TRIAL_UNSUPPORTED | Description: Free trials are not supported for single-payment plans.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: SINGLE_PAYMENT_CYCLE_COUNT_INVALID | Description: The number of cycles must be greater than 0.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: SINGLE_PAYMENT_DURATION_TOO_SHORT | Description: The duration must be at least 7 days.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: RECURRING_PLAN_CYCLE_COUNT_INVALID | Description: The number of cycles cannot be a negative number or 1.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: RECURRING_PLAN_CYCLE_DURATION_TOO_SHORT | Description: The cycle length must be at least 7 days.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: RECURRING_PLAN_PAYMENT_PRICE_MISSING | Description: The price must be defined when setting pricing options for recurring payments.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: PERIOD_AMOUNT_OUT_OF_RANGE | Description: The total plan length in specified units is out of range.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: PLAN_FEE_NAME_BLANK | Description: The plan fee name must not be empty.
   HTTP Code: 400 | Status Code: INVALID_ARGUMENT | Application Code: PLAN_NAME_BLANK | Description: The plan name must not be empty.
   HTTP Code: 428 | Status Code: FAILED_PRECONDITION | Application Code: PRICING_PLANS_NOT_INSTALLED | Description: The user does not have the Wix Pricing Plans app installed on the site.


```

### Examples

### Duplicate a plan (with $w)
The `populatePlansDropdown` function retrieves all plans and then populates them into the `#plansDropdown`. The `#plansDropdown` and `#clonePlanBtn` are set to `disabled` by default.

```javascript
/*******************************************
 * Backend code - plan-functions.web.js/ts *
 ******************************************/

import { Permissions, webMethod } from '@wix/web-methods';
import { plans } from '@wix/pricing-plans';
import { auth } from '@wix/essentials';

const elevatedListPlans = auth.elevate(plans.listPlans);
const elevatedGetPlan = auth.elevate(plans.getPlan);
const elevatedCreatePlan = auth.elevate(plans.createPlan);

export const listPlans = webMethod(Permissions.Anyone, async () => {
  try {
    const response = await elevatedListPlans();
    const allPlans = response.plans;

    return allPlans;
  } catch (error) {
    console.error(error);
    // Handle the error
  }
});

export const getPlan = webMethod(Permissions.Anyone, async (planId) => {
  try {
    const selectedPlan = await elevatedGetPlan(planId);

    return selectedPlan;
  } catch (error) {
    console.error(error);
    // Handle the error
  }
});

export const createPlan = webMethod(Permissions.Anyone, async (plan) => {
  try {
    const newPlan = await elevatedCreatePlan(plan);

    return newPlan;
  } catch (error) {
    console.error(error);
    // Handle the error
  }
});

/*************
 * Page code *
 *************/

import { listPlans, getPlan, createPlan } from 'backend/plan-functions.web';
$w.onReady(async function () {
  $w('#plansDropdown').disable();
  $w('#clonePlanBtn').disable();
  populatePlansDropdown();

  let selectedPlan;

  $w('#plansDropdown').onChange(async () => {
    const planId = $w('#plansDropdown').value;
    selectedPlan = await getPlan(planId);

    // Set default value for the new plan name
    $w('#planName').value = `${selectedPlan.name}-duplicate`
    $w('#clonePlanBtn').enable();
  });
  
  $w('#clonePlanBtn').onClick(async () => {
    const newPlan = selectedPlan;
    // Use inputs to set the new plan name and price
    newPlan.name = $w('#planName').value;
    newPlan.pricing.price.value = $w('#price').value;

    await createPlan(newPlan);
  });
});

async function populatePlansDropdown() {
  const plans = await listPlans();
  $w('#plansDropdown').options = plans.map((plan) => {
    return {
      label: plan.name,
      value: plan._id
    }
  });
  $w('#plansDropdown').enable();
}

```

### Create a simple plan (with elevated permissions)
```javascript
import { plans } from '@wix/pricing-plans';
import { auth } from '@wix/essentials';

/* Sample plan object:
 * {
 *   name: 'Default',
 *   pricing: {
 *     singlePaymentUnlimited: true
 *   }
 * }
 */

export async function myCreatePlanFunction(plan) {
  try {
    const elevatedCreatePlan = auth.elevate(plans.createPlan);
    const newPlan = await elevatedCreatePlan(plan);

    return newPlan;
  } catch (error) {
    console.error(error);
    // Handle the error
  }
}

/* Promise resolves to:
 * {
 *   "_createdDate": "2024-01-16T10:32:05.818Z",
 *   "_id": "aa0d8e0e-99ad-4c95-ac48-4955e37956c5",
 *   "_updatedDate": "2024-01-16T10:32:05.818Z",
 *   "allowFutureStartDate": false,
 *   "archived": false,
 *   "buyerCanCancel": true,
 *   "description": "",
 *   "hasOrders": false,
 *   "name": "Default",
 *   "perks": {
 *     "values": []
 *   },
 *   "pricing": {
 *     "price": {
 *       "currency": "EUR",
 *       "value": "0"
 *     },
 *     "singlePaymentUnlimited": true
 *   },
 *   "primary": false,
 *   "public": true,
 *   "slug": "default"
 * }
 */
```

### Create a simple plan
```javascript
import { plans } from '@wix/pricing-plans';

/* Sample plan object:
 * {
 *   name: 'Default',
 *   pricing: {
 *     singlePaymentUnlimited: true
 *   }
 * }
 */

export async function myCreatePlanFunction(plan) {
  try {
    const newPlan = await plans.createPlan(plan);

    return newPlan;
  } catch (error) {
    console.error(error);
    // Handle the error
  }
}

/* Promise resolves to:
 * {
 *   "_createdDate": "2024-01-16T10:32:05.818Z",
 *   "_id": "aa0d8e0e-99ad-4c95-ac48-4955e37956c5",
 *   "_updatedDate": "2024-01-16T10:32:05.818Z",
 *   "allowFutureStartDate": false,
 *   "archived": false,
 *   "buyerCanCancel": true,
 *   "description": "",
 *   "hasOrders": false,
 *   "name": "Default",
 *   "perks": {
 *     "values": []
 *   },
 *   "pricing": {
 *     "price": {
 *       "currency": "EUR",
 *       "value": "0"
 *     },
 *     "singlePaymentUnlimited": true
 *   },
 *   "primary": false,
 *   "public": true,
 *   "slug": "default"
 * }
 */
```

### Create a plan with optional fields (with elevated permissions)
```javascript
import { plans } from '@wix/pricing-plans';
import { auth } from '@wix/essentials';

/* Sample plan value:
 * {
 *   allowFutureStartDate: true,
 *   buyerCanCancel: true,
 *   description: 'Fun content for our younger users',
 *   formId: 'ee62cefa-bdc2-4b5d-baab-6faeef83cecb',
 *   maxPurchasesPerBuyer: 1,
 *   name: 'Junior',
 *   perks: {
 *     values: [
 *       'Multiplayer',
 *       'Multiple devices',
 *       'No ads",
 *       'Unlimited access'
 *     ]
 *   },
 *   pricing: {
 *     price: {
 *       currency: 'USD',
 *       value: '10.00"
 *     },
 *     subscription: {
 *       cycleCount: 12,
 *       cycleDuration: {
 *         count: 1,
 *         unit: 'MONTH'
 *       }
 *     }
 *   },
 *   public: true,
 *   termsAndConditions: 'No sharing access with others!'
 * }
 */

const elevatedCreatePlan = auth.elevate(plans.createPlan);

export async function myCreatePlanFunction(plan) {
  try {
    const newPlan = await elevatedCreatePlan(plan);

    const planId = newPlan._id;
    const pricingObject = newPlan.pricing;
    const perks = newPlan.perks;

    return newPlan;
  } catch (error) {
    console.error(error);
    // Handle the error
  }
}

/* Promise resolves to:
 * {
 *   "_createdDate": "2024-01-21T07:06:06.993Z",
 *   "_id": "046371ff-7e5d-4bdb-a01d-a00ff462bed8",
 *   "_updatedDate": "2024-01-21T07:06:06.993Z",
 *   "allowFutureStartDate": true,
 *   "archived": false,
 *   "buyerCanCancel": true,
 *   "description": "Fun content for our younger users",
 *   "formId": "ee62cefa-bdc2-4b5d-baab-6faeef83cecb",
 *   "hasOrders": false,
 *   "maxPurchasesPerBuyer": 1,
 *   "name": "Junior",
 *   "perks": {
 *     "values": [
 *       "Multiplayer",
 *       "Multiple devices",
 *       "No ads",
 *       "Unlimited access"
 *     ]
 *   },
 *   "pricing": {
 *     "price": {
 *       "currency": "USD",
 *       "value": "10.00"
 *     },
 *     "public": true,
 *     "slug": "junior",
 *     "subscription": {
 *       "cycleCount": 12,
 *       "cycleDuration": {
 *         "count": 1,
 *         "unit": "MONTH"
 *       }
 *     },
 *     "termsAndConditions": "No sharing access with others!"
 *   }
 * }
 */
```

### Create a plan with optional fields
```javascript
import { plans } from '@wix/pricing-plans';

/* Sample plan value:
 * {
 *   allowFutureStartDate: true,
 *   buyerCanCancel: true,
 *   description: 'Fun content for our younger users',
 *   formId: 'ee62cefa-bdc2-4b5d-baab-6faeef83cecb',
 *   maxPurchasesPerBuyer: 1,
 *   name: 'Junior',
 *   perks: {
 *     values: [
 *       'Multiplayer',
 *       'Multiple devices',
 *       'No ads",
 *       'Unlimited access'
 *     ]
 *   },
 *   pricing: {
 *     price: {
 *       currency: 'USD',
 *       value: '10.00"
 *     },
 *     subscription: {
 *       cycleCount: 12,
 *       cycleDuration: {
 *         count: 1,
 *         unit: 'MONTH'
 *       }
 *     }
 *   },
 *   public: true,
 *   termsAndConditions: 'No sharing access with others!'
 * }
 */

export async function myCreatePlanFunction(plan) {
  try {
    const newPlan = await plans.createPlan(plan);

    const planId = newPlan._id;
    const pricingObject = newPlan.pricing;
    const perks = newPlan.perks;

    return newPlan;
  } catch (error) {
    console.error(error);
    // Handle the error
  }
}

/* Promise resolves to:
 * {
 *   "_createdDate": "2024-01-21T07:06:06.993Z",
 *   "_id": "046371ff-7e5d-4bdb-a01d-a00ff462bed8",
 *   "_updatedDate": "2024-01-21T07:06:06.993Z",
 *   "allowFutureStartDate": true,
 *   "archived": false,
 *   "buyerCanCancel": true,
 *   "description": "Fun content for our younger users",
 *   "formId": "ee62cefa-bdc2-4b5d-baab-6faeef83cecb",
 *   "hasOrders": false,
 *   "maxPurchasesPerBuyer": 1,
 *   "name": "Junior",
 *   "perks": {
 *     "values": [
 *       "Multiplayer",
 *       "Multiple devices",
 *       "No ads",
 *       "Unlimited access"
 *     ]
 *   },
 *   "pricing": {
 *     "price": {
 *       "currency": "USD",
 *       "value": "10.00"
 *     },
 *     "public": true,
 *     "slug": "junior",
 *     "subscription": {
 *       "cycleCount": 12,
 *       "cycleDuration": {
 *         "count": 1,
 *         "unit": "MONTH"
 *       }
 *     },
 *     "termsAndConditions": "No sharing access with others!"
 *   }
 * }
 */ 
```

### createPlan (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 { plans } from '@wix/pricing-plans';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed

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


async function createPlan(plan) {
  const response = await myWixClient.plans.createPlan(plan);
};
```

---