# Cancel a subscription

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


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

Cancelling a subscription will move the subscription from its current state to **Cancelled**, and will stop all recurring actions.

You could schedule the cancellation by passing **end\_of\_term** parameter as **true**. If scheduled, the subscription status will be set to **non\_renewing** if it is in **active** state, until the end of term, and then **cancelled**. A subscription's state will not change if it is in **in\_trial** state. However, cancellation will be scheduled at the end of the trial.

#### CREDIT OPTION[](#credit-option)

On subscription cancellation, credits can be issued against current term charges of the subscription by using **credit\_option\_for\_current\_term\_charges**. You can choose to either provide no credits, prorate credits for the unused period or issue full credits for the current term charges.

#### UNBILLED CHARGES[](#unbilled-charges)

Any unbilled charges present in the subscription can either be invoiced or deleted by specifying **unbilled\_charges\_option**. Note that automatic charge will be attempted on the payment method available if the customer has enabled auto-collection. If not, the invoice will be closed as unpaid.

#### ACCOUNT RECEIVABLES[](#account-receivables)

Specifying **account\_receivables\_handling** allows you to close invoices of the subscription which have amounts due. The invoices are chosen for payment collection or for writing off the due amount after applying the available credits and excess payments.

If specified as **schedule\_payment\_collection**, payment collection for the amount due of past invoices will be attempted. The payment method available will be charged if auto-collection is enabled for the customer, and appropriate payment collection(payment succeeded or payment failed) events will be triggered. If the payment collection fails, no further retries will be made on the invoices. **Note:** If the invoices of the subscription are consolidated, and any of the subscriptions in the consolidated invoice are cancelled, these invoices will not be selected for collection.

If specified as **write\_off**, the amount due of past invoices will be written-off. **Note:** If the invoices of the subscription are consolidated, and any of the subscriptions in the consolidated invoice are still active(future, in-trial, active, and non-renewing), these invoices will not be selected for the write-off operation.

#### ACCOUNT PAYABLES[](#account-payables)

Specifying refundable\_credits\_handling allows you to provide refunds for refundable credits remaining, after they are applied to a subscription's due invoices. The refund initiated will be asynchronous and the payment refunded event will be triggered on refund success. **Note:** Consolidated credit notes of the subscription will not be selected for refund.

#### Contract terms[](#contract-terms)

If the subscription has [contract terms](/docs/api/contract_terms), it can only be canceled by terminating the contract using the `contract_term_cancel_option`. The contract term and the subscription are canceled together.

##### Contract terms parameters[](#contract-terms-parameters)

-   `[contract_term_cancel_option](/docs/api/v2/pcv-1/subscriptions/cancel-a-subscription#contract_term_cancel_option)`
-   `[cancel_at](/docs/api/v2/pcv-1/subscriptions/cancel-a-subscription#cancel_at)`
-   `[credit_option_for_current_term_charges](/docs/api/v2/pcv-1/subscriptions/cancel-a-subscription#credit_option_for_current_term_charges)`
-   `[unbilled_charges_option](/docs/api/v2/pcv-1/subscriptions/cancel-a-subscription#unbilled_charges_option)`
-   `[account_receivables_handling](/docs/api/v2/pcv-1/subscriptions/cancel-a-subscription#account_receivables_handling)`
-   `[refundable_credits_handling](/docs/api/v2/pcv-1/subscriptions/cancel-a-subscription#refundable_credits_handling)`

Advance charges, if any, will be refunded as credits.

## Sample Request

