# Cancel a subscription

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


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

Cancels the specified subscription.

### Prerequisites & Constraints

-   The subscription [status](/docs/api/subscriptions/subscription-object#status) must not be `cancelled` or `transferred`.
-   If the subscription has a [contract term](/docs/api/contract_terms), specify [`contract_term_cancel_option`](/docs/api/subscriptions/cancel-subscription-for-items#contract_term_cancel_option) instead of [`cancel_option`](/docs/api/subscriptions/cancel-subscription-for-items#cancel_option).

### Impacts

**

Subscription

**

-   The cancellation date-time depends on the provided parameters:
    -   When the subscription does not have a contract term, use `cancel_option`.
    -   When the subscription has a contract term, use `contract_term_cancel_option`.
-   The subscription `status` changes to `cancelled` when canceled.
-   If `cancel_option` is specified as `end_of_term`, or if `contract_term_cancel_option` is specified as `end_of_subscription_billing_term`, the subscription `status` changes to `non_renewing` and the subscription `billing_cycles` becomes `0`.

**

Contract Terms

**

-   The contract term and subscription are canceled together based on the provided `contract_term_cancel_option`.

**

Ramps

**

If [ramps](/docs/api/ramps) are scheduled for the subscription, this operation deletes any ramps that are set to become effective on or after the subscription's cancellation date-time.

### Implementation Notes

Before calling this API, perform the following checks:

-   Confirm that the subscription `status` is not `cancelled` or `transferred`.
-   If the subscription has a contract term, pass `contract_term_cancel_option` instead of `cancel_option`.

### Use Cases

Cancel a subscription with a [contract term](/docs/api/contract_terms)

If the subscription has a contract term, you can use the following parameters with this API:

-   `contract_term_cancel_option`
-   `cancel_at`
-   `credit_option_for_current_term_charges`
-   `unbilled_charges_option`
-   `account_receivables_handling`
-   `refundable_credits_handling`

## Sample Request

### cancels the subscription after the term ends.

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/subscriptions/__test__KyVnZKS5y28bL9/cancel_for_items \
     -u {site_api_key}:\
     -d end_of_term="true"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Subscription.CancelForItems("__test__KyVnZKS5y28bL9")
		.EndOfTerm(true)
		.Request();

Subscription subscription = result.Subscription;
Customer customer = result.Customer;
Card card = result.Card;
Invoice invoice = result.Invoice;
List<UnbilledCharge> unbilledCharges = result.UnbilledCharges;
List<CreditNote> creditNotes = result.CreditNotes;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    subscriptionAction "github.com/chargebee/chargebee-go/v3/actions/subscription"
    "github.com/chargebee/chargebee-go/v3/models/subscription"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := subscriptionAction.CancelForItems("__test__KyVnZKS5y28bL9", &subscription.CancelForItemsRequestParams{
        EndOfTerm : chargebee.Bool(true),
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Subscription := res.Subscription
        Customer := res.Customer
        Card := res.Card
        Invoice := res.Invoice
        UnbilledCharges := res.UnbilledCharges
        CreditNotes := res.CreditNotes
    }
}
```

#### 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.SubscriptionCancelForItemsRequest{
    EndOfTerm : chargebee.Bool(true),
}
  res, err := client.Subscription.CancelForItems("__test__KyVnZKS5y28bL9", req)
      if err != nil {
        fmt.Println(err)
    } else {
        Subscription := res.Subscription
        Customer := res.Customer
        Card := res.Card
        Invoice := res.Invoice
        UnbilledCharges := res.UnbilledCharges
        CreditNotes := res.CreditNotes
    }
}
```

#### Java

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

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = Subscription.cancelForItems("__test__KyVnZKS5y28bL9")
            .endOfTerm(true)
            .request();

        Subscription subscription = result.subscription();
        Customer customer = result.customer();
        Card card = result.card();
        Invoice invoice = result.invoice();
        List<UnbilledCharge> unbilledCharges = result.unbilledCharges();
        List<CreditNote> creditNotes = result.creditNotes();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.card.Card;
import com.chargebee.v4.models.creditNote.CreditNote;
import com.chargebee.v4.models.customer.Customer;
import com.chargebee.v4.models.invoice.Invoice;
import com.chargebee.v4.models.subscription.Subscription;
import com.chargebee.v4.models.subscription.params.SubscriptionCancelForItemsParams;
import com.chargebee.v4.models.subscription.responses.SubscriptionCancelForItemsResponse;
import com.chargebee.v4.models.unbilledCharge.UnbilledCharge;
import java.util.List;

public class SubscriptionCancelForItems {

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

        SubscriptionCancelForItemsParams params = SubscriptionCancelForItemsParams.builder()
            .endOfTerm(true)
            .build();

        SubscriptionCancelForItemsResponse response = client
            .subscriptions()
            .cancelForItems("__test__KyVnZKS5y28bL9", params);

        Subscription subscription = response.getSubscription();
        Customer customer = response.getCustomer();
        Card card = response.getCard();
        Invoice invoice = response.getInvoice();
        List<UnbilledCharge> unbilledCharges = response.getUnbilledCharges();
        List<CreditNote> creditNotes = response.getCreditNotes();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.subscription.cancelForItems("__test__KyVnZKS5y28bL9", {
        end_of_term: true
    });

    console.log(result);
    const subscription = result.subscription;
    const customer = result.customer;
    const card = result.card;
    const invoice = result.invoice;
    const unbilledCharges = result.unbilled_charges;
    const creditNotes = result.credit_notes;
} 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->subscription()->cancelForItems("__test__KyVnZKS5y28bL9", [
    "end_of_term" => true
]);
$subscription = $result->subscription;
$customer = $result->customer;
$card = $result->card;
$invoice = $result->invoice;
$unbilledCharges = $result->unbilled_charges;
$creditNotes = $result->credit_notes;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Subscription.cancel_for_items("__test__KyVnZKS5y28bL9",
    cb_client.Subscription.CancelForItemsParams(
        end_of_term=True
    )
)
subscription = response.subscription
customer = response.customer
card = response.card
invoice = response.invoice
unbilled_charges = response.unbilled_charges
credit_notes = response.credit_notes
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Subscription.cancel_for_items("__test__KyVnZKS5y28bL9",{
  :end_of_term => "true"
})

subscription = result.subscription
customer = result.customer
card = result.card
invoice = result.invoice
unbilled_charges = result.unbilled_charges
credit_notes = result.credit_notes
```

### cancels the subscription immediately with proration credits issued.

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/subscriptions/__test__KyVnZKS5y29FDJ/cancel_for_items \
     -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 = Subscription.CancelForItems("__test__KyVnZKS5y29FDJ")
		.CreditOptionForCurrentTermCharges(CreditOptionForCurrentTermChargesEnum.Prorate)
		.EndOfTerm(false)
		.Request();

Subscription subscription = result.Subscription;
Customer customer = result.Customer;
Card card = result.Card;
Invoice invoice = result.Invoice;
List<UnbilledCharge> unbilledCharges = result.UnbilledCharges;
List<CreditNote> creditNotes = result.CreditNotes;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    subscriptionAction "github.com/chargebee/chargebee-go/v3/actions/subscription"
    "github.com/chargebee/chargebee-go/v3/models/subscription"
    enum "github.com/chargebee/chargebee-go/v3/enum"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := subscriptionAction.CancelForItems("__test__KyVnZKS5y29FDJ", &subscription.CancelForItemsRequestParams{
        CreditOptionForCurrentTermCharges : enum.CreditOptionForCurrentTermChargesProrate,
        EndOfTerm : chargebee.Bool(false),
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Subscription := res.Subscription
        Customer := res.Customer
        Card := res.Card
        Invoice := res.Invoice
        UnbilledCharges := res.UnbilledCharges
        CreditNotes := res.CreditNotes
    }
}
```

#### 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.SubscriptionCancelForItemsRequest{
    CreditOptionForCurrentTermCharges : chargebee.CreditOptionForCurrentTermChargesProrate,
    EndOfTerm : chargebee.Bool(false),
}
  res, err := client.Subscription.CancelForItems("__test__KyVnZKS5y29FDJ", req)
      if err != nil {
        fmt.Println(err)
    } else {
        Subscription := res.Subscription
        Customer := res.Customer
        Card := res.Card
        Invoice := res.Invoice
        UnbilledCharges := res.UnbilledCharges
        CreditNotes := res.CreditNotes
    }
}
```

#### Java

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

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = Subscription.cancelForItems("__test__KyVnZKS5y29FDJ")
            .creditOptionForCurrentTermCharges(CreditOptionForCurrentTermCharges.PRORATE)
            .endOfTerm(false)
            .request();

        Subscription subscription = result.subscription();
        Customer customer = result.customer();
        Card card = result.card();
        Invoice invoice = result.invoice();
        List<UnbilledCharge> unbilledCharges = result.unbilledCharges();
        List<CreditNote> creditNotes = result.creditNotes();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.card.Card;
import com.chargebee.v4.models.creditNote.CreditNote;
import com.chargebee.v4.models.customer.Customer;
import com.chargebee.v4.models.invoice.Invoice;
import com.chargebee.v4.models.subscription.Subscription;
import com.chargebee.v4.models.subscription.params.SubscriptionCancelForItemsParams;
import com.chargebee.v4.models.subscription.responses.SubscriptionCancelForItemsResponse;
import com.chargebee.v4.models.unbilledCharge.UnbilledCharge;
import java.util.List;

public class SubscriptionCancelForItems {

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

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

        SubscriptionCancelForItemsResponse response = client
            .subscriptions()
            .cancelForItems("__test__KyVnZKS5y29FDJ", params);

        Subscription subscription = response.getSubscription();
        Customer customer = response.getCustomer();
        Card card = response.getCard();
        Invoice invoice = response.getInvoice();
        List<UnbilledCharge> unbilledCharges = response.getUnbilledCharges();
        List<CreditNote> creditNotes = response.getCreditNotes();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.subscription.cancelForItems("__test__KyVnZKS5y29FDJ", {
        credit_option_for_current_term_charges: "prorate",
        end_of_term: false
    });

    console.log(result);
    const subscription = result.subscription;
    const customer = result.customer;
    const card = result.card;
    const invoice = result.invoice;
    const unbilledCharges = result.unbilled_charges;
    const creditNotes = result.credit_notes;
} 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->subscription()->cancelForItems("__test__KyVnZKS5y29FDJ", [
    "credit_option_for_current_term_charges" => "prorate",
    "end_of_term" => false
]);
$subscription = $result->subscription;
$customer = $result->customer;
$card = $result->card;
$invoice = $result->invoice;
$unbilledCharges = $result->unbilled_charges;
$creditNotes = $result->credit_notes;
```

