# Cancel subscription for items estimate

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


Creates an estimate for [canceling](/docs/api/subscriptions/cancel-subscription-for-items) the specified subscription.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/subscriptions/__test__8ass3SIVLJaId/cancel_subscription_for_items_estimate \
     -u {site_api_key}:\
     -d credit_option_for_current_term_charges="PRORATE" \
     -d end_of_term="false"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Estimate.CancelSubscriptionForItems("__test__8ass3SIVLJaId")
		.CreditOptionForCurrentTermCharges(CreditOptionForCurrentTermChargesEnum.Prorate)
		.EndOfTerm(false)
		.Request();

Estimate estimate = result.Estimate;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    estimateAction "github.com/chargebee/chargebee-go/v3/actions/estimate"
    "github.com/chargebee/chargebee-go/v3/models/estimate"
    enum "github.com/chargebee/chargebee-go/v3/enum"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := estimateAction.CancelSubscriptionForItems("__test__8ass3SIVLJaId", &estimate.CancelSubscriptionForItemsRequestParams{
        CreditOptionForCurrentTermCharges : enum.CreditOptionForCurrentTermChargesProrate,
        EndOfTerm : chargebee.Bool(false),
    }).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.EstimateCancelSubscriptionForItemsRequest{
    CreditOptionForCurrentTermCharges : chargebee.CreditOptionForCurrentTermChargesProrate,
    EndOfTerm : chargebee.Bool(false),
}
  res, err := client.Estimate.CancelSubscriptionForItems("__test__8ass3SIVLJaId", 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 = Estimate.cancelSubscriptionForItems("__test__8ass3SIVLJaId")
            .creditOptionForCurrentTermCharges(CreditOptionForCurrentTermCharges.PRORATE)
            .endOfTerm(false)
            .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.estimate.params.EstimateCancelSubscriptionForItemsParams;
import com.chargebee.v4.models.estimate.responses.EstimateCancelSubscriptionForItemsResponse;

public class EstimateCancelSubscriptionForItems {

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

        EstimateCancelSubscriptionForItemsParams params = EstimateCancelSubscriptionForItemsParams.builder()
            .creditOptionForCurrentTermCharges(EstimateCancelSubscriptionForItemsParams.CreditOptionForCurrentTermCharges.PRORATE)
            .endOfTerm(false)
            .build();

        EstimateCancelSubscriptionForItemsResponse response = client
            .estimates()
            .cancelSubscriptionForItems("__test__8ass3SIVLJaId", 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.estimate.cancelSubscriptionForItems("__test__8ass3SIVLJaId", {
        credit_option_for_current_term_charges: "prorate",
        end_of_term: false
    });

    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->estimate()->cancelSubscriptionForItems("__test__8ass3SIVLJaId", [
    "credit_option_for_current_term_charges" => "prorate",
    "end_of_term" => false
]);
$estimate = $result->estimate;
```

#### Python

```python
import chargebee
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Estimate.cancel_subscription_for_items("__test__8ass3SIVLJaId",
    cb_client.Estimate.CancelSubscriptionForItemsParams(
        credit_option_for_current_term_charges=chargebee.CreditOptionForCurrentTermCharges.PRORATE,
        end_of_term=False
    )
)
estimate = response.estimate
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Estimate.cancel_subscription_for_items("__test__8ass3SIVLJaId",{
  :credit_option_for_current_term_charges => "PRORATE",
  :end_of_term => "false"
})

estimate = result.estimate
```

## Sample Response

```json
{
  "estimate": {
    "created_at": 1612964956,
    "credit_note_estimates": [
      {
        "amount_allocated": 1100,
        "amount_available": 0,
        "currency_code": "USD",
        "customer_id": "__test__8asyKSOceZlINV",
        "line_item_discounts": {},
        "line_item_taxes": {},
        "line_items": [
          {
            "amount": 1000,
            "customer_id": "__test__8asyKSOceZlINV",
            "date_from": 1612964956,
            "date_to": 1615384155,
            "description": "basic USD - Prorated Credits for 10-Feb-2021 - 10-Mar-2021",
            "discount_amount": 0,
            "entity_id": "basic-USD",
            "entity_type": "plan_item_price",
            "id": "li___test__8asyKSOceZyANi",
            "is_taxed": false,
            "item_level_discount_amount": 0,
            "object": "line_item",
            "pricing_model": "per_unit",
            "quantity": 1,
            "subscription_id": "__test__8asyKSOceZpONY",
            "tax_amount": 0,
            "unit_amount": 1000
          },
          {..}
        ],
        "object": "credit_note_estimate",
        "price_type": "tax_exclusive",
        "reference_invoice_id": "__demo_inv__4",
        "round_off_amount": 0,
        "sub_total": 1100,
        "taxes": {},
        "total": 1100,
        "type": "adjustment"
      },
      {..}
    ],
    "object": "estimate",
    "subscription_estimate": {
      "currency_code": "USD",
      "id": "__test__8asyKSOceZpONY",
      "object": "subscription_estimate",
      "status": "cancelled"
    }
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/subscriptions/{subscription-id}/cancel_subscription_for_items_estimate

## Input Parameters

- `cancel_option` (optional, enumerated string)
  ##### If the subscription does not have a contract term:[](#if-the-subscription-does-not-have-a-contract-term)
  
  Determines when to cancel the subscription.
  
  ##### If the subscription has a contract term:[](#if-the-subscription-has-a-contract-term)
  
  This parameter is not applicable.
  Possible enum values:
    - `immediately`
      This is used to cancel the subscription with immediate effect
    - `end_of_term`
      This is used to cancel a subscription at the end of the current billing cycle
    - `specific_date`
      This is used to cancel a subscription on a specified date. The change occurs as of the date/time defined in `cancel_at`
    - `end_of_billing_term`
      This is used to cancel a subscription either at the end of the advance term, if it's billed for future renewals or at the end of its current billing cycle

- `end_of_term` (optional, boolean, default=false)
  **(Deprecated)** Use `cancel_option` instead. Applicable only when the subscription does not have [contract terms](/docs/api/contract_terms). Set this to `true` if you want to cancel the subscription at the end of the current subscription billing cycle. The subscription `status` changes to `non_renewing`.

- `cancel_at` (optional, timestamp(UTC) in seconds)
  ##### If the subscription does not have a contract term:[](#if-the-subscription-does-not-have-a-contract-term)
  
  Specifies the date and time when the subscription should be canceled. Do not use this parameter when `end_of_term` is set to `true`.
  
  ##### If the subscription has a contract term:[](#if-the-subscription-has-a-contract-term)
  
  Applicable only when `contract_term_cancel_option` is `specific_date`. Specifies the date and time to cancel the subscription and contract term.
  
  ##### Backdating[](#backdating)
  
  You can set a past date to backdate the cancellation. Backdating is allowed only if the following conditions are met:
  
  -   [Backdating](https://www.chargebee.com/docs/1.0/backdating.html) is enabled for subscription cancellation.
  -   The current date does not exceed the [backdating limit configured in Chargebee Billing](https://www.chargebee.com/docs/1.0/backdating.html#configuring-backdated-subscription-actions-and-invoicing).
  -   The date is on or after the `current_term_start`.
  -   The date is on or after the most recent change involving:
      -   Addition/change/removal of plan or addon item prices.
      -   Addition of charge item prices.
  -   The date is not more than one billing period into the past. For example, if the plan's billing period is two months and today is April 14, `cancel_at` cannot be earlier than February 14.

- `credit_option_for_current_term_charges` (optional, enumerated string)
  ##### If the subscription does not have a contract term:[](#if-the-subscription-does-not-have-a-contract-term)
  
  Specifies how to handle credits for current term charges when canceling immediately (i.e., `cancel_option` is `immediately`). If not specified, the [site-level setting](https://www.chargebee.com/docs/1.0/cancellations.html#configure-subscription-cancellation) is used.
  
  ##### If the subscription has a contract term:[](#if-the-subscription-has-a-contract-term)
  
  Specifies how to handle credits for current term charges when `contract_term_cancel_option` is `terminate_immediately`. If not specified, the [site-level setting](https://www.chargebee.com/docs/1.0/contract-terms.html#configuring-contract-terms) is used.
  Possible enum values:
    - `none`
      No credits notes are created.
    - `prorate`
      Prorated credits are issued.
    - `full`
      Credits are issues for the full value of the current term charges.
    - `consumption_based`

- `unbilled_charges_option` (optional, enumerated string)
  ##### If the subscription does not have a contract term:[](#if-the-subscription-does-not-have-a-contract-term)
  
  Specifies how to handle unbilled charges when canceling immediately (i.e., `cancel_option` is `immediately`). If not specified, the [site-level setting](https://www.chargebee.com/docs/1.0/cancellations.html#configure-subscription-cancellation) is used.
  
  ##### If the subscription has a contract term:[](#if-the-subscription-has-a-contract-term)
  
  Specifies how to handle unbilled charges when `contract_term_cancel_option` is `terminate_immediately`. If not specified, the [site-level setting](https://www.chargebee.com/docs/1.0/contract-terms.html#configuring-contract-terms) is used.
  Possible enum values:
    - `invoice`
      An invoice is generated immediately with the unbilled charges.
    - `delete`
      The unbilled charges are deleted.

- `account_receivables_handling` (optional, enumerated string)
  ##### If the subscription does not have a contract term:[](#if-the-subscription-does-not-have-a-contract-term)
  
  Specifies how to handle past due invoices when canceling immediately (i.e., `cancel_option` is `immediately`). If not specified, the [site-level setting](https://www.chargebee.com/docs/1.0/cancellations.html#configure-subscription-cancellation) is used.
  
  ##### If the subscription has a contract term:[](#if-the-subscription-has-a-contract-term)
  
  Specifies how to handle past due invoices when `contract_term_cancel_option` is `terminate_immediately`. If not specified, the [site-level setting](https://www.chargebee.com/docs/1.0/contract-terms.html#configuring-contract-terms) is used.
  Possible enum values:
    - `no_action`
      No action is taken.
    - `schedule_payment_collection`
      Applies excess payments and refundable credits to past due invoices. If any amount remains and `auto_collection` is `on` , the remaining amount is automatically charged to the available payment method.
    - `write_off`
      Applies excess payments and refundable credits to past due invoices. Any remaining balance is written off.  
      _Note: The credit note for the write-off is not included in the API response._

- `refundable_credits_handling` (optional, enumerated string)
  ##### If the subscription does not have a contract term:[](#if-the-subscription-does-not-have-a-contract-term)
  
  Specifies how to handle refundable credits when canceling immediately (i.e., `cancel_option` is `immediately`). If not specified, the [site-level setting](https://www.chargebee.com/docs/1.0/cancellations.html#configure-subscription-cancellation) is used.
  
  ##### If the subscription has a contract term:[](#if-the-subscription-has-a-contract-term)
  
  Specifies how to handle refundable credits when `contract_term_cancel_option` is `terminate_immediately`. If not specified, the [site-level setting](https://www.chargebee.com/docs/1.0/contract-terms.html#configuring-contract-terms) is used.
  Possible enum values:
    - `no_action`
      No action is taken.
    - `schedule_refund`
      Refunds remaining credits after applying them to any past due invoices.

- `contract_term_cancel_option` (optional, enumerated string)
  Required when the subscription has a contract term. Determines when to cancel the subscription along with the contract term.
  Possible enum values:
    - `terminate_immediately`
      Cancels the subscription and contract term immediately. Sets the contract term's `status` to `terminated` and collects any termination fee, if applicable.  
      To specify the termination fee, include a single object in the `subscription_items` array. If not specified, the [default termination fee](/docs/api/contract_terms) is applied (if configured).
    - `end_of_contract_term`
      Prevents the contract term from renewing and schedules the subscription for cancellation at the end of the contract term.
    - `specific_date`
      Cancels the subscription and contract term on the date specified by `cancel_at`. Sets `action_at_term_end` to `cancel`.  
      **Note**: Contact [Chargebee Support](https://www.chargebee.com/docs/billing/2.0/kb/getting-started/how-to-contact-chargebees-support-team?utm_source=docs_api&utm_medium=content&utm_campaign=support) to enable this option for your [Chargebee site](https://www.chargebee.com/docs/2.0/sites-intro.html).
    - `end_of_subscription_billing_term`
      Cancels the subscription and contract term at the end of the current billing cycle. Sets `action_at_term_end` to `cancel`.  
      **Note**: Contact [Chargebee Support](https://www.chargebee.com/docs/billing/2.0/kb/getting-started/how-to-contact-chargebees-support-team?utm_source=docs_api&utm_medium=content&utm_campaign=support) to enable this option for your [Chargebee site](https://www.chargebee.com/docs/2.0/sites-intro.html).

- `invoice_date` (optional, timestamp(UTC) in seconds)
  The document date displayed on the invoice PDF. The default value is the current date. Provide this value to backdate the invoice. Backdating an invoice is done for reasons such as booking revenue for a previous date or when the subscription is effective as of a past date. Moreover, if `create_pending_invoices` is `true` , and if the site is configured to set invoice dates to date of closing, then upon invoice closure, this date is changed to the invoice closing date. `taxes` and `line_item_taxes` are computed based on the `tax` configuration as of `invoice_date`. When passing this parameter, the following prerequisites must be met:
  
  -   `invoice_date` must be in the past.
  -   `invoice_date` is not more than one calendar month into the past. For example, if today is 13th January, then you cannot pass a value that is earlier than 13th December.
  -   It is not earlier than `cancel_at`. .

- `include_cancellation_day_in_billing` (optional, boolean)
  Determines whether the cancellation day is included in the billing period when prorated credits are issued for the current term charges. Set to `true` to bill the customer for the cancellation day (the term ends on the cancellation date), or `false` to exclude it (the term ends the day before). If not specified, the [site-level setting](https://www.chargebee.com/docs/2.0/cancellations.html#configure-subscription-cancellation) is used. This parameter is applicable only for sites using Day-Based Billing, when:
  
  -   the subscription is `active` or `non_renewing`,
  -   the subscription is canceled immediately, on a backdated date, or on a specific date within the current term, and
  -   `credit_option_for_current_term_charges` is set to `prorate`.
  
  **Note**: Passing this parameter in any other scenario results in a validation error.

- `cancel_reason_code` (optional, string, max chars=100)
  Reason code for canceling the subscription. Must be one from a list of reason codes set in the Chargebee app in **Settings > Configure Chargebee > Reason Codes > Subscriptions > Subscription Cancellation**. Must be passed if set as mandatory in the app. The codes are case-sensitive.

- `subscription_items` (optional, array)
  Parameters for subscription\_items
  - `item_price_id` (optional, string, max chars=100)
    The unique `id` of the charge item\_price that represents the termination fee.
  - `quantity` (optional, integer)
    The quantity associated with the termination fee. Applicable only when the item\_price for the termination charge is quantity-based.
  - `quantity_in_decimal` (optional, string, max chars=33)
    The decimal representation of the quantity of the item purchased. Can be provided for quantity-based item prices and only when [multi-decimal pricing](/docs/api/getting-started) is enabled.
  - `unit_price` (optional, in cents)
    The termination fee. In case it is quantity-based, this is the fee per unit.
  - `unit_price_in_decimal` (optional, string, max chars=39)
    When [price overriding](https://www.chargebee.com/docs/2.0/price-override.html) is enabled for the site, the price or per-unit price of the item can be set here. The [value set for the item price](/docs/api/item_prices/item_price-object#price) is used by default. Provide the value as a decimal string in major units of the currency. Can be provided only when [multi-decimal pricing](/docs/api/getting-started) is enabled.
  - `service_period_days` (optional, integer)
    The service period of the termination fee-expressed in days-starting from the current date.

## Returns

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