# Estimates for purchase

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


**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).

Returns an estimate for creating a `purchase` resource. The operation works exactly like [Create a purchase](/docs/api/purchases/create-a-purchase), except that only an `[estimate](/docs/api/estimates)` resource is returned without an actual `purchase` resource being created.

## Sample Request

### Default

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/purchases/estimate \
     -u {site_api_key}:\
     -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.Estimate()
		.PurchaseItemIndex(0, 1)
		.PurchaseItemItemPriceId(0, "basic-USD")
		.PurchaseItemQuantity(0, 10)
		.PurchaseItemIndex(1, 2)
		.PurchaseItemItemPriceId(1, "basic-USD-yearly")
		.PurchaseItemQuantity(1, 5)
		.Request();

Estimate estimate = result.Estimate;
```

#### 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.Estimate(&purchase.EstimateRequestParams{
        PurchaseItems : []*purchase.EstimatePurchaseItemParams{
            {
                Index : chargebee.Int32(1),
                ItemPriceId : "basic-USD",
                Quantity : chargebee.Int32(10),
            },
            {
                Index : chargebee.Int32(2),
                ItemPriceId : "basic-USD-yearly",
                Quantity : chargebee.Int32(5),
            },
        },
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Estimate := res.Estimate
    }
}
```

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

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

        Estimate estimate = result.estimate();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.estimate.Estimate;
import com.chargebee.v4.models.purchase.params.PurchaseEstimateParams;
import com.chargebee.v4.models.purchase.responses.PurchaseEstimateResponse;
import java.util.List;

public class PurchaseEstimate {

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

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

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

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

        PurchaseEstimateParams params = PurchaseEstimateParams.builder()
            .purchaseItems(purchaseItemsList)
            .build();

        PurchaseEstimateResponse response = client.purchases().estimate(params);

        Estimate estimate = response.getEstimate();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

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

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

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Purchase.estimate(
    cb_client.Purchase.EstimateParams(
        purchase_items=[
            cb_client.Purchase.EstimatePurchaseItemParams(
              index=1,
              item_price_id="basic-USD",
              quantity=10
            ),
            cb_client.Purchase.EstimatePurchaseItemParams(
              index=2,
              item_price_id="basic-USD-yearly",
              quantity=5
            )
        ]
    )
)
estimate = response.estimate
```

#### Ruby

```ruby
require 'chargebee'

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

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

estimate = result.estimate
```

### Estimate With Plan And Addons

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/purchases/estimate \
     -u {site_api_key}:\
     -d customer_id="__test__XpbG9acT88TIUT3H" \
     -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.Estimate()
		.CustomerId("__test__XpbG9acT88TIUT3H")
		.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();

Estimate estimate = result.Estimate;
```

#### 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.Estimate(&purchase.EstimateRequestParams{
        PurchaseItems : []*purchase.EstimatePurchaseItemParams{
            {
                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__XpbG9acT88TIUT3H",
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Estimate := res.Estimate
    }
}
```

#### 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.PurchaseEstimateRequest{
    PurchaseItems : []*chargebee.PurchaseEstimatePurchaseItem{
        {
            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__XpbG9acT88TIUT3H",
}
  res, err := client.Purchase.Estimate(req)
      if err != nil {
        fmt.Println(err)
    } else {
        Estimate := res.Estimate
    }
}
```

#### 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.estimate()
            .customerId("__test__XpbG9acT88TIUT3H")
            .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();

        Estimate estimate = result.estimate();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.estimate.Estimate;
import com.chargebee.v4.models.purchase.params.PurchaseEstimateParams;
import com.chargebee.v4.models.purchase.responses.PurchaseEstimateResponse;
import java.util.List;

public class PurchaseEstimate {

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

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

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

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

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

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

        PurchaseEstimateParams params = PurchaseEstimateParams.builder()
            .customerId("__test__XpbG9acT88TIUT3H")
            .purchaseItems(purchaseItemsList)
            .build();

        PurchaseEstimateResponse response = client.purchases().estimate(params);

        Estimate estimate = response.getEstimate();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.purchase.estimate({
        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__XpbG9acT88TIUT3H"
    });

    console.log(result);
    const estimate = result.estimate;
} 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()->estimate([
    "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__XpbG9acT88TIUT3H"
]);
$estimate = $result->estimate;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Purchase.estimate(
    cb_client.Purchase.EstimateParams(
        purchase_items=[
            cb_client.Purchase.EstimatePurchaseItemParams(
              index=1,
              item_price_id="basic-USD",
              quantity=5
            ),
            cb_client.Purchase.EstimatePurchaseItemParams(
              index=1,
              item_price_id="day-pass-USD"
            ),
            cb_client.Purchase.EstimatePurchaseItemParams(
              index=2,
              item_price_id="basic-USD-yearly",
              quantity=5
            ),
            cb_client.Purchase.EstimatePurchaseItemParams(
              index=2,
              item_price_id="day-pass-USD"
            )
        ],
        customer_id="__test__XpbG9acT88TIUT3H"
    )
)
estimate = response.estimate
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Purchase.estimate({
  :customer_id => "__test__XpbG9acT88TIUT3H",
  :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"
    }
  ]
})

