# Create a purchase

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


[Idempotency Supported](/docs/api/idempotency)

**Deprecated.** The Purchase API is deprecated. It still works and existing integrations are unaffected, but it's no longer recommended for new integrations. Support for purchasing multiple plans in a single subscription is planned for the [Subscriptions API](/docs/api/subscriptions).

Creates a `purchase` resource. A purchase can contain one or more of the following:

-   subscriptions (a `[subscription](/docs/api/subscriptions)` resource consists of item prices such that at least one of the item prices belongs to an `[item](/docs/api/items)` of `type` `plan`.)
-   group of one-time charges (aka [charge item prices](/docs/api/item_prices))

When you call this API, the invoices for the subscription(s) and one-time charge(s) are created immediately and not left [unbilled](/docs/api/subscriptions/create-subscription-for-items#invoice_immediately) .

**Note**

Providing `shipping_addresses[]` is required when the [Orders feature](https://www.chargebee.com/docs/2.0/orders.html#configuration_step-1-configure-site-wide-settings) has been enabled.

### Specifying `purchase_item` groups[](#specifying-purchaseitem-groups)

When creating a purchase, you must specify the _group_ or `index` to which each item price belongs. You can do this by setting the `purchase_items[index]` for each item price. Item prices with the same `purchase_items[index]` belong to the same group. The grouping of item prices allows you to specify the `discounts[]` applicable for each group and indicate which item prices should be added to any subscriptions you want to create. Groups can be one of two types:

-   Subscription groups
-   One-time charge groups

The following subsections describe the types of groups in detail.

**Note**

You can specify up to 10 groups,

-   with a recommended subscription group of 5. To increase this limit to a maximum of 8, contact eap@chargebee.com.
-   with a maximum of 10 one-time charge groups by default.

The total limit for group items for a single purchase is 60.

#### Subscription groups[](#subscription-groups)

To create a subscription, specify a _subscription group_. A subscription [group](/docs/api/purchases) is a group of item prices that contains exactly one item price of `type` `plan`. To create multiple subscriptions, provide multiple subscription groups.

**Note**

A subscription group can have up to 20 non-plan item prices. To increase this limit to a maximum of 60, contact eap@chargebee.com.

#### Custom Fields[](#custom-fields)

Purchase API supports custom fields of Subscriptions, use the following format to specify custom fields in Purchase API: **`subscription_info[custom_field]`**.

#### One-time charge groups[](#one-time-charge-groups)

A one-time charge [group](/docs/api/purchases) is a group of charge item prices (i.e. item prices belonging to items of `type` `charge`). Charge item prices can be added to subscription groups as well. The charges within and across each one-time group must be unique.

**Note**

-   A one-time charge group can have up to 20 item prices. To increase this limit to a maximum of 60, contact eap@chargebee.com.
-   A charge item price can only be added to a single one-time charge group. However, it can be part of multiple [subscription groups](/docs/api/purchases).

### Applying discounts[](#applying-discounts)

Discounts, both [manual discounts](/docs/api/discounts) and [coupons](/docs/api/coupons), can be applied to groups by specifying the `discounts[]` array. The following table describes the method of application based on whether `discounts[index][i]` is provided:

**`discounts[index][i]` is provided**

**`discounts[index][i]` is not provided**

**Coupons**

-   The coupon is applied exclusively to the invoice for group `i`.
-   The coupon is applied exclusively to the invoice created immediately upon invoking this API.
-   If group `i` is a [subscription group](/docs/api/purchases), then the coupon is applied to invoices for subscription renewals based on coupon attributes such as `duration_type` and `max_redemptions`.

-   The coupon is applied to all the invoices immediately generated upon invoking this API.
-   The coupon is not applied to subsequent invoices, such as those generated upon subscription renewal.

**Manual discounts**

-   The manual discount is applied exclusively to the invoice for group `i`.
-   The manual discount is applied exclusively to the invoice created immediately upon invoking this API.
-   The manual discount is not applied to subsequent invoices, such as those generated upon subscription renewal.

-   The manual discount is applied to all the invoices immediately generated upon invoking this API.
-   The manual discount is not applied to subsequent invoices, such as those generated upon subscription renewal.

## Sample Request

### Default

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/purchases \
     -u {site_api_key}:\
     -d customer_id="__test__XpbG9acT88TIfH3T" \
     -d "purchase_items[index][0]"=1 \
     -d "purchase_items[item_price_id][0]"="basic-USD" \
     -d "purchase_items[quantity][0]"=10 \
     -d "purchase_items[index][1]"=2 \
     -d "purchase_items[item_price_id][1]"="basic-USD-yearly" \
     -d "purchase_items[quantity][1]"=5
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Purchase.Create()
		.CustomerId("__test__XpbG9acT88TIfH3T")
		.PurchaseItemIndex(0, 1)
		.PurchaseItemItemPriceId(0, "basic-USD")
		.PurchaseItemQuantity(0, 10)
		.PurchaseItemIndex(1, 2)
		.PurchaseItemItemPriceId(1, "basic-USD-yearly")
		.PurchaseItemQuantity(1, 5)
		.Request();

Purchase purchase = result.Purchase;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    purchaseAction "github.com/chargebee/chargebee-go/v3/actions/purchase"
    "github.com/chargebee/chargebee-go/v3/models/purchase"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := purchaseAction.Create(&purchase.CreateRequestParams{
        PurchaseItems : []*purchase.CreatePurchaseItemParams{
            {
                Index : chargebee.Int32(1),
                ItemPriceId : "basic-USD",
                Quantity : chargebee.Int32(10),
            },
            {
                Index : chargebee.Int32(2),
                ItemPriceId : "basic-USD-yearly",
                Quantity : chargebee.Int32(5),
            },
        },
        CustomerId : "__test__XpbG9acT88TIfH3T",
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Purchase := res.Purchase
    }
}
```

#### 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.PurchaseCreateRequest{
    PurchaseItems : []*chargebee.PurchaseCreatePurchaseItem{
        {
            Index : chargebee.Int32(1),
            ItemPriceId : "basic-USD",
            Quantity : chargebee.Int32(10),
        },
        {
            Index : chargebee.Int32(2),
            ItemPriceId : "basic-USD-yearly",
            Quantity : chargebee.Int32(5),
        },
    },
    CustomerId : "__test__XpbG9acT88TIfH3T",
}
  res, err := client.Purchase.Create(req)
      if err != nil {
        fmt.Println(err)
    } else {
        Purchase := res.Purchase
    }
}
```

#### 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 = Purchase.create()
            .customerId("__test__XpbG9acT88TIfH3T")
            .purchaseItemIndex(0, 1)
            .purchaseItemItemPriceId(0, "basic-USD")
            .purchaseItemQuantity(0, 10)
            .purchaseItemIndex(1, 2)
            .purchaseItemItemPriceId(1, "basic-USD-yearly")
            .purchaseItemQuantity(1, 5)
            .request();

        Purchase purchase = result.purchase();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.purchase.Purchase;
import com.chargebee.v4.models.purchase.params.PurchaseCreateParams;
import com.chargebee.v4.models.purchase.responses.PurchaseCreateResponse;
import java.util.List;

public class PurchaseCreate {

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

        PurchaseCreateParams.PurchaseItemsParams purchaseItem0 =
            PurchaseCreateParams.PurchaseItemsParams.builder()
                .index(1)
                .itemPriceId("basic-USD")
                .quantity(10)
                .build();

        PurchaseCreateParams.PurchaseItemsParams purchaseItem1 =
            PurchaseCreateParams.PurchaseItemsParams.builder()
                .index(2)
                .itemPriceId("basic-USD-yearly")
                .quantity(5)
                .build();

        List<PurchaseCreateParams.PurchaseItemsParams> purchaseItemsList =
            List.of(purchaseItem0, purchaseItem1);

        PurchaseCreateParams params = PurchaseCreateParams.builder()
            .customerId("__test__XpbG9acT88TIfH3T")
            .purchaseItems(purchaseItemsList)
            .build();

        PurchaseCreateResponse response = client.purchases().create(params);

        Purchase purchase = response.getPurchase();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.purchase.create({
        purchase_items: [
            {
                index: 1,
                item_price_id: "basic-USD",
                quantity: 10
            },
            {
                index: 2,
                item_price_id: "basic-USD-yearly",
                quantity: 5
            }
        ],
        customer_id: "__test__XpbG9acT88TIfH3T"
    });

    console.log(result);
    const purchase = result.purchase;
} 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->purchase()->create([
    "purchase_items" => [
        [
            "index" => 1,
            "item_price_id" => "basic-USD",
            "quantity" => 10
        ],
        [
            "index" => 2,
            "item_price_id" => "basic-USD-yearly",
            "quantity" => 5
        ]
    ],
    "customer_id" => "__test__XpbG9acT88TIfH3T"
]);
$purchase = $result->purchase;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Purchase.create(
    cb_client.Purchase.CreateParams(
        purchase_items=[
            cb_client.Purchase.CreatePurchaseItemParams(
              index=1,
              item_price_id="basic-USD",
              quantity=10
            ),
            cb_client.Purchase.CreatePurchaseItemParams(
              index=2,
              item_price_id="basic-USD-yearly",
              quantity=5
            )
        ],
        customer_id="__test__XpbG9acT88TIfH3T"
    )
)
purchase = response.purchase
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Purchase.create({
  :customer_id => "__test__XpbG9acT88TIfH3T",
  :purchase_items => [
    {
      :index => 1,
      :item_price_id => "basic-USD",
      :quantity => 10
    },
    {
      :index => 2,
      :item_price_id => "basic-USD-yearly",
      :quantity => 5
    }
  ]
})

purchase = result.purchase
```

### Purchase With Plan And Addons

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/purchases \
     -u {site_api_key}:\
     -d customer_id="__test__XpbG9acT88TJ8h43" \
     -d "purchase_items[index][0]"=1 \
     -d "purchase_items[item_price_id][0]"="basic-USD" \
     -d "purchase_items[quantity][0]"=5 \
     -d "purchase_items[index][1]"=1 \
     -d "purchase_items[item_price_id][1]"="day-pass-USD" \
     -d "purchase_items[index][2]"=2 \
     -d "purchase_items[item_price_id][2]"="basic-USD-yearly" \
     -d "purchase_items[quantity][2]"=5 \
     -d "purchase_items[index][3]"=2 \
     -d "purchase_items[item_price_id][3]"="day-pass-USD"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Purchase.Create()
		.CustomerId("__test__XpbG9acT88TJ8h43")
		.PurchaseItemIndex(0, 1)
		.PurchaseItemItemPriceId(0, "basic-USD")
		.PurchaseItemQuantity(0, 5)
		.PurchaseItemIndex(1, 1)
		.PurchaseItemItemPriceId(1, "day-pass-USD")
		.PurchaseItemIndex(2, 2)
		.PurchaseItemItemPriceId(2, "basic-USD-yearly")
		.PurchaseItemQuantity(2, 5)
		.PurchaseItemIndex(3, 2)
		.PurchaseItemItemPriceId(3, "day-pass-USD")
		.Request();

Purchase purchase = result.Purchase;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    purchaseAction "github.com/chargebee/chargebee-go/v3/actions/purchase"
    "github.com/chargebee/chargebee-go/v3/models/purchase"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := purchaseAction.Create(&purchase.CreateRequestParams{
        PurchaseItems : []*purchase.CreatePurchaseItemParams{
            {
                Index : chargebee.Int32(1),
                ItemPriceId : "basic-USD",
                Quantity : chargebee.Int32(5),
            },
            {
                Index : chargebee.Int32(1),
                ItemPriceId : "day-pass-USD",
            },
            {
                Index : chargebee.Int32(2),
                ItemPriceId : "basic-USD-yearly",
                Quantity : chargebee.Int32(5),
            },
            {
                Index : chargebee.Int32(2),
                ItemPriceId : "day-pass-USD",
            },
        },
        CustomerId : "__test__XpbG9acT88TJ8h43",
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Purchase := res.Purchase
    }
}
```

#### 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.PurchaseCreateRequest{
    PurchaseItems : []*chargebee.PurchaseCreatePurchaseItem{
        {
            Index : chargebee.Int32(1),
            ItemPriceId : "basic-USD",
            Quantity : chargebee.Int32(5),
        },
        {
            Index : chargebee.Int32(1),
            ItemPriceId : "day-pass-USD",
        },
        {
            Index : chargebee.Int32(2),
            ItemPriceId : "basic-USD-yearly",
            Quantity : chargebee.Int32(5),
        },
        {
            Index : chargebee.Int32(2),
            ItemPriceId : "day-pass-USD",
        },
    },
    CustomerId : "__test__XpbG9acT88TJ8h43",
}
  res, err := client.Purchase.Create(req)
      if err != nil {
        fmt.Println(err)
    } else {
        Purchase := res.Purchase
    }
}
```

#### 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 = Purchase.create()
            .customerId("__test__XpbG9acT88TJ8h43")
            .purchaseItemIndex(0, 1)
            .purchaseItemItemPriceId(0, "basic-USD")
            .purchaseItemQuantity(0, 5)
            .purchaseItemIndex(1, 1)
            .purchaseItemItemPriceId(1, "day-pass-USD")
            .purchaseItemIndex(2, 2)
            .purchaseItemItemPriceId(2, "basic-USD-yearly")
            .purchaseItemQuantity(2, 5)
            .purchaseItemIndex(3, 2)
            .purchaseItemItemPriceId(3, "day-pass-USD")
            .request();

        Purchase purchase = result.purchase();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.purchase.Purchase;
import com.chargebee.v4.models.purchase.params.PurchaseCreateParams;
import com.chargebee.v4.models.purchase.responses.PurchaseCreateResponse;
import java.util.List;

public class PurchaseCreate {

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

        PurchaseCreateParams.PurchaseItemsParams purchaseItem0 =
            PurchaseCreateParams.PurchaseItemsParams.builder()
                .index(1)
                .itemPriceId("basic-USD")
                .quantity(5)
                .build();

        PurchaseCreateParams.PurchaseItemsParams purchaseItem1 =
            PurchaseCreateParams.PurchaseItemsParams.builder()
                .index(1)
                .itemPriceId("day-pass-USD")
                .build();

        PurchaseCreateParams.PurchaseItemsParams purchaseItem2 =
            PurchaseCreateParams.PurchaseItemsParams.builder()
                .index(2)
                .itemPriceId("basic-USD-yearly")
                .quantity(5)
                .build();

        PurchaseCreateParams.PurchaseItemsParams purchaseItem3 =
            PurchaseCreateParams.PurchaseItemsParams.builder()
                .index(2)
                .itemPriceId("day-pass-USD")
                .build();

        List<PurchaseCreateParams.PurchaseItemsParams> purchaseItemsList =
            List.of(purchaseItem0, purchaseItem1, purchaseItem2, purchaseItem3);

        PurchaseCreateParams params = PurchaseCreateParams.builder()
            .customerId("__test__XpbG9acT88TJ8h43")
            .purchaseItems(purchaseItemsList)
            .build();

        PurchaseCreateResponse response = client.purchases().create(params);

        Purchase purchase = response.getPurchase();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.purchase.create({
        purchase_items: [
            {
                index: 1,
                item_price_id: "basic-USD",
                quantity: 5
            },
            {
                index: 1,
                item_price_id: "day-pass-USD"
            },
            {
                index: 2,
                item_price_id: "basic-USD-yearly",
                quantity: 5
            },
            {
                index: 2,
                item_price_id: "day-pass-USD"
            }
        ],
        customer_id: "__test__XpbG9acT88TJ8h43"
    });

    console.log(result);
    const purchase = result.purchase;
} 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->purchase()->create([
    "purchase_items" => [
        [
            "index" => 1,
            "item_price_id" => "basic-USD",
            "quantity" => 5
        ],
        [
            "index" => 1,
            "item_price_id" => "day-pass-USD"
        ],
        [
            "index" => 2,
            "item_price_id" => "basic-USD-yearly",
            "quantity" => 5
        ],
        [
            "index" => 2,
            "item_price_id" => "day-pass-USD"
        ]
    ],
    "customer_id" => "__test__XpbG9acT88TJ8h43"
]);
$purchase = $result->purchase;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Purchase.create(
    cb_client.Purchase.CreateParams(
        purchase_items=[
            cb_client.Purchase.CreatePurchaseItemParams(
              index=1,
              item_price_id="basic-USD",
              quantity=5
            ),
            cb_client.Purchase.CreatePurchaseItemParams(
              index=1,
              item_price_id="day-pass-USD"
            ),
            cb_client.Purchase.CreatePurchaseItemParams(
              index=2,
              item_price_id="basic-USD-yearly",
              quantity=5
            ),
            cb_client.Purchase.CreatePurchaseItemParams(
              index=2,
              item_price_id="day-pass-USD"
            )
        ],
        customer_id="__test__XpbG9acT88TJ8h43"
    )
)
purchase = response.purchase
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Purchase.create({
  :customer_id => "__test__XpbG9acT88TJ8h43",
  :purchase_items => [
    {
      :index => 1,
      :item_price_id => "basic-USD",
      :quantity => 5
    },
    {
      :index => 1,
      :item_price_id => "day-pass-USD"
    },
    {
      :index => 2,
      :item_price_id => "basic-USD-yearly",
      :quantity => 5
    },
    {
      :index => 2,
      :item_price_id => "day-pass-USD"
    }
  ]
})

purchase = result.purchase
```