#### Python

```python
import chargebee
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Subscription.cancel_for_items("__test__KyVnZKS5y29FDJ",
    cb_client.Subscription.CancelForItemsParams(
        credit_option_for_current_term_charges=chargebee.CreditOptionForCurrentTermCharges.PRORATE,
        end_of_term=False
    )
)
subscription = response.subscription
customer = response.customer
card = response.card
invoice = response.invoice
unbilled_charges = response.unbilled_charges
credit_notes = response.credit_notes
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Subscription.cancel_for_items("__test__KyVnZKS5y29FDJ",{
  :credit_option_for_current_term_charges => "PRORATE",
  :end_of_term => "false"
})

subscription = result.subscription
customer = result.customer
card = result.card
invoice = result.invoice
unbilled_charges = result.unbilled_charges
credit_notes = result.credit_notes
```

### Cancel the subscription immediately and invoice all unbilled charges for it.

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/subscriptions/6o2M5UhE6aJp17C/cancel_for_items \
     -u {site_api_key}:\
     -d cancel_option="IMMEDIATELY" \
     -d unbilled_charges_option="INVOICE" \
     -d cancel_reason_code="Product Unsatisfactory"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Subscription.CancelForItems("6o2M5UhE6aJp17C")
		.CancelOption(CancelOptionEnum.Immediately)
		.UnbilledChargesOption(UnbilledChargesOptionEnum.Invoice)
		.CancelReasonCode("Product Unsatisfactory")
		.Request();