estimate = result.estimate
```

### With CustomerId

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/purchases/estimate \
     -u {site_api_key}:\
     -d customer_id="__test__XpbG9acT88TII837" \
     -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.Estimate()
		.CustomerId("__test__XpbG9acT88TII837")
		.PurchaseItemIndex(0, 1)
		.PurchaseItemItemPriceId(0, "basic-USD")
		.PurchaseItemQuantity(0, 10)
		.PurchaseItemIndex(1, 2)
		.PurchaseItemItemPriceId(1, "basic-USD-yearly")
		.PurchaseItemQuantity(1, 5)
		.Request();

Estimate estimate = result.Estimate;
```

#### 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.Estimate(&purchase.EstimateRequestParams{
        PurchaseItems : []*purchase.EstimatePurchaseItemParams{
            {
                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__XpbG9acT88TII837",
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Estimate := res.Estimate
    }
}
```

#### 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.PurchaseEstimateRequest{
    PurchaseItems : []*chargebee.PurchaseEstimatePurchaseItem{
        {
            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__XpbG9acT88TII837",
}
  res, err := client.Purchase.Estimate(req)
      if err != nil {
        fmt.Println(err)
    } else {
        Estimate := res.Estimate
    }
}
```

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

        Estimate estimate = result.estimate();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.estimate.Estimate;
import com.chargebee.v4.models.purchase.params.PurchaseEstimateParams;
import com.chargebee.v4.models.purchase.responses.PurchaseEstimateResponse;
import java.util.List;

public class PurchaseEstimate {

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

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

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

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

        PurchaseEstimateParams params = PurchaseEstimateParams.builder()
            .customerId("__test__XpbG9acT88TII837")
            .purchaseItems(purchaseItemsList)
            .build();

        PurchaseEstimateResponse response = client.purchases().estimate(params);