### Purchase With Subscription Ids

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/purchases \
     -u {site_api_key}:\
     -d customer_id="__test__XpbG9acT88TIuk3m" \
     -d "purchase_items[index][0]"=1 \
     -d "purchase_items[item_price_id][0]"="basic-USD" \
     -d "purchase_items[quantity][0]"=10 \
     -d "purchase_items[index][1]"=2 \
     -d "purchase_items[item_price_id][1]"="basic-USD-yearly" \
     -d "purchase_items[quantity][1]"=5 \
     -d "subscription_info[index][0]"=1 \
     -d "subscription_info[subscription_id][0]"="sub-1" \
     -d "subscription_info[index][1]"=2 \
     -d "subscription_info[subscription_id][1]"="sub-2"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Purchase.Create()
		.CustomerId("__test__XpbG9acT88TIuk3m")
		.PurchaseItemIndex(0, 1)
		.PurchaseItemItemPriceId(0, "basic-USD")
		.PurchaseItemQuantity(0, 10)
		.PurchaseItemIndex(1, 2)
		.PurchaseItemItemPriceId(1, "basic-USD-yearly")
		.PurchaseItemQuantity(1, 5)
		.SubscriptionInfoIndex(0, 1)
		.SubscriptionInfoSubscriptionId(0, "sub-1")
		.SubscriptionInfoIndex(1, 2)
		.SubscriptionInfoSubscriptionId(1, "sub-2")
		.Request();