Subscription subscription = result.Subscription;
Customer customer = result.Customer;
Card card = result.Card;
Invoice invoice = result.Invoice;
List<UnbilledCharge> unbilledCharges = result.UnbilledCharges;
List<CreditNote> creditNotes = result.CreditNotes;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    subscriptionAction "github.com/chargebee/chargebee-go/v3/actions/subscription"
    "github.com/chargebee/chargebee-go/v3/models/subscription"
    enum "github.com/chargebee/chargebee-go/v3/enum"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := subscriptionAction.CancelForItems("6o2M5UhE6aJp17C", &subscription.CancelForItemsRequestParams{
        CancelOption : enum.CancelOptionImmediately,
        UnbilledChargesOption : enum.UnbilledChargesOptionInvoice,
        CancelReasonCode : "Product Unsatisfactory",
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Subscription := res.Subscription
        Customer := res.Customer
        Card := res.Card
        Invoice := res.Invoice
        UnbilledCharges := res.UnbilledCharges
        CreditNotes := res.CreditNotes
    }
}
```

#### 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.SubscriptionCancelForItemsRequest{
    CancelOption : chargebee.CancelOptionImmediately,
    UnbilledChargesOption : chargebee.UnbilledChargesOptionInvoice,
    CancelReasonCode : "Product Unsatisfactory",
}
  res, err := client.Subscription.CancelForItems("6o2M5UhE6aJp17C", req)
      if err != nil {
        fmt.Println(err)
    } else {
        Subscription := res.Subscription
        Customer := res.Customer
        Card := res.Card
        Invoice := res.Invoice
        UnbilledCharges := res.UnbilledCharges
        CreditNotes := res.CreditNotes
    }
}
```