        Estimate estimate = response.getEstimate();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

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

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

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Purchase.estimate(
    cb_client.Purchase.EstimateParams(
        purchase_items=[
            cb_client.Purchase.EstimatePurchaseItemParams(
              index=1,
              item_price_id="basic-USD",
              quantity=10
            ),
            cb_client.Purchase.EstimatePurchaseItemParams(
              index=2,
              item_price_id="basic-USD-yearly",
              quantity=5
            )
        ],
        customer_id="__test__XpbG9acT88TII837"
    )
)
estimate = response.estimate
```

#### Ruby

```ruby
require 'chargebee'

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

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

estimate = result.estimate
```

## Sample Response

```json
{
  "estimate": {
    "created_at": 1651662607,
    "invoice_estimates": [
      {
        "amount_due": 15000,
        "amount_paid": 0,
        "credits_applied": 0,
        "currency_code": "USD",
        "customer_id": "__test__rHsiT4rXxy4U",
        "date": 1651662606,
        "line_item_discounts": {},
        "line_item_taxes": {},
        "line_item_tiers": [
          {
            "ending_unit": 10,
            "line_item_id": "li___test__rHsiT4rXyUya",
            "object": "line_item_tier",
            "quantity_used": 5,
            "starting_unit": 1,
            "unit_amount": 1000
          },
          {..}
        ],
        "line_items": [
          {
            "amount": 10000,
            "customer_id": "__test__rHsiT4rXxy4U",
            "date_from": 1651662604,
            "date_to": 1654341004,
            "description": "basic USD",
            "discount_amount": 0,
            "entity_id": "basic-USD",
            "entity_type": "plan_item_price",
            "id": "li___test__rHsiT4rXyJmX",
            "is_taxed": false,
            "item_level_discount_amount": 0,
            "object": "line_item",
            "pricing_model": "per_unit",
            "quantity": 10,
            "subscription_id": "__test__rHsiT4rXxzvV",
            "tax_amount": 0,
            "unit_amount": 1000
          },
          {..}
        ],
        "object": "invoice_estimate",
        "price_type": "tax_exclusive",
        "recurring": true,
        "round_off_amount": 0,
        "sub_total": 15000,
        "taxes": {},
        "total": 15000
      },
      {..}
    ],
    "object": "estimate"
  }
}
```

## URL Format

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

## Input Parameters

- `client_profile_id` (optional, string, max chars=50)
  Indicates the Client profile id for the customer. This is applicable only if you use [Chargebee's AvaTax for Communications](https://www.chargebee.com/docs/avatax-for-communication.html) integration.

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

- `customer` (optional, string)
  Parameters for customer
  - `vat_number` (optional, string, max chars=20)
    VAT number of this customer. If not provided then taxes are not calculated for the estimate. Applicable only when taxes are configured for the EU or UK region. VAT validation is not done for this.
  - `vat_number_prefix` (optional, string, max chars=10)
    An overridden value for the first two characters of the [full VAT number](https://en.wikipedia.org/wiki/VAT_identification_number). Only applicable specifically for customers with `[billing_address](/docs/api/customers/customer-object#billing_address)`
    
    `country` as `XI` (which is **United Kingdom - Northern Ireland** ).
    
    When you have enabled [EU VAT](https://www.chargebee.com/docs/eu-vat.html) in 2021 or have [manually enabled](https://www.chargebee.com/docs/brexit.html#what-needs-to-be-done-in-chargebee) the Brexit configuration, you have the option of setting `[billing_address](/docs/api/customers/customer-object#billing_address)`
    
    `country` as `XI`. That's the code for **United Kingdom - Northern Ireland**. The first two characters of the VAT number in such a case is `XI` by default. However, if the VAT number was registered in UK, the value should be `GB`. Set `vat_number_prefix` to `GB` for such cases.
  - `registered_for_gst` (optional, boolean)
    Confirms that a customer is registered under GST. If set to `true` then the [Reverse Charge Mechanism](https://www.chargebee.com/docs/australian-gst.html#reverse-charge-mechanism) is applicable. This field is applicable only when Australian GST is configured for your site.
  - `taxability` (optional, enumerated string, default=taxable)
    Specifies if the customer is liable for tax
    Possible enum values:
      - `taxable`
        Computes tax for the customer based on the [site configuration](https://www.chargebee.com/docs/tax.html). In some cases, depending on the region, shipping\_address is needed. If not provided, then billing\_address is used to compute tax. If that's not available either, the tax is taken as zero.
      - `exempt`
        -   Customer is exempted from tax. When using Chargebee's native [Taxes](https://www.chargebee.com/docs/tax.html) feature or when using the [TaxJar integration](https://www.chargebee.com/docs/taxjar.html), no other action is needed.
        -   However, when using our [Avalara integration](https://www.chargebee.com/docs/avalara.html), optionally, specify `entity_code` or `exempt_number` attributes if you use Chargebee's [AvaTax for Sales](https://www.chargebee.com/docs/avalara.html#configuring-tax-exemption) or specify `exemption_details` attribute if you use [Chargebee's AvaTax for Communications](https://www.chargebee.com/docs/avatax-for-communication.html) integration. Tax may still be applied by Avalara for certain values of `entity_code`/`exempt_number`/`exemption_details` based on the state/region/province of the taxable address.
  - `entity_code` (optional, enumerated string)
    The exemption category of the customer, for USA and Canada. Applicable if you use Chargebee's [AvaTax for Sales integration](https://www.chargebee.com/docs/avalara.html#configuring-tax-exemption) .
    Possible enum values:
      - `a`
        Federal government
      - `b`
        State government
      - `c`
        Tribe/Status Indian/Indian Band
      - `d`
        Foreign diplomat
      - `e`
        Charitable or benevolent organization
      - `f`
        Religious organization
      - `g`
        Resale
      - `h`
        Commercial agricultural production
      - `i`
        Industrial production/manufacturer
      - `j`
        Direct pay permit
      - `k`
        Direct mail
      - `l`
        Other or custom
      - `m`
        Educational organization
      - `n`
        Local government
      - `p`
        Commercial aquaculture
      - `q`
        Commercial Fishery
      - `r`
        Non-resident
      - `med1`
        US Medical Device Excise Tax with exempt sales tax
      - `med2`
        US Medical Device Excise Tax with taxable sales tax
  - `exempt_number` (optional, string, max chars=100)
    Any string value that will cause the sale to be exempted. Use this if your finance team manually verifies and tracks exemption certificates. Applicable if you use Chargebee's [AvaTax for Sales integration](https://www.chargebee.com/docs/avalara.html#configuring-tax-exemption) .
  - `exemption_details` (optional)
    Indicates the exemption information. You can customize customer exemption based on specific Location, Tax level (Federal, State, County and Local), Category of Tax or specific Tax Name. This is applicable only if you use [Chargebee's AvaTax for Communications](https://www.chargebee.com/docs/avatax-for-communication.html) integration. To know more about what values you need to provide, refer to this [Avalara's API document](https://developer.avalara.com/communications/dev-guide_rest_v2/customizing-transactions/sample-transactions/exemption/) .
  - `customer_type` (optional, enumerated string)
    Indicates the type of the customer. 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:
      - `residential`
        When the purchase is made by a customer for home use
      - `business`
        When the purchase is made at a place of business
      - `senior_citizen`
        When the purchase is made by a customer who meets the jurisdiction requirements to be considered a senior citizen and qualifies for senior citizen tax breaks
      - `industrial`
        When the purchase is made by an industrial business

- `billing_address` (optional, string)
  Parameters for billing\_address
  - `line1` (optional, string, max chars=150)
    Address line 1
  - `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.
  - `state_code` (optional, string, max chars=50)
    The [ISO 3166-2 state/province code](https://www.iso.org/obp/ui/#search/code) 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` ).
  - `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) .
  - `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) .
    
    **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.
  - `validation_status` (optional, enumerated string, default=not_validated)
    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.

- `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/getting-started) 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/getting-started) 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`, 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) .

- `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

- `estimate` (Estimate object)
  Resource object representing estimate