Purchase purchase = result.Purchase;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    purchaseAction "github.com/chargebee/chargebee-go/v3/actions/purchase"
    "github.com/chargebee/chargebee-go/v3/models/purchase"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := purchaseAction.Create(&purchase.CreateRequestParams{
        PurchaseItems : []*purchase.CreatePurchaseItemParams{
            {
                Index : chargebee.Int32(1),
                ItemPriceId : "basic-USD",
                Quantity : chargebee.Int32(10),
            },
            {
                Index : chargebee.Int32(2),
                ItemPriceId : "basic-USD-yearly",
                Quantity : chargebee.Int32(5),
            },
        },
        SubscriptionInfo : []*purchase.CreateSubscriptionInfoParams{
            {
                Index : chargebee.Int32(1),
                SubscriptionId : "sub-1",
            },
            {
                Index : chargebee.Int32(2),
                SubscriptionId : "sub-2",
            },
        },
        CustomerId : "__test__XpbG9acT88TIuk3m",
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Purchase := res.Purchase
    }
}
```

#### 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.PurchaseCreateRequest{
    PurchaseItems : []*chargebee.PurchaseCreatePurchaseItem{
        {
            Index : chargebee.Int32(1),
            ItemPriceId : "basic-USD",
            Quantity : chargebee.Int32(10),
        },
        {
            Index : chargebee.Int32(2),
            ItemPriceId : "basic-USD-yearly",
            Quantity : chargebee.Int32(5),
        },
    },
    SubscriptionInfo : []*chargebee.PurchaseCreateSubscriptionInfo{
        {
            Index : chargebee.Int32(1),
            SubscriptionId : "sub-1",
        },
        {
            Index : chargebee.Int32(2),
            SubscriptionId : "sub-2",
        },
    },
    CustomerId : "__test__XpbG9acT88TIuk3m",
}
  res, err := client.Purchase.Create(req)
      if err != nil {
        fmt.Println(err)
    } else {
        Purchase := res.Purchase
    }
}
```