#### Java

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

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = Subscription.cancelForItems("6o2M5UhE6aJp17C")
            .cancelOption(CancelOption.IMMEDIATELY)
            .unbilledChargesOption(UnbilledChargesOption.INVOICE)
            .cancelReasonCode("Product Unsatisfactory")
            .request();

        Subscription subscription = result.subscription();
        Customer customer = result.customer();
        Card card = result.card();
        Invoice invoice = result.invoice();
        List<UnbilledCharge> unbilledCharges = result.unbilledCharges();
        List<CreditNote> creditNotes = result.creditNotes();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.card.Card;
import com.chargebee.v4.models.creditNote.CreditNote;
import com.chargebee.v4.models.customer.Customer;
import com.chargebee.v4.models.invoice.Invoice;
import com.chargebee.v4.models.subscription.Subscription;
import com.chargebee.v4.models.subscription.params.SubscriptionCancelForItemsParams;
import com.chargebee.v4.models.subscription.responses.SubscriptionCancelForItemsResponse;
import com.chargebee.v4.models.unbilledCharge.UnbilledCharge;
import java.util.List;

public class SubscriptionCancelForItems {

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

        SubscriptionCancelForItemsParams params = SubscriptionCancelForItemsParams.builder()
            .cancelOption(SubscriptionCancelForItemsParams.CancelOption.IMMEDIATELY)
            .unbilledChargesOption(SubscriptionCancelForItemsParams.UnbilledChargesOption.INVOICE)
            .cancelReasonCode("Product Unsatisfactory")
            .build();

        SubscriptionCancelForItemsResponse response = client
            .subscriptions()
            .cancelForItems("6o2M5UhE6aJp17C", params);

        Subscription subscription = response.getSubscription();
        Customer customer = response.getCustomer();
        Card card = response.getCard();
        Invoice invoice = response.getInvoice();
        List<UnbilledCharge> unbilledCharges = response.getUnbilledCharges();
        List<CreditNote> creditNotes = response.getCreditNotes();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.subscription.cancelForItems("6o2M5UhE6aJp17C", {
        cancel_option: "immediately",
        unbilled_charges_option: "invoice",
        cancel_reason_code: "Product Unsatisfactory"
    });