### cancels the subscription after the term ends.

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/subscriptions/__test__KyVnHhSBWkekU2RC/cancel \
     -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.Cancel("__test__KyVnHhSBWkekU2RC")
		.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.Cancel("__test__KyVnHhSBWkekU2RC", &subscription.CancelRequestParams{
        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.SubscriptionCancelRequest{
    EndOfTerm : chargebee.Bool(true),
}
  res, err := client.Subscription.Cancel("__test__KyVnHhSBWkekU2RC", 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.cancel("__test__KyVnHhSBWkekU2RC")
            .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.SubscriptionCancelParams;
import com.chargebee.v4.models.subscription.responses.SubscriptionCancelResponse;
import com.chargebee.v4.models.unbilledCharge.UnbilledCharge;
import java.util.List;

public class SubscriptionCancel {

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

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

        SubscriptionCancelResponse response = client
            .subscriptions()
            .cancel("__test__KyVnHhSBWkekU2RC", 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.cancel("__test__KyVnHhSBWkekU2RC", {
        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()->cancel("__test__KyVnHhSBWkekU2RC", [
    "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("__test__KyVnHhSBWkekU2RC",
    cb_client.Subscription.CancelParams(
        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("__test__KyVnHhSBWkekU2RC",{
  :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__KyVnHhSBWkf9f2RK/cancel \
     -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.Cancel("__test__KyVnHhSBWkf9f2RK")
		.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.Cancel("__test__KyVnHhSBWkf9f2RK", &subscription.CancelRequestParams{
        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.SubscriptionCancelRequest{
    CreditOptionForCurrentTermCharges : chargebee.CreditOptionForCurrentTermChargesProrate,
    EndOfTerm : chargebee.Bool(false),
}
  res, err := client.Subscription.Cancel("__test__KyVnHhSBWkf9f2RK", 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.cancel("__test__KyVnHhSBWkf9f2RK")
            .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.SubscriptionCancelParams;
import com.chargebee.v4.models.subscription.responses.SubscriptionCancelResponse;
import com.chargebee.v4.models.unbilledCharge.UnbilledCharge;
import java.util.List;

public class SubscriptionCancel {

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

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

        SubscriptionCancelResponse response = client
            .subscriptions()
            .cancel("__test__KyVnHhSBWkf9f2RK", 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.cancel("__test__KyVnHhSBWkf9f2RK", {
        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()->cancel("__test__KyVnHhSBWkf9f2RK", [
    "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("__test__KyVnHhSBWkf9f2RK",
    cb_client.Subscription.CancelParams(
        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("__test__KyVnHhSBWkf9f2RK",{
  :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
```

## Sample Response

```json
{
  "customer": {
    "allow_direct_debit": false,
    "auto_collection": "off",
    "card_status": "no_card",
    "created_at": 1517505620,
    "deleted": false,
    "excess_payments": 0,
    "id": "__test__KyVnHhSBWkekU2RC",
    "net_term_days": 0,
    "object": "customer",
    "pii_cleared": "active",
    "preferred_currency_code": "USD",
    "promotional_credits": 0,
    "refundable_credits": 0,
    "resource_version": 1517505620000,
    "taxability": "taxable",
    "unbilled_charges": 0,
    "updated_at": 1517505620
  },
  "subscription": {
    "activated_at": 1517505620,
    "billing_period": 1,
    "billing_period_unit": "month",
    "cancelled_at": 1519924820,
    "created_at": 1517505620,
    "currency_code": "USD",
    "current_term_end": 1519924820,
    "current_term_start": 1517505620,
    "customer_id": "__test__KyVnHhSBWkekU2RC",
    "deleted": false,
    "due_invoices_count": 1,
    "due_since": 1517505620,
    "has_scheduled_changes": false,
    "id": "__test__KyVnHhSBWkekU2RC",
    "mrr": 0,
    "object": "subscription",
    "plan_amount": 895,
    "plan_free_quantity": 0,
    "plan_id": "no_trial",
    "plan_quantity": 1,
    "plan_unit_price": 895,
    "remaining_billing_cycles": 0,
    "resource_version": 1517505620000,
    "started_at": 1517505620,
    "status": "non_renewing",
    "total_dues": 895,
    "updated_at": 1517505620
  }
}
```

## URL Format

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

## 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/1.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/1.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`. .

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

- `event_based_addons` (optional, array)
  Parameters for event\_based\_addons
  - `id` (optional, string, max chars=100)
    The unique `id` of the event-based addon that represents the termination fee.
  - `quantity` (optional, integer)
    The quantity associated with the termination fee. Applicable only when the addon for the termination charge is quantity-based.
  - `unit_price` (optional, in cents)
    The termination fee. In case it is quantity-based, this is the fee per unit.
  - `service_period_in_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