#### 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 = Purchase.create()
            .customerId("__test__XpbG9acT88TIuk3m")
            .purchaseItemIndex(0, 1)
            .purchaseItemItemPriceId(0, "basic-USD")
            .purchaseItemQuantity(0, 10)
            .purchaseItemIndex(1, 2)
            .purchaseItemItemPriceId(1, "basic-USD-yearly")
            .purchaseItemQuantity(1, 5)
            .subscriptionInfoIndex(0, 1)
            .subscriptionInfoSubscriptionId(0, "sub-1")
            .subscriptionInfoIndex(1, 2)
            .subscriptionInfoSubscriptionId(1, "sub-2")
            .request();

        Purchase purchase = result.purchase();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.purchase.Purchase;
import com.chargebee.v4.models.purchase.params.PurchaseCreateParams;
import com.chargebee.v4.models.purchase.responses.PurchaseCreateResponse;
import java.util.List;

public class PurchaseCreate {

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

        PurchaseCreateParams.PurchaseItemsParams purchaseItem0 =
            PurchaseCreateParams.PurchaseItemsParams.builder()
                .index(1)
                .itemPriceId("basic-USD")
                .quantity(10)
                .build();

        PurchaseCreateParams.PurchaseItemsParams purchaseItem1 =
            PurchaseCreateParams.PurchaseItemsParams.builder()
                .index(2)
                .itemPriceId("basic-USD-yearly")
                .quantity(5)
                .build();

        List<PurchaseCreateParams.PurchaseItemsParams> purchaseItemsList =
            List.of(purchaseItem0, purchaseItem1);

        PurchaseCreateParams.SubscriptionInfoParams subscriptionInfo0 =
            PurchaseCreateParams.SubscriptionInfoParams.builder()
                .index(1)
                .subscriptionId("sub-1")
                .build();

        PurchaseCreateParams.SubscriptionInfoParams subscriptionInfo1 =
            PurchaseCreateParams.SubscriptionInfoParams.builder()
                .index(2)
                .subscriptionId("sub-2")
                .build();

        List<PurchaseCreateParams.SubscriptionInfoParams> subscriptionInfoList =
            List.of(subscriptionInfo0, subscriptionInfo1);

