# Create a plan

> For the complete machine-readable documentation index, see [llms.txt](https://apidocs.chargebee.com/llms.txt).


[Idempotency Supported](/docs/api/v2/pcv-1/idempotency)

This endpoint creates a new plan based on the plan Id and plan name.

## Sample Request

### Default

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/plans \
     -u {site_api_key}:\
     -d id="silver" \
     -d name="Silver" \
     -d invoice_name="sample plan" \
     -d price=5000
```

#### .NET

```dotnet
using ChargeBee.Api;
using ChargeBee.Models;

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Plan.Create()
		.Id("silver")
		.Name("Silver")
		.InvoiceName("sample plan")
		.Price(5000)
		.Request();

Plan plan = result.Plan;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    planAction "github.com/chargebee/chargebee-go/v3/actions/plan"
    "github.com/chargebee/chargebee-go/v3/models/plan"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := planAction.Create(&plan.CreateRequestParams{
        Id : "silver",
        Name : "Silver",
        InvoiceName : "sample plan",
        Price : chargebee.Int64(5000),
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Plan := res.Plan
    }
}
```

#### Go

```go
package main

import (
  "fmt"
  "github.com/chargebee/chargebee-go/v4"
)

func main() {
  config := &chargebee.ClientConfig{
    SiteName: "{site}",
    ApiKey: "{site_api_key}",
  }    
  client := chargebee.NewClient(config)
  req := &chargebee.PlanCreateRequest{
    Id : "silver",
    Name : "Silver",
    InvoiceName : "sample plan",
    Price : chargebee.Int64(5000),
}
  res, err := client.Plan.Create(req)
      if err != nil {
        fmt.Println(err)
    } else {
        Plan := res.Plan
    }
}
```

#### Java

```java
import com.chargebee.*;
import com.chargebee.ListResult;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;
import java.io.IOException;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = Plan.create()
            .id("silver")
            .name("Silver")
            .invoiceName("sample plan")
            .price(5000L)
            .request();

        Plan plan = result.plan();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.plan.Plan;
import com.chargebee.v4.models.plan.params.PlanCreateParams;
import com.chargebee.v4.models.plan.responses.PlanCreateResponse;

public class PlanCreate {

    public static void main(String[] args) {
        ChargebeeClient client = ChargebeeClient.builder()
            .apiKey("{site_api_key}")
            .siteName("{site}")
            .build();

        PlanCreateParams params = PlanCreateParams.builder()
            .id("silver")
            .name("Silver")
            .invoiceName("sample plan")
            .price(5000L)
            .build();

        PlanCreateResponse response = client.plans().create(params);

        Plan plan = response.getPlan();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

const chargebee = new Chargebee({
    site: "{site}",
    apiKey: "{site_api_key}",
});

try {
    const result = await chargebee.plan.create({
        id: "silver",
        name: "Silver",
        invoice_name: "sample plan",
        price: 5000
    });

    console.log(result);
    const plan = result.plan;
} catch (err) {
    console.log(err);
}
```

#### PHP

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use Chargebee\ChargebeeClient;

$chargebee = new ChargebeeClient(options: [
    "site" => "{site}",
    "apiKey" => "{site_api_key}",
]);
$result = $chargebee->plan()->create([
    "id" => "silver",
    "name" => "Silver",
    "invoice_name" => "sample plan",
    "price" => 5000
]);
$plan = $result->plan;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Plan.create(
    cb_client.Plan.CreateParams(
        id="silver",
        name="Silver",
        invoice_name="sample plan",
        price=5000
    )
)
plan = response.plan
```

#### Ruby

```ruby
require 'chargebee'

ChargeBee.configure(:site => "{site}",
  :api_key => "{site_api_key}")

result = ChargeBee::Plan.create({
  :id => "silver",
  :name => "Silver",
  :invoice_name => "sample plan",
  :price => 5000
})

plan = result.plan
```

### creates a plan with addon applicability factor.

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/plans \
     -u {site_api_key}:\
     -d id="gold" \
     -d name="Gold" \
     -d price=500 \
     -d addon_applicability="RESTRICTED" \
     -d "applicable_addons[id][0]"="sub_ssl"
```

#### .NET

```dotnet
using ChargeBee.Api;
using ChargeBee.Models;

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Plan.Create()
		.Id("gold")
		.Name("Gold")
		.Price(500)
		.AddonApplicability(Plan.AddonApplicabilityEnum.Restricted)
		.ApplicableAddonId(0, "sub_ssl")
		.Request();

Plan plan = result.Plan;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    planAction "github.com/chargebee/chargebee-go/v3/actions/plan"
    "github.com/chargebee/chargebee-go/v3/models/plan"
    planEnum "github.com/chargebee/chargebee-go/v3/models/plan/enum"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := planAction.Create(&plan.CreateRequestParams{
        ApplicableAddons : []*plan.CreateApplicableAddonParams{
            {
                Id : "sub_ssl",
            },
        },
        Id : "gold",
        Name : "Gold",
        Price : chargebee.Int64(500),
        AddonApplicability : planEnum.AddonApplicabilityRestricted,
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Plan := res.Plan
    }
}
```

#### Go

```go
package main

import (
  "fmt"
  "github.com/chargebee/chargebee-go/v4"
)

func main() {
  config := &chargebee.ClientConfig{
    SiteName: "{site}",
    ApiKey: "{site_api_key}",
  }    
  client := chargebee.NewClient(config)
  req := &chargebee.PlanCreateRequest{
    ApplicableAddons : []*chargebee.PlanCreateApplicableAddon{
        {
            Id : "sub_ssl",
        },
    },
    Id : "gold",
    Name : "Gold",
    Price : chargebee.Int64(500),
    AddonApplicability : chargebee.PlanAddonApplicabilityRestricted,
}
  res, err := client.Plan.Create(req)
      if err != nil {
        fmt.Println(err)
    } else {
        Plan := res.Plan
    }
}
```

#### Java

```java
import com.chargebee.*;
import com.chargebee.ListResult;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;
import java.io.IOException;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = Plan.create()
            .id("gold")
            .name("Gold")
            .price(500L)
            .addonApplicability(Plan.AddonApplicability.RESTRICTED)
            .applicableAddonId(0, "sub_ssl")
            .request();

        Plan plan = result.plan();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.plan.Plan;
import com.chargebee.v4.models.plan.params.PlanCreateParams;
import com.chargebee.v4.models.plan.responses.PlanCreateResponse;
import java.util.List;

public class PlanCreate {

    public static void main(String[] args) {
        ChargebeeClient client = ChargebeeClient.builder()
            .apiKey("{site_api_key}")
            .siteName("{site}")
            .build();

        PlanCreateParams.ApplicableAddonsParams applicableAddon0 =
            PlanCreateParams.ApplicableAddonsParams.builder()
                .id("sub_ssl")
                .build();

        List<PlanCreateParams.ApplicableAddonsParams> applicableAddonsList =
            List.of(applicableAddon0);

        PlanCreateParams params = PlanCreateParams.builder()
            .id("gold")
            .name("Gold")
            .price(500L)
            .addonApplicability(PlanCreateParams.AddonApplicability.RESTRICTED)
            .applicableAddons(applicableAddonsList)
            .build();

        PlanCreateResponse response = client.plans().create(params);

        Plan plan = response.getPlan();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

const chargebee = new Chargebee({
    site: "{site}",
    apiKey: "{site_api_key}",
});

try {
    const result = await chargebee.plan.create({
        applicable_addons: [
            {
                id: "sub_ssl"
            }
        ],
        id: "gold",
        name: "Gold",
        price: 500,
        addon_applicability: "restricted"
    });

    console.log(result);
    const plan = result.plan;
} catch (err) {
    console.log(err);
}
```

#### PHP

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use Chargebee\ChargebeeClient;

$chargebee = new ChargebeeClient(options: [
    "site" => "{site}",
    "apiKey" => "{site_api_key}",
]);
$result = $chargebee->plan()->create([
    "applicable_addons" => [
        [
            "id" => "sub_ssl"
        ]
    ],
    "id" => "gold",
    "name" => "Gold",
    "price" => 500,
    "addon_applicability" => "restricted"
]);
$plan = $result->plan;
```

#### Python

```python
import chargebee
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Plan.create(
    cb_client.Plan.CreateParams(
        applicable_addons=[
            cb_client.Plan.CreateApplicableAddonParams(
              id="sub_ssl"
            )
        ],
        id="gold",
        name="Gold",
        price=500,
        addon_applicability=chargebee.Plan.AddonApplicability.RESTRICTED
    )
)
plan = response.plan
```

#### Ruby

```ruby
require 'chargebee'

ChargeBee.configure(:site => "{site}",
  :api_key => "{site_api_key}")

result = ChargeBee::Plan.create({
  :id => "gold",
  :name => "Gold",
  :price => 500,
  :addon_applicability => "RESTRICTED",
  :applicable_addons => [
    {
      :id => "sub_ssl"
    }
  ]
})

plan = result.plan
```

### creates a plan with tiered pricing model.

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/plans \
     -u {site_api_key}:\
     -d id="tiered_plan" \
     -d name="Tiered Plan" \
     -d invoice_name="sample Tiered Plan" \
     -d pricing_model="TIERED" \
     -d "tiers[starting_unit][0]"=1 \
     -d "tiers[ending_unit][0]"=10 \
     -d "tiers[price][0]"=100 \
     -d "tiers[starting_unit][1]"=11 \
     -d "tiers[ending_unit][1]"=20 \
     -d "tiers[price][1]"=300 \
     -d "tiers[starting_unit][2]"=21 \
     -d "tiers[price][2]"=500
```

#### .NET

```dotnet
using ChargeBee.Api;
using ChargeBee.Models;
using ChargeBee.Models.Enums;

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Plan.Create()
		.Id("tiered_plan")
		.Name("Tiered Plan")
		.InvoiceName("sample Tiered Plan")
		.PricingModel(PricingModelEnum.Tiered)
		.TierStartingUnit(0, 1)
		.TierEndingUnit(0, 10)
		.TierPrice(0, 100)
		.TierStartingUnit(1, 11)
		.TierEndingUnit(1, 20)
		.TierPrice(1, 300)
		.TierStartingUnit(2, 21)
		.TierPrice(2, 500)
		.Request();

Plan plan = result.Plan;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    planAction "github.com/chargebee/chargebee-go/v3/actions/plan"
    "github.com/chargebee/chargebee-go/v3/models/plan"
    enum "github.com/chargebee/chargebee-go/v3/enum"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := planAction.Create(&plan.CreateRequestParams{
        Tiers : []*plan.CreateTierParams{
            {
                StartingUnit : chargebee.Int32(1),
                EndingUnit : chargebee.Int32(10),
                Price : chargebee.Int64(100),
            },
            {
                StartingUnit : chargebee.Int32(11),
                EndingUnit : chargebee.Int32(20),
                Price : chargebee.Int64(300),
            },
            {
                StartingUnit : chargebee.Int32(21),
                Price : chargebee.Int64(500),
            },
        },
        Id : "tiered_plan",
        Name : "Tiered Plan",
        InvoiceName : "sample Tiered Plan",
        PricingModel : enum.PricingModelTiered,
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Plan := res.Plan
    }
}
```

#### Go

```go
package main

import (
  "fmt"
  "github.com/chargebee/chargebee-go/v4"
)

func main() {
  config := &chargebee.ClientConfig{
    SiteName: "{site}",
    ApiKey: "{site_api_key}",
  }    
  client := chargebee.NewClient(config)
  req := &chargebee.PlanCreateRequest{
    Tiers : []*chargebee.PlanCreateTier{
        {
            StartingUnit : chargebee.Int32(1),
            EndingUnit : chargebee.Int32(10),
            Price : chargebee.Int64(100),
        },
        {
            StartingUnit : chargebee.Int32(11),
            EndingUnit : chargebee.Int32(20),
            Price : chargebee.Int64(300),
        },
        {
            StartingUnit : chargebee.Int32(21),
            Price : chargebee.Int64(500),
        },
    },
    Id : "tiered_plan",
    Name : "Tiered Plan",
    InvoiceName : "sample Tiered Plan",
    PricingModel : chargebee.PricingModelTiered,
}
  res, err := client.Plan.Create(req)
      if err != nil {
        fmt.Println(err)
    } else {
        Plan := res.Plan
    }
}
```

#### Java

```java
import com.chargebee.*;
import com.chargebee.ListResult;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;
import java.io.IOException;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = Plan.create()
            .id("tiered_plan")
            .name("Tiered Plan")
            .invoiceName("sample Tiered Plan")
            .pricingModel(PricingModel.TIERED)
            .tierStartingUnit(0, 1)
            .tierEndingUnit(0, 10)
            .tierPrice(0, 100L)
            .tierStartingUnit(1, 11)
            .tierEndingUnit(1, 20)
            .tierPrice(1, 300L)
            .tierStartingUnit(2, 21)
            .tierPrice(2, 500L)
            .request();

        Plan plan = result.plan();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.plan.Plan;
import com.chargebee.v4.models.plan.params.PlanCreateParams;
import com.chargebee.v4.models.plan.responses.PlanCreateResponse;
import java.util.List;

public class PlanCreate {

    public static void main(String[] args) {
        ChargebeeClient client = ChargebeeClient.builder()
            .apiKey("{site_api_key}")
            .siteName("{site}")
            .build();

        PlanCreateParams.TiersParams tier0 =
            PlanCreateParams.TiersParams.builder()
                .startingUnit(1)
                .endingUnit(10)
                .price(100L)
                .build();

        PlanCreateParams.TiersParams tier1 =
            PlanCreateParams.TiersParams.builder()
                .startingUnit(11)
                .endingUnit(20)
                .price(300L)
                .build();

        PlanCreateParams.TiersParams tier2 =
            PlanCreateParams.TiersParams.builder()
                .startingUnit(21)
                .price(500L)
                .build();

        List<PlanCreateParams.TiersParams> tiersList =
            List.of(tier0, tier1, tier2);

        PlanCreateParams params = PlanCreateParams.builder()
            .id("tiered_plan")
            .name("Tiered Plan")
            .invoiceName("sample Tiered Plan")
            .pricingModel(PlanCreateParams.PricingModel.TIERED)
            .tiers(tiersList)
            .build();

        PlanCreateResponse response = client.plans().create(params);

        Plan plan = response.getPlan();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

const chargebee = new Chargebee({
    site: "{site}",
    apiKey: "{site_api_key}",
});

try {
    const result = await chargebee.plan.create({
        tiers: [
            {
                starting_unit: 1,
                ending_unit: 10,
                price: 100
            },
            {
                starting_unit: 11,
                ending_unit: 20,
                price: 300
            },
            {
                starting_unit: 21,
                price: 500
            }
        ],
        id: "tiered_plan",
        name: "Tiered Plan",
        invoice_name: "sample Tiered Plan",
        pricing_model: "tiered"
    });

    console.log(result);
    const plan = result.plan;
} catch (err) {
    console.log(err);
}
```

#### PHP

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use Chargebee\ChargebeeClient;

$chargebee = new ChargebeeClient(options: [
    "site" => "{site}",
    "apiKey" => "{site_api_key}",
]);
$result = $chargebee->plan()->create([
    "tiers" => [
        [
            "starting_unit" => 1,
            "ending_unit" => 10,
            "price" => 100
        ],
        [
            "starting_unit" => 11,
            "ending_unit" => 20,
            "price" => 300
        ],
        [
            "starting_unit" => 21,
            "price" => 500
        ]
    ],
    "id" => "tiered_plan",
    "name" => "Tiered Plan",
    "invoice_name" => "sample Tiered Plan",
    "pricing_model" => "tiered"
]);
$plan = $result->plan;
```

#### Python

```python
import chargebee
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Plan.create(
    cb_client.Plan.CreateParams(
        tiers=[
            cb_client.Plan.CreateTierParams(
              starting_unit=1,
              ending_unit=10,
              price=100
            ),
            cb_client.Plan.CreateTierParams(
              starting_unit=11,
              ending_unit=20,
              price=300
            ),
            cb_client.Plan.CreateTierParams(
              starting_unit=21,
              price=500
            )
        ],
        id="tiered_plan",
        name="Tiered Plan",
        invoice_name="sample Tiered Plan",
        pricing_model=chargebee.PricingModel.TIERED
    )
)
plan = response.plan
```

#### Ruby

```ruby
require 'chargebee'

ChargeBee.configure(:site => "{site}",
  :api_key => "{site_api_key}")

result = ChargeBee::Plan.create({
  :id => "tiered_plan",
  :name => "Tiered Plan",
  :invoice_name => "sample Tiered Plan",
  :pricing_model => "TIERED",
  :tiers => [
    {
      :starting_unit => 1,
      :ending_unit => 10,
      :price => 100
    },
    {
      :starting_unit => 11,
      :ending_unit => 20,
      :price => 300
    },
    {
      :starting_unit => 21,
      :price => 500
    }
  ]
})

plan = result.plan
```

### creates a plan with trial period.

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/plans \
     -u {site_api_key}:\
     -d id="trial_plan" \
     -d name="Trial Plan" \
     -d invoice_name="sample trial plan" \
     -d trial_period_unit="DAY" \
     -d trial_period=14 \
     -d pricing_model="PER_UNIT" \
     -d price=100
```

#### .NET

```dotnet
using ChargeBee.Api;
using ChargeBee.Models;
using ChargeBee.Models.Enums;

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Plan.Create()
		.Id("trial_plan")
		.Name("Trial Plan")
		.InvoiceName("sample trial plan")
		.TrialPeriodUnit(Plan.TrialPeriodUnitEnum.Day)
		.TrialPeriod(14)
		.PricingModel(PricingModelEnum.PerUnit)
		.Price(100)
		.Request();

Plan plan = result.Plan;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    planAction "github.com/chargebee/chargebee-go/v3/actions/plan"
    "github.com/chargebee/chargebee-go/v3/models/plan"
    planEnum "github.com/chargebee/chargebee-go/v3/models/plan/enum"
    enum "github.com/chargebee/chargebee-go/v3/enum"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := planAction.Create(&plan.CreateRequestParams{
        Id : "trial_plan",
        Name : "Trial Plan",
        InvoiceName : "sample trial plan",
        TrialPeriodUnit : planEnum.TrialPeriodUnitDay,
        TrialPeriod : chargebee.Int32(14),
        PricingModel : enum.PricingModelPerUnit,
        Price : chargebee.Int64(100),
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Plan := res.Plan
    }
}
```

#### Go

```go
package main

import (
  "fmt"
  "github.com/chargebee/chargebee-go/v4"
)

func main() {
  config := &chargebee.ClientConfig{
    SiteName: "{site}",
    ApiKey: "{site_api_key}",
  }    
  client := chargebee.NewClient(config)
  req := &chargebee.PlanCreateRequest{
    Id : "trial_plan",
    Name : "Trial Plan",
    InvoiceName : "sample trial plan",
    TrialPeriodUnit : chargebee.PlanTrialPeriodUnitDay,
    TrialPeriod : chargebee.Int32(14),
    PricingModel : chargebee.PricingModelPerUnit,
    Price : chargebee.Int64(100),
}
  res, err := client.Plan.Create(req)
      if err != nil {
        fmt.Println(err)
    } else {
        Plan := res.Plan
    }
}
```

#### Java

```java
import com.chargebee.*;
import com.chargebee.ListResult;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;
import java.io.IOException;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = Plan.create()
            .id("trial_plan")
            .name("Trial Plan")
            .invoiceName("sample trial plan")
            .trialPeriodUnit(Plan.TrialPeriodUnit.DAY)
            .trialPeriod(14)
            .pricingModel(PricingModel.PER_UNIT)
            .price(100L)
            .request();

        Plan plan = result.plan();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.plan.Plan;
import com.chargebee.v4.models.plan.params.PlanCreateParams;
import com.chargebee.v4.models.plan.responses.PlanCreateResponse;

public class PlanCreate {

    public static void main(String[] args) {
        ChargebeeClient client = ChargebeeClient.builder()
            .apiKey("{site_api_key}")
            .siteName("{site}")
            .build();

        PlanCreateParams params = PlanCreateParams.builder()
            .id("trial_plan")
            .name("Trial Plan")
            .invoiceName("sample trial plan")
            .trialPeriodUnit(PlanCreateParams.TrialPeriodUnit.DAY)
            .trialPeriod(14)
            .pricingModel(PlanCreateParams.PricingModel.PER_UNIT)
            .price(100L)
            .build();

        PlanCreateResponse response = client.plans().create(params);

        Plan plan = response.getPlan();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

const chargebee = new Chargebee({
    site: "{site}",
    apiKey: "{site_api_key}",
});

try {
    const result = await chargebee.plan.create({
        id: "trial_plan",
        name: "Trial Plan",
        invoice_name: "sample trial plan",
        trial_period_unit: "day",
        trial_period: 14,
        pricing_model: "per_unit",
        price: 100
    });

    console.log(result);
    const plan = result.plan;
} catch (err) {
    console.log(err);
}
```

#### PHP

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use Chargebee\ChargebeeClient;

$chargebee = new ChargebeeClient(options: [
    "site" => "{site}",
    "apiKey" => "{site_api_key}",
]);
$result = $chargebee->plan()->create([
    "id" => "trial_plan",
    "name" => "Trial Plan",
    "invoice_name" => "sample trial plan",
    "trial_period_unit" => "day",
    "trial_period" => 14,
    "pricing_model" => "per_unit",
    "price" => 100
]);
$plan = $result->plan;
```

#### Python

```python
import chargebee
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Plan.create(
    cb_client.Plan.CreateParams(
        id="trial_plan",
        name="Trial Plan",
        invoice_name="sample trial plan",
        trial_period_unit=chargebee.Plan.TrialPeriodUnit.DAY,
        trial_period=14,
        pricing_model=chargebee.PricingModel.PER_UNIT,
        price=100
    )
)
plan = response.plan
```

#### Ruby

```ruby
require 'chargebee'

ChargeBee.configure(:site => "{site}",
  :api_key => "{site_api_key}")

result = ChargeBee::Plan.create({
  :id => "trial_plan",
  :name => "Trial Plan",
  :invoice_name => "sample trial plan",
  :trial_period_unit => "DAY",
  :trial_period => 14,
  :pricing_model => "PER_UNIT",
  :price => 100
})

plan = result.plan
```

## Sample Response

```json
{
  "plan": {
    "addon_applicability": "all",
    "charge_model": "flat_fee",
    "currency_code": "USD",
    "enabled_in_hosted_pages": true,
    "enabled_in_portal": true,
    "free_quantity": 0,
    "giftable": false,
    "id": "silver",
    "invoice_name": "sample plan",
    "is_shippable": false,
    "name": "Silver",
    "object": "plan",
    "period": 1,
    "period_unit": "month",
    "price": 5000,
    "pricing_model": "flat_fee",
    "resource_version": 1517505797000,
    "show_description_in_invoices": false,
    "show_description_in_quotes": false,
    "status": "active",
    "taxable": true,
    "updated_at": 1517505797
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/plans

## Input Parameters

- `id` (required, string, max chars=100)
  A unique ID for your system to identify the plan.

- `name` (required, string, max chars=100)
  The display name used in web interface for identifying the plan.

- `invoice_name` (optional, string, max chars=100)
  Display name used in invoice. If it is not configured then name is used in invoice.

- `description` (optional, string, max chars=2000)
  Description about the plan to show in the hosted pages & customer portal. **Note:**
  
  If your input contains characters that are subjected to sanitization (like incomplete HTML tags), the sanitization process might increase the length of your input. If the sanitized input exceeds the limit, your request will be rejected.

- `trial_period` (optional, integer, min=1)
  The free time window for your customer to try your product.

- `trial_period_unit` (optional, enumerated string)
  Time unit for the trial period.
  Possible enum values:
    - `day`
      In days
    - `month`
      In months

- `trial_end_action` (optional, enumerated string)
  Applicable only when [End-of-trial Action](https://www.chargebee.com/docs/1.0/trial_periods_hidden.html#how-to-define-the-end-of-trial-actions-for-subscriptions) has been enabled for the site. Whenever the plan has a trial period, this attribute (parameter) is returned (required) and specifies the operation to be carried out for the subscription once the trial ends. This can be overridden at the [subscription-level](/docs/api/v2/pcv-1/subscriptions/subscription-object#trial_end_action) .
  Possible enum values:
    - `site_default`
      The action [configured for the site](https://www.chargebee.com/docs/1.0/trial_periods_hidden.html#how-to-define-the-end-of-trial-actions-for-subscriptions) at the time when the trial ends, takes effect.
    - `activate_subscription`
      The subscription activates and charges are raised for non-metered items.
    - `cancel_subscription`
      The subscription cancels.

- `period` (optional, integer, default=1, min=1)
  Defines billing frequency. Example: to bill customer every 3 months, provide "3" here.

- `period_unit` (optional, enumerated string, default=month)
  Defines billing frequency in association with billing period.
  Possible enum values:
    - `day`
      Charge based on day(s)
    - `week`
      Charge based on week(s)
    - `month`
      Charge based on month(s)
    - `year`
      Charge based on year(s)

- `setup_cost` (optional, in cents, min=1)
  One-time setup fee charged as part of the first invoice.

- `price` (optional, in cents, min=0)
  The price of the plan. The unit depends on the [type of currency](/docs/api/getting-started) .

- `price_in_decimal` (optional, string, max chars=39)
  The price of the plan when the `pricing_model` is `flat_fee`. When the pricing model is `per_unit` , it is the price per unit quantity of the plan. Not applicable for the other pricing models. The value is in decimal and in major units of the currency. Also, this is only applicable when [multi-decimal pricing](/docs/api/v2/pcv-1/currencies) is enabled. .

- `currency_code` (required if Multicurrency is enabled, string, max chars=3)
  The currency code (ISO 4217 format) of the plan.

- `billing_cycles` (optional, integer, min=1)
  The number of billing cycles the subscription is active. The subscription is moved to non renewing state and then to cancelled state automatically.

- `pricing_model` (optional, enumerated string, default=flat_fee)
  Defines how the recurring charges for the subscription is calculated.
  Possible enum values:
    - `flat_fee`
      A fixed price that is not quantity-based.
    - `per_unit`
      A fixed price per unit quantity.
    - `tiered`
      There are quantity tiers for which per unit prices are set. Quantities are purchased from successive tiers.
    - `volume`
      The per unit price is based on the tier that the total quantity falls in.
    - `stairstep`
      A quantity-based pricing scheme. The item is charged a fixed price based on the tier that the total quantity falls in.

- `free_quantity` (optional, integer, default=0, min=0)
  Free quantity the subscriptions of this plan will have. Only the quantity more than this will be charged for the subscription.

- `free_quantity_in_decimal` (optional, string, max chars=33)
  The quantity of the plan that is available free-of-charge, represented in decimal. When a subscription is created for this plan or when the plan of a subscription is changed to this one, only the quantity above this number is charged for. Applicable for quantity-based plans and only when [multi-decimal pricing](/docs/api/v2/pcv-1/currencies) is enabled. .

- `addon_applicability` (optional, enumerated string, default=all)
  Indicates if all or only some addons are applicable with the plan.
  Possible enum values:
    - `all`
      All addons are applicable with this plan.
    - `restricted`
      Only addons marked as 'applicable\_addons' are applicable with the plan.

- `redirect_url` (optional, string, max chars=500)
  The url to redirect on successful checkout. Eg: https://yoursite.com/success.html?plan=basic.

- `enabled_in_hosted_pages` (optional, boolean, default=true)
  If true, allow checkout through plan specific hosted page URL for this plan.

- `enabled_in_portal` (optional, boolean, default=true)
  If enabled, customers can switch to this plan using the 'Change Subscription' option in the customer portal.

- `taxable` (optional, boolean, default=true)
  Specifies whether taxes apply to this plan. This value is set and returned even if [Taxes](https://www.chargebee.com/docs/tax.html) have been disabled in Chargebee. However, the value is effective only while Taxes are enabled.

- `tax_profile_id` (optional, string, max chars=50)
  Tax profile of the plan.

- `tax_code` (optional, string, max chars=50)
  The Avalara tax codes to which items are mapped to should be provided here. Applicable only if you use Chargebee's [AvaTax for Sales integration](https://www.chargebee.com/docs/avalara.html) .

- `hsn_code` (optional, string, max chars=50)
  The [HSN code](https://cbic-gst.gov.in/gst-goods-services-rates.html) to which the item is mapped for calculating the customer's tax in India. Applicable only when both of the following conditions are true:
  
  -   [**India**](https://www.chargebee.com/docs/indian-gst.html#configuring-indian-gst) has been enabled as a **Tax Region**. (An error is returned when this condition is not true.)
  -   The [**AvaTax for Sales** integration](https://www.chargebee.com/docs/avalara.html) has been enabled in Chargebee. .

- `taxjar_product_code` (optional, string, max chars=50)
  The TaxJar product codes to which items are mapped to should be provided here. Applicable only if you use Chargebee's [TaxJar integration](https://www.chargebee.com/docs/taxjar.html) .

- `avalara_sale_type` (optional, enumerated string)
  Indicates the type of sale carried out. This is applicable only if you use [Chargebee's AvaTax for Communications](https://www.chargebee.com/docs/avatax-for-communication.html) integration.
  Possible enum values:
    - `wholesale`
      Transaction is a sale to another company that will resell your product or service to another consumer
    - `retail`
      Transaction is a sale to an end user
    - `consumed`
      Transaction is for an item that is consumed directly
    - `vendor_use`
      Transaction is for an item that is subject to vendor use tax

- `avalara_transaction_type` (optional, integer)
  Indicates the type of product to be taxed. Values for this field can be taken from Avalara. This is applicable only if you use [Chargebee's AvaTax for Communications](https://www.chargebee.com/docs/avatax-for-communication.html) integration.

- `avalara_service_type` (optional, integer)
  Indicates the type of service for the product to be taxed. Values for this field can be taken from Avalara. This is applicable only if you use [Chargebee's AvaTax for Communications](https://www.chargebee.com/docs/avatax-for-communication.html) integration.

- `sku` (optional, string, max chars=100)
  The field is used as Product name/code in your third party accounting application. Chargebee will use it as an alternate name in your accounting application.

- `accounting_code` (optional, string, max chars=100)
  This field is to capture the Account code setup in your Accounting system for integration purposes only.

- `accounting_category1` (optional, string, max chars=100)
  Used exclusively with the following [accounting integrations](https://www.chargebee.com/docs/1.0/finance-integration-index.html )
  
  -   [**Xero:**](https://www.chargebee.com/docs/1.0/xero.html ) If you've categorized your products in Xero, provide the category name and option. Use the format: `:` . For example:`Location: Singapore.`
  -   [**QuickBooks:**](https://www.chargebee.com/docs/1.0/quickbooks.html ) If you've categorized your product sales in QuickBooks according to Classes, provide the class name here. Use the following format: `::...`
  -   [**NetSuite:**](https://www.chargebee.com/docs/1.0/netsuite.html ) If you've categorized your products in NetSuite under Classes, provide the class name here. Use the following format: `: : ....` For example: `Services : Plan.`
  -   [**Intacct:**](https://www.chargebee.com/docs/1.0/intacct.html ) If you've classified your products in Intacct under Locations, provide the name of the Location here.

- `accounting_category2` (optional, string, max chars=100)
  Used exclusively with the following [accounting integrations](https://www.chargebee.com/docs/1.0/finance-integration-index.html )
  
  -   [**Xero:**](https://www.chargebee.com/docs/1.0/xero.html ) If you've categorized your products in Xero, then provide the second category name and option here. Use the format: `: ....` For example, `Region: South`
  -   [**QuickBooks:**](https://www.chargebee.com/docs/1.0/quickbooks.html ) If you've categorized your product sales in QuickBooks according to Location, provide the Location name here. Use the following format: `::....` For example: `Location: North America: Canada`
  -   [**NetSuite:**](https://www.chargebee.com/docs/1.0/netsuite.html ) If you've categorized your products in NetSuite under Locations, provide the location name here. Use the following format `: : ....` For example: `NA:US:CA`
  -   [**Intacct:**](https://www.chargebee.com/docs/1.0/intacct.html ) If you've classified your products in Intacct under Dimensions, provide the value of the Dimension here.

- `accounting_category3` (optional, string, max chars=100)
  Used exclusively with the following [accounting integrations](https://www.chargebee.com/docs/1.0/finance-integration-index.html )
  
  -   [**NetSuite:**](https://www.chargebee.com/docs/1.0/netsuite.html ) If you've categorized your products in NetSuite under Departments, pass the department name here. Use the following format: `: : ....` For example: `Production: Assembly.`
  -   [**Intacct:**](https://www.chargebee.com/docs/1.0/intacct.html ) If you've classified your products in Intacct under multiple Dimensions, provide the value of the second Dimension here. .

- `accounting_category4` (optional, string, max chars=100)
  Used exclusively with the following [accounting integrations](https://www.chargebee.com/docs/1.0/finance-integration-index.html )
  
  -   [**NetSuite:**](https://www.chargebee.com/docs/1.0/netsuite.html ) Provide the "Revenue Recognition Rule Id" for the product from NetSuite.
  -   [**Intacct:**](https://www.chargebee.com/docs/1.0/intacct.html ) If you have configured "Revenue Recognition Templates" for products in Intacct, provide the template ID for the product. .

- `is_shippable` (optional, boolean, default=false)
  If enabled, charges for this plan/addon will be added to orders.

- `shipping_frequency_period` (optional, integer, min=1)
  Defines the shipping frequency. Example: to bill customer every 2 weeks, provide "2" here.

- `shipping_frequency_period_unit` (optional, enumerated string)
  Defines the shipping frequency in association with shipping period.
  Possible enum values:
    - `year`
      Ship based on year(s)
    - `month`
      Ship based on month(s)
    - `week`
      Ship based on week(s)
    - `day`
      Ship based on day(s)

- `invoice_notes` (optional, string, max chars=2000)
  A customer-facing note added to all invoices associated with this API resource. This note becomes one among [all the notes](/docs/api/invoices/invoice-object#notes) displayed on the invoice PDF.

- `meta_data` (optional, jsonobject)
  A collection of key-value pairs that provides extra information about the plan.
  
  **Note:** There's a character limit of 65,535.
  
  [Learn more](/docs/api/v2/pcv-1/advanced-features) .

- `show_description_in_invoices` (optional, boolean, default=false)
  Whether the `[plan.description](/docs/api/v2/pcv-1/plans/plan-object)` should be shown on [invoice PDFs](/docs/api/invoices/retrieve-invoice-as-pdf). If this Boolean is changed, only invoices generated (or [regenerated](https://www.chargebee.com/docs/billing/2.0/invoices-credit-notes-and-quotes/invoice-operations#actions-for-payment-due-not-paid-invoices) )after the change are affected; past invoices are not.

- `show_description_in_quotes` (optional, boolean, default=false)
  Whether the [plan description](/docs/api/v2/pcv-1/plans/plan-object) should be shown on [quote PDFs](/docs/api/quotes/retrieve-quote-as-pdf). If this Boolean is changed, only quotes created after the change are affected; past quotes are not.

- `giftable` (optional, boolean, default=false)
  Specifies if the plan should be gifted or not.

- `status` (optional, enumerated string, default=active)
  The plan state.
  Possible enum values:
    - `active`
      New subscriptions can be created with the plan.
    - `archived`
      No new subscriptions allowed for the plan. Existing subscriptions on this plan will remain as-is and can be migrated to another active plan if required.

- `claim_url` (optional, string, max chars=500)
  The url to redirect on successful claim. Eg: https://yoursite.com/claim\_success.html?plan=basic.

- `tiers` (optional, array)
  Parameters for tiers
  - `starting_unit` (optional, integer)
    The lower limit of a range of units for the tier
  - `ending_unit` (optional, integer)
    The upper limit of a range of units for the tier
  - `price` (optional, in cents)
    The per-unit price for the tier when the `pricing_model` is `tiered` or `volume` ; the total cost for the item price when the `pricing_model` is `stairstep`. The value is in the [minor unit of the currency](/docs/api/v2/pcv-1/currencies) .
  - `starting_unit_in_decimal` (optional, string, max chars=33)
    The decimal representation of the lowest value of quantity in this tier. This is zero for the lowest tier. For all other tiers, it is the same as `ending_unit_in_decimal` of the next lower tier. Returned only when the `line_items.pricing_model` is `tiered` , `volume` or `stairstep` and [multi-decimal pricing](/docs/api/currencies) is enabled.
  - `ending_unit_in_decimal` (optional, string, max chars=33)
    The decimal representation of the highest value of quantity in this tier. This attribute is not applicable for the highest tier. For all other tiers, it must be equal to the `starting_unit_in_decimal` of the next higher tier. Applicable only when the `pricing_model` is `tiered` , `volume` or `stairstep` and [multi-decimal pricing](/docs/api/v2/pcv-1/currencies) is enabled.
  - `price_in_decimal` (optional, string, max chars=39)
    The decimal representation of the per-unit price for the tier when the `pricing_model` is `tiered` or `volume`. When the `pricing_model` is `stairstep` , it is the decimal representation of the total price for `line_item`. The value is in major units of the currency. Returned when the `line_item` is quantity-based and [multi-decimal pricing](/docs/api/currencies) is enabled.

- `tax_providers_fields` (optional, array)
  Parameters for tax\_providers\_fields
  - `provider_name` (required, string, max chars=50)
    Name of the tax provider currently supported.
  - `field_id` (required, string, max chars=50)
    Field id of the attribute which tax vendor has provided while getting onboarded with us.
  - `field_value` (required, string, max chars=50)
    The value of the corresponding tax field.

- `applicable_addons` (optional, array)
  Parameters for applicable\_addons
  - `id` (optional, string, max chars=100)
    Identifier of the addon appplicable to the plan.

- `event_based_addons` (optional, array)
  Parameters for event\_based\_addons
  - `id` (optional, string, max chars=100)
    Identifier of the addon. Multiple addons can be passed.
  - `quantity` (optional, integer)
    Quantity of the addon. Applicable for addons with `pricing_model` other than `flat_fee` .
  - `quantity_in_decimal` (optional, string, max chars=33)
    The decimal representation of the quantity of the item purchased. Can be provided for quantity-based item prices and only when [multi-decimal pricing](/docs/api/getting-started) is enabled.
  - `on_event` (optional, enumerated string)
    Event on which the addon will be charged
    Possible enum values:
      - `subscription_creation`
        Addon will be charged on subscription creation.
      - `subscription_trial_start`
        Addon will be charged when the trial period starts.
      - `plan_activation`
        Addon will be charged on plan activation.
      - `subscription_activation`
        Addon will be charged on subscription activation.
      - `contract_termination`
        Addon will be charged on contract termination.
  - `charge_once` (optional, boolean)
    If enabled, the addon will be charged only at the first occurrence of the event. Applicable only for non-recurring add-ons.

- `attached_addons` (optional, array)
  Parameters for attached\_addons
  - `id` (optional, string, max chars=100)
    Identifier of the addon attached with the plan. Only recurring addons can be attached with the plan.
  - `quantity` (optional, integer)
    Quantity of the addon. Applicable for addons with `pricing_model` other than `flat_fee` .
  - `quantity_in_decimal` (optional, string, max chars=33)
    The default quantity of the addon to be attached when the quantity is not specified while [creating](/docs/api/v2/pcv-1/subscriptions/create-a-subscription) / [updating](/docs/api/v2/pcv-1/subscriptions/update-a-subscription) the subscription. The value is in decimal. Can be provided for quantity-based addons and only when [multi-decimal pricing](/docs/api/v2/pcv-1/currencies) is enabled.
  - `billing_cycles` (optional, integer)
    The number of billing cycles this addon will be attached to the plan.
  - `type` (optional, enumerated string)
    Specifies attachment type of the addon to the plan
    Possible enum values:
      - `recommended`
        Addon will be charged with this plan unless specifically removed.
      - `mandatory`
        Addon will be always charged with this plan.

## Returns

- `plan` (Plan object)
  Resource object representing plan
