# Add charge at term end

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


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

Adds a one time charge to the subscription which will be added to the invoice generated at the end of the current term. If there are any applicable coupons in the subscription, an appropriate discount will be applied.

To collect a charge immediately, [use this API](/docs/api/v2/pcv-1/invoices/create-invoice-for-a-one-time-charge).

If any subscription changes happen before the end of the current term, these charges will be collected along with it.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/subscriptions/__test__8asukSOXds3JLW/add_charge_at_term_end \
     -u {site_api_key}:\
     -d amount=300 \
     -d description="Service Charge"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Subscription.AddChargeAtTermEnd("__test__8asukSOXds3JLW")
		.Amount(300)
		.Description("Service Charge")
		.Request();

Estimate estimate = result.Estimate;
```

#### 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.AddChargeAtTermEnd("__test__8asukSOXds3JLW", &subscription.AddChargeAtTermEndRequestParams{
        Amount : chargebee.Int64(300),
        Description : "Service Charge",
    }).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.SubscriptionAddChargeAtTermEndRequest{
    Amount : chargebee.Int64(300),
    Description : "Service Charge",
}
  res, err := client.Subscription.AddChargeAtTermEnd("__test__8asukSOXds3JLW", 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 = Subscription.addChargeAtTermEnd("__test__8asukSOXds3JLW")
            .amount(300L)
            .description("Service Charge")
            .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.subscription.params.SubscriptionAddChargeAtTermEndParams;
import com.chargebee.v4.models.subscription.responses.SubscriptionAddChargeAtTermEndResponse;

public class SubscriptionAddChargeAtTermEnd {

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

        SubscriptionAddChargeAtTermEndParams params = SubscriptionAddChargeAtTermEndParams.builder()
            .amount(300L)
            .description("Service Charge")
            .build();

        SubscriptionAddChargeAtTermEndResponse response = client
            .subscriptions()
            .addChargeAtTermEnd("__test__8asukSOXds3JLW", 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.subscription.addChargeAtTermEnd("__test__8asukSOXds3JLW", {
        amount: 300,
        description: "Service Charge"
    });

    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->subscription()->addChargeAtTermEnd("__test__8asukSOXds3JLW", [
    "amount" => 300,
    "description" => "Service Charge"
]);
$estimate = $result->estimate;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Subscription.add_charge_at_term_end("__test__8asukSOXds3JLW",
    cb_client.Subscription.AddChargeAtTermEndParams(
        amount=300,
        description="Service Charge"
    )
)
estimate = response.estimate
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Subscription.add_charge_at_term_end("__test__8asukSOXds3JLW",{
  :amount => 300,
  :description => "Service Charge"
})

estimate = result.estimate
```

## Sample Response

```json
{
  "estimate": {
    "created_at": 1612890907,
    "invoice_estimate": {
      "amount_due": 1400,
      "amount_paid": 0,
      "credits_applied": 0,
      "currency_code": "USD",
      "customer_id": "__test__8asukSOXdrvyLT",
      "line_item_discounts": {},
      "line_item_taxes": {},
      "line_items": [
        {
          "amount": 300,
          "customer_id": "__test__8asukSOXdrvyLT",
          "date_from": 1612890906,
          "date_to": 1612890906,
          "description": "Service Charge",
          "discount_amount": 0,
          "entity_type": "adhoc",
          "id": "li___test__8asukSOXdsHoLe",
          "is_taxed": false,
          "item_level_discount_amount": 0,
          "object": "line_item",
          "pricing_model": "flat_fee",
          "quantity": 1,
          "subscription_id": "__test__8asukSOXds3JLW",
          "tax_amount": 0,
          "unit_amount": 300
        },
        {..}
      ],
      "object": "invoice_estimate",
      "price_type": "tax_exclusive",
      "recurring": true,
      "round_off_amount": 0,
      "sub_total": 1400,
      "taxes": {},
      "total": 1400
    },
    "object": "estimate",
    "subscription_estimate": {
      "currency_code": "USD",
      "id": "__test__8asukSOXds3JLW",
      "next_billing_at": 1615310105,
      "object": "subscription_estimate",
      "status": "active"
    }
  }
}
```

## URL Format

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

## Input Parameters

- `amount` (optional, in cents, min=1)
  The amount to be charged. The unit depends on the [type of currency](/docs/api/getting-started) .

- `description` (required, string, max chars=250)
  Description for this charge.

- `amount_in_decimal` (optional, string, max chars=39)
  The decimal representation of the amount for the [one-time charge](https://www.chargebee.com/docs/charges.html#one-time-charges ). Provide the value in major units of the currency. Can be provided only when [multi-decimal pricing](/docs/api/currencies) is enabled.

- `avalara_sale_type` (optional, enumerated string)
  Indicates the type of sale carried out. This is applicable only if you use [Chargebee's AvaTax for Communications](https://www.chargebee.com/docs/avatax-for-communication.html) integration.
  Possible enum values:
    - `wholesale`
      Transaction is a sale to another company that will resell your product or service to another consumer
    - `retail`
      Transaction is a sale to an end user
    - `consumed`
      Transaction is for an item that is consumed directly
    - `vendor_use`
      Transaction is for an item that is subject to vendor use tax

- `avalara_transaction_type` (optional, integer)
  Indicates the type of product to be taxed. Values for this field can be taken from Avalara. This is applicable only if you use [Chargebee's AvaTax for Communications](https://www.chargebee.com/docs/avatax-for-communication.html) integration.

- `avalara_service_type` (optional, integer)
  Indicates the type of service for the product to be taxed. Values for this field can be taken from Avalara. This is applicable only if you use [Chargebee's AvaTax for Communications](https://www.chargebee.com/docs/avatax-for-communication.html) integration.

- `date_from` (optional, timestamp(UTC) in seconds)
  The time when the service period for the charge starts.

- `date_to` (optional, timestamp(UTC) in seconds)
  The time when the service period for the charge ends.

## Returns

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