        PurchaseCreateParams params = PurchaseCreateParams.builder()
            .customerId("__test__XpbG9acT88TIuk3m")
            .purchaseItems(purchaseItemsList)
            .subscriptionInfo(subscriptionInfoList)
            .build();

        PurchaseCreateResponse response = client.purchases().create(params);

        Purchase purchase = response.getPurchase();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.purchase.create({
        purchase_items: [
            {
                index: 1,
                item_price_id: "basic-USD",
                quantity: 10
            },
            {
                index: 2,
                item_price_id: "basic-USD-yearly",
                quantity: 5
            }
        ],
        subscription_info: [
            {
                index: 1,
                subscription_id: "sub-1"
            },
            {
                index: 2,
                subscription_id: "sub-2"
            }
        ],
        customer_id: "__test__XpbG9acT88TIuk3m"
    });

    console.log(result);
    const purchase = result.purchase;
} 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->purchase()->create([
    "purchase_items" => [
        [
            "index" => 1,
            "item_price_id" => "basic-USD",
            "quantity" => 10
        ],
        [
            "index" => 2,
            "item_price_id" => "basic-USD-yearly",
            "quantity" => 5
        ]
    ],
    "subscription_info" => [
        [
            "index" => 1,
            "subscription_id" => "sub-1"
        ],
        [
            "index" => 2,
            "subscription_id" => "sub-2"
        ]
    ],
    "customer_id" => "__test__XpbG9acT88TIuk3m"
]);
$purchase = $result->purchase;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Purchase.create(
    cb_client.Purchase.CreateParams(
        purchase_items=[
            cb_client.Purchase.CreatePurchaseItemParams(
              index=1,
              item_price_id="basic-USD",
              quantity=10
            ),
            cb_client.Purchase.CreatePurchaseItemParams(
              index=2,
              item_price_id="basic-USD-yearly",
              quantity=5
            )
        ],
        subscription_info=[
            cb_client.Purchase.CreateSubscriptionInfoParams(
              index=1,
              subscription_id="sub-1"
            ),
            cb_client.Purchase.CreateSubscriptionInfoParams(
              index=2,
              subscription_id="sub-2"
            )
        ],
        customer_id="__test__XpbG9acT88TIuk3m"
    )
)
purchase = response.purchase
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Purchase.create({
  :customer_id => "__test__XpbG9acT88TIuk3m",
  :purchase_items => [
    {
      :index => 1,
      :item_price_id => "basic-USD",
      :quantity => 10
    },
    {
      :index => 2,
      :item_price_id => "basic-USD-yearly",
      :quantity => 5
    }
  ],
  :subscription_info => [
    {
      :index => 1,
      :subscription_id => "sub-1"
    },
    {
      :index => 2,
      :subscription_id => "sub-2"
    }
  ]
})