    console.log(result);
    const subscription = result.subscription;
    const customer = result.customer;
    const card = result.card;
    const invoice = result.invoice;
    const unbilledCharges = result.unbilled_charges;
    const creditNotes = result.credit_notes;
} 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->subscription()->cancelForItems("6o2M5UhE6aJp17C", [
    "cancel_option" => "immediately",
    "unbilled_charges_option" => "invoice",
    "cancel_reason_code" => "Product Unsatisfactory"
]);
$subscription = $result->subscription;
$customer = $result->customer;
$card = $result->card;
$invoice = $result->invoice;
$unbilledCharges = $result->unbilled_charges;
$creditNotes = $result->credit_notes;
```

#### Python

```python
import chargebee
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Subscription.cancel_for_items("6o2M5UhE6aJp17C",
    cb_client.Subscription.CancelForItemsParams(
        cancel_option=chargebee.CancelOption.IMMEDIATELY,
        unbilled_charges_option=chargebee.UnbilledChargesOption.INVOICE,
        cancel_reason_code="Product Unsatisfactory"
    )
)
subscription = response.subscription
customer = response.customer
card = response.card
invoice = response.invoice
unbilled_charges = response.unbilled_charges
credit_notes = response.credit_notes
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Subscription.cancel_for_items("6o2M5UhE6aJp17C",{
  :cancel_option => "IMMEDIATELY",
  :unbilled_charges_option => "INVOICE",
  :cancel_reason_code => "Product Unsatisfactory"
})

subscription = result.subscription
customer = result.customer
card = result.card
invoice = result.invoice
unbilled_charges = result.unbilled_charges
credit_notes = result.credit_notes
```

### Cancel a subscription on a specific date, create credits for the unused period, and invoice any unbilled charges.

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/subscriptions/6ohkiUdK5kM410A/cancel_for_items \
     -u {site_api_key}:\
     -d cancel_option="SPECIFIC_DATE" \
     -d cancel_at=1758931200 \
     -d credit_option_for_current_term_charges="PRORATE" \
     -d unbilled_charges_option="INVOICE"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Subscription.CancelForItems("6ohkiUdK5kM410A")
		.CancelOption(CancelOptionEnum.SpecificDate)
		.CancelAt(1758931200)
		.CreditOptionForCurrentTermCharges(CreditOptionForCurrentTermChargesEnum.Prorate)
		.UnbilledChargesOption(UnbilledChargesOptionEnum.Invoice)
		.Request();

Subscription subscription = result.Subscription;
Customer customer = result.Customer;
Card card = result.Card;
Invoice invoice = result.Invoice;
List<UnbilledCharge> unbilledCharges = result.UnbilledCharges;
List<CreditNote> creditNotes = result.CreditNotes;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    subscriptionAction "github.com/chargebee/chargebee-go/v3/actions/subscription"
    "github.com/chargebee/chargebee-go/v3/models/subscription"
    enum "github.com/chargebee/chargebee-go/v3/enum"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := subscriptionAction.CancelForItems("6ohkiUdK5kM410A", &subscription.CancelForItemsRequestParams{
        CancelOption : enum.CancelOptionSpecificDate,
        CancelAt : chargebee.Int64(1758931200),
        CreditOptionForCurrentTermCharges : enum.CreditOptionForCurrentTermChargesProrate,
        UnbilledChargesOption : enum.UnbilledChargesOptionInvoice,
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Subscription := res.Subscription
        Customer := res.Customer
        Card := res.Card
        Invoice := res.Invoice
        UnbilledCharges := res.UnbilledCharges
        CreditNotes := res.CreditNotes
    }
}
```

#### 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.SubscriptionCancelForItemsRequest{
    CancelOption : chargebee.CancelOptionSpecificDate,
    CancelAt : chargebee.Int64(1758931200),
    CreditOptionForCurrentTermCharges : chargebee.CreditOptionForCurrentTermChargesProrate,
    UnbilledChargesOption : chargebee.UnbilledChargesOptionInvoice,
}
  res, err := client.Subscription.CancelForItems("6ohkiUdK5kM410A", req)
      if err != nil {
        fmt.Println(err)
    } else {
        Subscription := res.Subscription
        Customer := res.Customer
        Card := res.Card
        Invoice := res.Invoice
        UnbilledCharges := res.UnbilledCharges
        CreditNotes := res.CreditNotes
    }
}
```

#### Java

```java
import com.chargebee.*;
import com.chargebee.ListResult;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;
import java.io.IOException;
import java.util.List;
import java.sql.Timestamp;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = Subscription.cancelForItems("6ohkiUdK5kM410A")
            .cancelOption(CancelOption.SPECIFIC_DATE)
            .cancelAt(new Timestamp(1758931200L * 1000))
            .creditOptionForCurrentTermCharges(CreditOptionForCurrentTermCharges.PRORATE)
            .unbilledChargesOption(UnbilledChargesOption.INVOICE)
            .request();

        Subscription subscription = result.subscription();
        Customer customer = result.customer();
        Card card = result.card();
        Invoice invoice = result.invoice();
        List<UnbilledCharge> unbilledCharges = result.unbilledCharges();
        List<CreditNote> creditNotes = result.creditNotes();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.card.Card;