purchase = result.purchase
```

## Sample Response

```json
{
  "purchase": {
    "created_at": 1651662622,
    "customer_id": "__test__rHsiT4rY1zmz",
    "id": "__test__rHsiT4rY2hC1A",
    "invoice_ids": [
      "__demo_inv__1",
      {..}
    ],
    "object": "purchase",
    "subscription_ids": [
      "__test__rHsiT4rY2Lr12",
      {..}
    ]
  }
}
```

## URL Format

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

## Input Parameters

- `customer_id` (required, string, max chars=50)
  The unique identifier of the [customer](/docs/api/customers) that made this purchase.

- `payment_source_id` (optional, string, max chars=40)
  Payment source attached to this purchase. If present, the customer's payment sources won't be used to collect any payment for this purchase.

- `replace_primary_payment_source` (optional, boolean, default=true)
  Indicates whether the primary payment source is replaced with this payment source. If a `payment_intent` object is included in the request, `replace_primary` defaults to `true`. For all other cases, the default is `false` .

- `invoice_info` (optional, string)
  Parameters for invoice\_info
  - `po_number` (optional, string, max chars=100)
    The [purchase order number](https://www.chargebee.com/docs/2.0/po-number.html) for this purchase. This is reflected in all the subscriptions and invoices under this purchase.
  - `notes` (optional, string, max chars=2000)
    A customer-facing note added to the PDF of the first invoice associated with this purchase. This is added to [invoice.notes](/docs/api/invoices/invoice-object#notes). Subsequent invoices do not have this note.

- `payment_schedule` (optional, string)
  Parameters for `payment_schedule`
  - `scheme_id` (optional, string, max chars=40)
    The identifier of the `payment_schedule_scheme` , used to create the payment schedules.
  - `amount` (optional, in cents, min=0)
    The part of the `invoice.amount_due` to be distributed across the payment schedules. If not specified, the entire `invoice.amount_due` is considered by default.

- `statement_descriptor` (optional, string)
  Parameters for statement\_descriptor
  - `descriptor` (optional, string, max chars=65k)
    Payment transaction descriptor text to help your customer easily recognize the transaction. When you pass this value it will override the [transaction descriptor](https://www.chargebee.com/docs/2.0/transaction_descriptors.html) text configured on your Chargebee site for the first [consolidated invoice](https://www.chargebee.com/docs/2.0/consolidated-invoicing.html) .

- `payment_intent` (optional, string)
  Parameters for payment\_intent
  - `id` (optional, string, max chars=150)
    Identifier for PaymentIntent generated by Chargebee.js. Applicable only when you are using Chargebee.js for completing the 3DS flow. The PaymentIntent should be in 'authorized' state while passing it here. You need not pass other PaymentIntent parameters if this is passed.
  - `gateway_account_id` (required if payment intent token provided, string, max chars=50)
    The gateway account used for performing the 3DS flow.
  - `gw_token` (optional, string, max chars=65k)
    Identifier for 3DS transaction/verification object at the gateway. Can be passed only after successfully completing the 3DS flow. Refer [3DS implementation in Chargebee](/docs/api/3ds_card_payments#3ds-gateway-side-implementation) to find out the gateway-specific gw\_token format. Applicable when you are using gateway APIs directly for completing the 3DS flow.
  - `payment_method_type` (optional, enumerated string)
    The list of payment method types (For example, card, ideal, sofort, bancontact, etc.) this Payment Intent is allowed to use. If payment method type is empty, Card is taken as the default type for all gateways except Razorpay.
    Possible enum values:
      - `card`
        Card based payment including credit cards and debit cards.
      - `ideal`
        Payments made via iDEAL.
      - `sofort`
        Payments made via Sofort.
      - `bancontact`
        Payments made via Bancontact Card.
      - `google_pay`
        Payments made via Google Pay.
      - `dotpay`
        Payments made via Dotpay.
      - `giropay`
        Payments made via giropay.
      - `apple_pay`
        Payments made via Apple Pay.
      - `upi`
        UPI Payments.
      - `netbanking_emandates`
        Netbanking (eMandates) Payments.
      - `paypal_express_checkout`
        Payments made via PayPal Express Checkout.
      - `direct_debit`
        Payments made via Direct Debit.
      - `boleto`
        Payments made via Boleto.
      - `venmo`
        Venmo
      - `amazon_payments`
        Amazon Payments
      - `pay_to`
        PayTo
      - `faster_payments`
        Faster Payments
      - `sepa_instant_transfer`
        Sepa Instant Transfer
      - `klarna_pay_now`
        Klarna Pay Now
      - `online_banking_poland`
        Online Banking Poland
      - `payconiq_by_bancontact`
        Payconiq by Bancontact
      - `electronic_payment_standard`
        Electronic Payment Standard
      - `kbc_payment_button`
        KBC Payment Button
      - `pay_by_bank`
        Pay By Bank
      - `trustly`
        Trustly
      - `stablecoin`
        Stablecoin
      - `kakao_pay`
        Kakao Pay
      - `naver_pay`
        Naver Pay
      - `revolut_pay`
        Revolut Pay
      - `cash_app_pay`
        Cash App Pay
      - `wechat_pay`
        WeChat Pay
      - `alipay`
        Alipay
      - `twint`
        Twint
      - `go_pay`
        Go Pay
      - `grab_pay`
        Grab Pay
      - `pay_co`
        Pay Co
      - `after_pay`
        After Pay
      - `swish`
        Swish
      - `payme`
        PayMe
      - `pix`
        Payments made via Pix
      - `klarna`
        Klarna
      - `alipay_hk`
        Payments made via Alipay HK.
      - `paypay`
        PayPay
      - `gcash`
        Payments made via GCash.
      - `south_korean_cards`
        Payments made via South Korean Cards
      - `paynow`
      - `bizum`
      - `promptpay`
      - `dana`
        Payments made via Dana.
      - `touch_n_go`
        Payments made via Touch 'n Go.
      - `tamara`
        Payments made via Tamara.
      - `qpay`
        Payments made via Qpay.
      - `ovo`
      - `momo`
      - `mercado_pago`
      - `nequi`
      - `nupay`
      - `picpay`
      - `thai_qr`
      - `blik`
      - `fpx`
      - `wero`
      - `p24`
      - `affirm_pay`
      - `rakuten_pay`
  - `reference_id` (optional, string, max chars=65k)
    Identifier for Braintree permanent token. Applicable when you are using Braintree APIs for completing the 3DS flow.
  - `additional_information` (optional, jsonobject)
    -   `checkout_com`: While adding a new payment method using [permanent token](/docs/api/payment_sources/create-using-permanent-token) or passing raw card details to Checkout.com, `document` ID and `country_of_residence` are required to support payments through [dLocal](https://www.checkout.com/docs/previous/payments/payment-methods/cards/dlocal).
        
        -   `payer`: User related information.
            -   `country_of_residence`: This is required since the billing country associated with the user's payment method may not be the same as their country of residence. Hence the user's country of residence needs to be specified. The country code should be a [two-character ISO code](https://docs.checkout.com/resources/codes/country-codes).
            -   `document`: Document ID is the user's [identification number](https://docs.dlocal.com/api-documentation/payins-api-reference/country-reference#documents) based on their country.
    -   `bluesnap`: While passing raw card details to BlueSnap, if `fraud_session_id` is added, [additional validation](https://developers.bluesnap.com/docs/fraud-prevention) is performed to avoid fraudulent transactions.
        
        -   `fraud`: Fraud identification related information.
            -   `fraud_session_id`: Your [BlueSnap fraud session ID](https://developers.bluesnap.com/docs/fraud-prevention#section-implementing-device-data-collector) required to perform anti-fraud validation.
    -   `braintree`: While passing raw card details to Braintree, your `fraud_merchant_id` and the user's `device_session_id` can be added to perform [additional validation](https://developers.braintreepayments.com/guides/premium-fraud-management-tools/device-data-collection/javascript/v3#collecting-device-data) and avoid fraudulent transactions.
        
        -   `fraud`: Fraud identification related information.
            -   `device_session_id`: Session ID associated with the user's device.
            -   `fraud_merchant_id`: Your [merchant ID](https://developers.braintreepayments.com/guides/premium-fraud-management-tools/device-data-collection/javascript/v3#collecting-device-data) for fraud detection.
    -   `chargebee_payments`: While passing raw card details to Chargebee Payments, if `fraud_session_id` is added, additional validation is performed to avoid fraudulent transactions.
        
        -   `fraud`: Fraud identification related information.
            -   `fraud_session_id`: Your Chargebee Payments fraud session ID required to perform anti-fraud validation.
    -   `bank_of_america`: While passing raw card details to Bank of America, your user's `device_session_id` can be added to perform additional validation and avoid fraudulent transactions.
        
        -   `fraud`: Fraud identification related information.
            -   `device_session_id`: Session ID associated with the user's device.
    -   `ecentric`: This parameter is used to verify and process payment method details in Ecentric. If the `merchant_id` parameter is included, Chargebee will vault it / perform a lookup and verification against this `merchant_id`, overriding the one configured in Chargebee. If tokens and processing occur in the same Merchant GUID, you can just skip this part.
        
        -   `merchant_id`: Merchant GUID where the card is vaulted or need to be vaulted.
    -   `ebanx`: While passing raw card details to EBANX, the user's `document` is required for some countries and `device_session_id` can be added to perform [additional validation](https://developer.ebanx.com/docs/payments/guides/features/device-fingerprint#device-fingerprint) and avoid fraudulent transactions.
        
        -   `payer`: User related information.
            -   `document`: Document is the user's identification number based on their country.
        -   `fraud`: Fraud identification related information.
            -   `device_session_id`: Session ID associated with the user's device

- `purchase_items` (optional, array)
  Parameters for purchase\_items
  - `index` (required, integer)
    The index or identifier of the [group](/docs/api/purchases) to which the item price belongs. The item prices assigned the same index belong to the same group.
  - `item_price_id` (required, string, max chars=100)
    The unique identifier of the [item price](/docs/api/item_prices) to be added to the [group](/docs/api/purchases) .
  - `quantity` (optional, integer)
    The quantity of the item price. Applicable only when the [pricing model](/docs/api/item_prices/item_price-object#pricing_model) of the item price is anything other than `flat_fee`. You can provide this value whether [multi-decimal pricing](/docs/api/currencies) is enabled or disabled.
  - `unit_amount` (optional, in cents)
    The price or per unit price of the item. You may provide this only when [price overriding](https://www.chargebee.com/docs/2.0/price-override.html) is enabled for the site.
  - `unit_amount_in_decimal` (optional, string, max chars=39)
    The decimal representation of the price or per-unit price of the plan. The value is in major units of the currency. Always returned when [multi-decimal pricing](/docs/api/currencies) is enabled.
  - `quantity_in_decimal` (optional, string, max chars=33)
    The decimal representation of the quantity of the item purchased. By default [multi-decimal pricing](/docs/api/currencies) is enabled for purchase API, it is recommended to use the `purchase_items[quantity_in_decimal][0..n]` for providing quantity-based item prices when multi-decimal pricing is enabled. When multi-decimal pricing is disabled provide the value in `purchase_items[quantity][0..n]` .

- `item_tiers` (optional, array)
  Parameters for item\_tiers
  - `index` (required, integer)
    The index or identifier of the [group](/docs/api/purchases) to which this tier information belongs. This must be a value from the `purchase_items[index]` array.
  - `item_price_id` (optional, string, max chars=100)
    The unique ID of the item price to which this tier information belongs. This must be a value from the `purchase_items[item_price_id]` array.
  - `starting_unit` (optional, integer)
    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 very next lower tier.
  - `ending_unit` (optional, integer)
    The highest value of quantity in this tier. For all other tiers,it must be equal to the `starting_unit_in_decimal` of the very next higher tier.
  - `price` (optional, in cents)
    The per-unit price for the tier when the `pricing_model` is `tiered` or `volume`. When the `pricing_model` is `stairstep` , it is the total price of the item. The currency units in which this value is expressed [depends](/docs/api/currencies) on the type of currency.
  - `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 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. Returned only when the pricing\_model is `tiered` , `volume` or `stairstep` and [multi-decimal pricing](/docs/api/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 the item. The value is in major units of the currency. Returned when the plan is quantity-based and [multi-decimal pricing](/docs/api/currencies) is enabled.

- `shipping_addresses` (optional, array)
  Parameters for shipping\_addresses
  - `first_name` (optional, string, max chars=150)
    The first name of the contact. This parameter is `mandatory` when providing shipping information.
  - `last_name` (optional, string, max chars=150)
    The last name of the contact. This parameter is `mandatory` when providing shipping information.
  - `email` (optional, string, max chars=70)
    The email address.
  - `company` (optional, string, max chars=250)
    The company name.
  - `phone` (optional, string, max chars=50)
    The phone number.
  - `line1` (optional, string, max chars=150)
    Address line 1. This parameter is `mandatory` when providing shipping information.
  - `line2` (optional, string, max chars=150)
    Address line 2
  - `line3` (optional, string, max chars=150)
    Address line 3
  - `city` (optional, string, max chars=50)
    The name of the city. This parameter is `mandatory` when providing shipping information.
  - `state` (optional, string, max chars=50)
    The state/province name.
  - `state_code` (optional, string, max chars=50)
    The [ISO 3166-2 state/province code](https://www.iso.org/obp/ui/#search) without the country prefix. Currently supported for USA, Canada and India. For instance, for Arizona (USA), set `state_code` as `AZ` (not `US-AZ` ). For Tamil Nadu (India), set as `TN` (not `IN-TN` ). For British Columbia (Canada), set as `BC` (not `CA-BC` ).
  - `country` (optional, string, max chars=50)
    The billing address country of the customer. Must be one of [ISO 3166 alpha-2 country code](https://www.iso.org/iso-3166-country-codes.html). This parameter is `mandatory` when providing shipping information.
    
    **Note**: If you enter an invalid country code, the system will return an error.
    
    **Brexit**
    
    If you have enabled [EU VAT](https://www.chargebee.com/docs/eu-vat.html) in 2021 or later, or have [manually enable](https://www.chargebee.com/docs/brexit.html#what-needs-to-be-done-in-chargebee) the Brexit configuration, then `XI` (the code for **United Kingdom - Northern Ireland**) is available as an option.
  - `zip` (optional, string, max chars=20)
    Zip or postal code. The number of characters is validated according to the rules [specified here](https://chromium-i18n.appspot.com/ssl-address). This parameter is `mandatory` when providing shipping information.
  - `validation_status` (optional, enumerated string)
    The address verification status.
    Possible enum values:
      - `not_validated`
        Address is not yet validated.
      - `valid`
        Address was validated successfully.
      - `partially_valid`
        The address is valid for taxability but has not been validated for shipping.
      - `invalid`
        Address is invalid.

- `discounts` (optional, array)
  Parameters for discounts
  - `index` (optional, integer)
    The index or identifier of the [group](/docs/api/purchases) to which this discount or coupon information belongs. This must be a value from the `purchase_items[index]` array. When not provided, the coupon is applied to the first invoice only; irrespective of the values set for `[coupon.duration_type](/docs/api/coupons/coupon-object#duration_type)`or `[coupon.max_redemptions](/docs/api/coupons/coupon-object#max_redemptions)`.
    
    **See also:**
    
    [Applying discounts](/docs/api/purchases)
  - `coupon_id` (optional, string, max chars=100)
    The unique ID of a coupon to be applied to the group. Alternatively, you may provide a [coupon code](/docs/api/coupon_codes). Applicable only for [coupons](/docs/api/coupons).
    
    **See also:** [Applying discounts](/docs/api/purchases)
  - `percentage` (optional, double)
    The percentage of the discount. Applicable only for [manual discounts](/docs/api/discounts). For any given array index `i`, provide `discounts[percentage][i]` or `discounts[quantity][i]` or `discounts[amount][i]`
    
    **See also:**
    
    [Applying discounts](/docs/api/purchases)
  - `quantity` (optional, integer)
    The discount quantity. Applicable only for [manual discounts](/docs/api/discounts). For any given array index `i`, provide `discounts[percentage][i]` or `discounts[quantity][i]` or `discounts[amount][i]`
    
    **See also:**
    
    [Applying discounts](/docs/api/purchases)
  - `amount` (optional, in cents)
    The absolute value of the discount. The currency units in which this value is expressed [depends](/docs/api/currencies) on the type of currency. Applicable only for [manual discounts](/docs/api/discounts). For any given array index `i`, you can provide `discounts[percentage][i]` or `discounts[quantity][i]` or `discounts[amount][i]`
    
    **See also:**
    
    [Applying discounts](/docs/api/purchases)
  - `included_in_mrr` (optional, boolean)
    For [manual discounts](/docs/api/discounts), set this to `false` if this manual discount should be excluded from monthly recurring revenue (MRR) calculations for the site. The following prerequisites must be met to allow this parameter to be passed:
    
    -   The feature must be [enabled in Chargebee](https://www.chargebee.com/docs/2.0/reporting.html#dashboards_flexible-mrr-calculation).
    -   The [site-level](https://www.chargebee.com/docs/2.0/reporting.html#chart_flexible-mrr-calculation) setting must be to include coupons in MRR calculations.
    
    **See also:** [Applying discounts](/docs/api/purchases)

- `subscription_info` (optional, array)
  Parameters for subscription\_info
  - `index` (required, integer)
    The index or identifier of the [group](/docs/api/purchases) to which this subscription information belongs. This must be a value from the `purchase_items[index]` array and the group must be a [subscription group](/docs/api/purchases) .
  - `subscription_id` (optional, string, max chars=50)
    When specifying a [subscription group](/docs/api/purchases) , this is the unique identifier of the [subscription](/docs/api/subscriptions) to be created. This value must be unique for each subscription group.
  - `billing_cycles` (optional, integer)
    The number of billing cycles the subscription runs before canceling. If not provided, then the billing cycles [set for the plan-item price](/docs/api/item_prices/item_price-object#billing_cycles) is used.
  - `contract_term_billing_cycle_on_renewal` (optional, integer)
    Number of billing cycles the new contract term should run for, on contract renewal. The default value is the same as `billing_cycles` or a custom value depending on the [site configuration](https://www.chargebee.com/docs/contract-terms.html#configuring-contract-terms) .
  - `meta_data` (optional, jsonobject)
    A collection of key-value pairs that provides extra information about the customer.
    
    **Note:** There's a character limit of 65,535.
    
    [Learn more](/docs/api/advanced-features) .

- `contract_terms` (optional, array)
  Parameters for contract\_terms
  - `index` (required, integer)
    The index number of the subscription/one-time group to which the item price is added. Provide a unique number between `0` and `9` (inclusive) for each group that is to be created. To increase this limit, contact Chargebee Support
  - `action_at_term_end` (optional, enumerated string)
    Action to be taken when the contract term completes.
    Possible enum values:
      - `renew`
        -   Contract term completes and a new contract term is started for the number of billing cycles specified in [`contract_billing_cycle_on_renewal`](/docs/api/v2/pcv-1/subscriptions/create-subscription-for-customer#contract_term_billing_cycle_on_renewal).
        -   The `action_at_term_end` for the new contract term is set to `renew`.
      - `evergreen`
        Contract term completes and the subscription renews.
      - `cancel`
        Contract term completes and subscription is canceled.
      - `renew_once`
        Used when you want to renew the contract term just once. Does the following: - Contract term completes and a new contract term is started for the number of billing cycles specified in [`contract_billing_cycle_on_renewal`](/docs/api/v2/pcv-1/subscriptions/create-subscription-for-customer#contract_term_billing_cycle_on_renewal).
        
        -   The `action_at_term_end` for the new contract term is set to `cancel`.
  - `cancellation_cutoff_period` (optional, integer)
    The number of days before [`contract_end`](/docs/api/contract_terms/contract_term-object#contract_end) , during which the customer is barred from canceling the contract term. The customer is allowed to cancel the contract term via the Self-Serve Portal only before this period. This allows you to have sufficient time for processing the contract term closure.

## Returns

- `purchase` (Purchase object)
  Resource object representing purchase