import com.chargebee.v4.models.creditNote.CreditNote;
import com.chargebee.v4.models.customer.Customer;
import com.chargebee.v4.models.invoice.Invoice;
import com.chargebee.v4.models.subscription.Subscription;
import com.chargebee.v4.models.subscription.params.SubscriptionCancelForItemsParams;
import com.chargebee.v4.models.subscription.responses.SubscriptionCancelForItemsResponse;
import com.chargebee.v4.models.unbilledCharge.UnbilledCharge;
import java.sql.Timestamp;
import java.util.List;

public class SubscriptionCancelForItems {

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

        SubscriptionCancelForItemsParams params = SubscriptionCancelForItemsParams.builder()
            .cancelOption(SubscriptionCancelForItemsParams.CancelOption.SPECIFIC_DATE)
            .cancelAt(new Timestamp(1758931200L * 1000))
            .creditOptionForCurrentTermCharges(SubscriptionCancelForItemsParams.CreditOptionForCurrentTermCharges.PRORATE)
            .unbilledChargesOption(SubscriptionCancelForItemsParams.UnbilledChargesOption.INVOICE)
            .build();

        SubscriptionCancelForItemsResponse response = client
            .subscriptions()
            .cancelForItems("6ohkiUdK5kM410A", params);

        Subscription subscription = response.getSubscription();
        Customer customer = response.getCustomer();
        Card card = response.getCard();
        Invoice invoice = response.getInvoice();
        List<UnbilledCharge> unbilledCharges = response.getUnbilledCharges();
        List<CreditNote> creditNotes = response.getCreditNotes();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.subscription.cancelForItems("6ohkiUdK5kM410A", {
        cancel_option: "specific_date",
        cancel_at: 1758931200,
        credit_option_for_current_term_charges: "prorate",
        unbilled_charges_option: "invoice"
    });

    console.log(result);
    const subscription = result.subscription;
    const customer = result.customer;
    const card = result.card;
    const invoice = result.invoice;
    const unbilledCharges = result.unbilled_charges;
    const creditNotes = result.credit_notes;
} 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->subscription()->cancelForItems("6ohkiUdK5kM410A", [
    "cancel_option" => "specific_date",
    "cancel_at" => 1758931200,
    "credit_option_for_current_term_charges" => "prorate",
    "unbilled_charges_option" => "invoice"
]);
$subscription = $result->subscription;
$customer = $result->customer;
$card = $result->card;
$invoice = $result->invoice;
$unbilledCharges = $result->unbilled_charges;
$creditNotes = $result->credit_notes;
```

#### Python

```python
import chargebee
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Subscription.cancel_for_items("6ohkiUdK5kM410A",
    cb_client.Subscription.CancelForItemsParams(
        cancel_option=chargebee.CancelOption.SPECIFIC_DATE,
        cancel_at=1758931200,
        credit_option_for_current_term_charges=chargebee.CreditOptionForCurrentTermCharges.PRORATE,
        unbilled_charges_option=chargebee.UnbilledChargesOption.INVOICE
    )
)
subscription = response.subscription
customer = response.customer
card = response.card
invoice = response.invoice
unbilled_charges = response.unbilled_charges
credit_notes = response.credit_notes
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Subscription.cancel_for_items("6ohkiUdK5kM410A",{
  :cancel_option => "SPECIFIC_DATE",
  :cancel_at => 1758931200,
  :credit_option_for_current_term_charges => "PRORATE",
  :unbilled_charges_option => "INVOICE"
})

subscription = result.subscription
customer = result.customer
card = result.card
invoice = result.invoice
unbilled_charges = result.unbilled_charges
credit_notes = result.credit_notes
```

### Schedule the subscription to cancel at the end of the contract term.

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/subscriptions/6ohkiUdGUwfmK2/cancel_for_items \
     -u {site_api_key}:\
     -d contract_term_cancel_option="END_OF_CONTRACT_TERM" \
     -d cancel_reason_code="Other"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Subscription.CancelForItems("6ohkiUdGUwfmK2")
		.ContractTermCancelOption(ContractTermCancelOptionEnum.EndOfContractTerm)
		.CancelReasonCode("Other")
		.Request();

Subscription subscription = result.Subscription;
Customer customer = result.Customer;
Card card = result.Card;
Invoice invoice = result.Invoice;
List<UnbilledCharge> unbilledCharges = result.UnbilledCharges;
List<CreditNote> creditNotes = result.CreditNotes;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    subscriptionAction "github.com/chargebee/chargebee-go/v3/actions/subscription"
    "github.com/chargebee/chargebee-go/v3/models/subscription"
    enum "github.com/chargebee/chargebee-go/v3/enum"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := subscriptionAction.CancelForItems("6ohkiUdGUwfmK2", &subscription.CancelForItemsRequestParams{
        ContractTermCancelOption : enum.ContractTermCancelOptionEndOfContractTerm,
        CancelReasonCode : "Other",
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Subscription := res.Subscription
        Customer := res.Customer
        Card := res.Card
        Invoice := res.Invoice
        UnbilledCharges := res.UnbilledCharges
        CreditNotes := res.CreditNotes
    }
}
```

#### 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.SubscriptionCancelForItemsRequest{
    ContractTermCancelOption : chargebee.ContractTermCancelOptionEndOfContractTerm,
    CancelReasonCode : "Other",
}
  res, err := client.Subscription.CancelForItems("6ohkiUdGUwfmK2", req)
      if err != nil {
        fmt.Println(err)
    } else {
        Subscription := res.Subscription
        Customer := res.Customer
        Card := res.Card
        Invoice := res.Invoice
        UnbilledCharges := res.UnbilledCharges
        CreditNotes := res.CreditNotes
    }
}
```

#### Java

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

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = Subscription.cancelForItems("6ohkiUdGUwfmK2")
            .contractTermCancelOption(ContractTermCancelOption.END_OF_CONTRACT_TERM)
            .cancelReasonCode("Other")
            .request();

        Subscription subscription = result.subscription();
        Customer customer = result.customer();
        Card card = result.card();
        Invoice invoice = result.invoice();
        List<UnbilledCharge> unbilledCharges = result.unbilledCharges();
        List<CreditNote> creditNotes = result.creditNotes();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.card.Card;
import com.chargebee.v4.models.creditNote.CreditNote;
import com.chargebee.v4.models.customer.Customer;
import com.chargebee.v4.models.invoice.Invoice;
import com.chargebee.v4.models.subscription.Subscription;
import com.chargebee.v4.models.subscription.params.SubscriptionCancelForItemsParams;
import com.chargebee.v4.models.subscription.responses.SubscriptionCancelForItemsResponse;
import com.chargebee.v4.models.unbilledCharge.UnbilledCharge;
import java.util.List;

public class SubscriptionCancelForItems {

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

        SubscriptionCancelForItemsParams params = SubscriptionCancelForItemsParams.builder()
            .contractTermCancelOption(SubscriptionCancelForItemsParams.ContractTermCancelOption.END_OF_CONTRACT_TERM)
            .cancelReasonCode("Other")
            .build();

        SubscriptionCancelForItemsResponse response = client
            .subscriptions()
            .cancelForItems("6ohkiUdGUwfmK2", params);

        Subscription subscription = response.getSubscription();
        Customer customer = response.getCustomer();
        Card card = response.getCard();
        Invoice invoice = response.getInvoice();
        List<UnbilledCharge> unbilledCharges = response.getUnbilledCharges();
        List<CreditNote> creditNotes = response.getCreditNotes();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.subscription.cancelForItems("6ohkiUdGUwfmK2", {
        contract_term_cancel_option: "end_of_contract_term",
        cancel_reason_code: "Other"
    });

    console.log(result);
    const subscription = result.subscription;
    const customer = result.customer;
    const card = result.card;
    const invoice = result.invoice;
    const unbilledCharges = result.unbilled_charges;
    const creditNotes = result.credit_notes;
} 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->subscription()->cancelForItems("6ohkiUdGUwfmK2", [
    "contract_term_cancel_option" => "end_of_contract_term",
    "cancel_reason_code" => "Other"
]);
$subscription = $result->subscription;
$customer = $result->customer;
$card = $result->card;
$invoice = $result->invoice;
$unbilledCharges = $result->unbilled_charges;
$creditNotes = $result->credit_notes;
```

#### Python

```python
import chargebee
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Subscription.cancel_for_items("6ohkiUdGUwfmK2",
    cb_client.Subscription.CancelForItemsParams(
        contract_term_cancel_option=chargebee.ContractTermCancelOption.END_OF_CONTRACT_TERM,
        cancel_reason_code="Other"
    )
)
subscription = response.subscription
customer = response.customer
card = response.card
invoice = response.invoice
unbilled_charges = response.unbilled_charges
credit_notes = response.credit_notes
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Subscription.cancel_for_items("6ohkiUdGUwfmK2",{
  :contract_term_cancel_option => "END_OF_CONTRACT_TERM",
  :cancel_reason_code => "Other"
})

subscription = result.subscription
customer = result.customer
card = result.card
invoice = result.invoice
unbilled_charges = result.unbilled_charges
credit_notes = result.credit_notes
```

## Sample Response

```json
{
  "customer": {
    "allow_direct_debit": false,
    "auto_collection": "off",
    "card_status": "no_card",
    "created_at": 1612890907,
    "deleted": false,
    "excess_payments": 0,
    "first_name": "John",
    "id": "__test__8asukSOXdsPqLk",
    "last_name": "Doe",
    "net_term_days": 0,
    "object": "customer",
    "pii_cleared": "active",
    "preferred_currency_code": "USD",
    "promotional_credits": 0,
    "refundable_credits": 0,
    "resource_version": 1612890907000,
    "taxability": "taxable",
    "unbilled_charges": 0,
    "updated_at": 1612890907
  },
  "subscription": {
    "activated_at": 1612890907,
    "billing_period": 1,
    "billing_period_unit": "month",
    "cancelled_at": 1615310107,
    "created_at": 1612890907,
    "currency_code": "USD",
    "current_term_end": 1615310107,
    "current_term_start": 1612890907,
    "customer_id": "__test__8asukSOXdsPqLk",
    "deleted": false,
    "due_invoices_count": 1,
    "due_since": 1612890907,
    "has_scheduled_changes": false,
    "id": "__test__8asukSOXdsV6Ln",
    "mrr": 0,
    "object": "subscription",
    "remaining_billing_cycles": 0,
    "resource_version": 1612890908000,
    "started_at": 1612890907,
    "status": "non_renewing",
    "subscription_items": [
      {
        "amount": 1000,
        "billing_cycles": 0,
        "free_quantity": 0,
        "item_price_id": "basic-USD",
        "item_type": "plan",
        "object": "subscription_item",
        "quantity": 1,
        "unit_price": 1000
      },
      {..}
    ],
    "total_dues": 1100,
    "updated_at": 1612890908
  }
}
```

## URL Format

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

## 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.

- `decommissioned` (optional, boolean, default=false)
  Indicates whether the subscription should be decommissioned when it is canceled. If set to `true` all subscription operations will be disabled except deletion.
  
  **Note**: Decommission operation is irreversible. Once set to `true` it cannot be updated to `false` and thus subscription will remain decommissioned permanently.

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

- `subscription` (Subscription object)
  Resource object representing subscription

- `customer` (Customer object)
  Resource object representing customer

- `card` (Card object)
  Resource object representing card

- `invoice` (Invoice object)
  Resource object representing invoice

- `unbilled_charges` (optional)
  Resource object representing unbilled\_charge

- `credit_notes` (optional)
  Resource object representing credit\_note
