# Charge future renewals

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


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

Creates a single [advance invoice](/docs/api/invoices/invoice-object#invoice_has_advance_charges) or an [advance invoicing schedule](/docs/api/advance_invoice_schedules#advance_invoice_schedule) for a [subscription](/docs/api/subscriptions).

Use this operation to bill future renewals in advance, enabling customers to prepay for upcoming billing cycles.

### Prerequisites & Constraints

-   The [Advance Invoicing](https://www.chargebee.com/docs/billing/2.0/invoices-credit-notes-and-quotes/advance-invoices) feature must be enabled on the site.
-   The subscription [`status`](/docs/api/subscriptions/subscription-object#subscription_status) must be `active`.
-   The subscription must not be scheduled for [cancellation](/docs/api/subscriptions/cancel-subscription-for-items) or [pause](/docs/api/subscriptions/pause-a-subscription) within the terms being invoiced.
-   The subscription must have at least one item price belonging to a [non-`metered` item](/docs/api/items/item-object#item_metered).
-   The [Multi-Frequency Billing](https://apidocs.chargebee.com/docs/api/subscriptions?lang=curl#subscription-billing-frequencies) feature must be disabled for the site.
-   The subscription must not be a [gift](/docs/api/gifts) subscription. You can check this by [listing all gifts](/docs/api/gifts/list-gifts) setting the filter parameter `gift_receiver[customer_id][is]` to the `customer_id` of the subscription and checking if one of the returned objects has [`gift_receiver.subscription_id`](/docs/api/gifts/gift-object#gift_gift_receiver) matching the `id` of the subscription.
-   For subscriptions with [ramps](/docs/api/ramps), the following constraints apply:
    -   The subscription must not have more than 12 scheduled ramps in the invoicing period specified by this API.
    -   For the invoicing period specified by this API, the subscription must not have any ramps scheduled for the middle of the subscription term.
-   The subscription must not be in its final contract term. i.e. the subscription must not have [`contract_term.action_at_term_end`](/docs/api/subscriptions/subscription-object#contract_term) set to `cancel`.
-   The subscription must not have [addons in trial](https://www.chargebee.com/docs/billing/2.0/subscriptions/addons-trial).

### Impacts

**Subscription**

-   The subscription [`next_billing_at`](/docs/api/subscriptions/subscription-object#subscription_next_billing_at) is updated to reflect the end of the last term being invoiced. If all remaining billing cycles are invoiced, `next_billing_at` is set to `null`.
-   The subscription's [`remaining_billing_cycles`](/docs/api/subscriptions/subscription-object#subscription_remaining_billing_cycles) is reduced by the number of terms charged.

**Invoice**

-   When `schedule_type` is `immediate` and `invoice_immediately = true`:
    -   a single [advance invoice](/docs/api/invoices/invoice-object#invoice_has_advance_charges) is created covering the specified number of future billing cycles.
    -   the invoice includes line items for all non-metered items, applicable coupons, taxes, and credits.
    -   any changes scheduled in the current term or at the end of the current term for the subscription are automatically taken into account while generating the advance invoice.
    -   if `auto_collection` is `on` for the subscription, the payment for the invoice is collected immediately using the [payment source](/docs/api/subscriptions/subscription-object#subscription_payment_source_id) associated with the subscription.

**Unbilled Charges**

-   When `schedule_type` is `immediate` and `invoice_immediately` is `false`: The charges are added to [`unbilled_charges`](/docs/api/unbilled_charges) for the subscription and invoiced on the next renewal.

**Advance Invoice Schedule**

-   When `schedule_type` is `specific_dates` or `fixed_intervals`:
    -   an [advance invoice schedule](/docs/api/advance_invoice_schedules) is created. The schedule defines when advance invoices will be generated in the future.
    -   any changes scheduled for the subscription are automatically taken into account while generating the advance invoice.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/subscriptions/__test__8asukSOXdtV2MX/charge_future_renewals \
     -u {site_api_key}:\
     -d terms_to_charge=5
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Subscription.ChargeFutureRenewals("__test__8asukSOXdtV2MX")
		.TermsToCharge(5)
		.Request();

Subscription subscription = result.Subscription;
Customer customer = result.Customer;
Card card = result.Card;
Invoice invoice = result.Invoice;
List<AdvanceInvoiceSchedule> advanceInvoiceSchedules = result.AdvanceInvoiceSchedules;
```

#### 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.ChargeFutureRenewals("__test__8asukSOXdtV2MX", &subscription.ChargeFutureRenewalsRequestParams{
        TermsToCharge : chargebee.Int32(5),
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Subscription := res.Subscription
        Customer := res.Customer
        Card := res.Card
        Invoice := res.Invoice
        AdvanceInvoiceSchedules := res.AdvanceInvoiceSchedules
    }
}
```

#### 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.SubscriptionChargeFutureRenewalsRequest{
    TermsToCharge : chargebee.Int32(5),
}
  res, err := client.Subscription.ChargeFutureRenewals("__test__8asukSOXdtV2MX", req)
      if err != nil {
        fmt.Println(err)
    } else {
        Subscription := res.Subscription
        Customer := res.Customer
        Card := res.Card
        Invoice := res.Invoice
        AdvanceInvoiceSchedules := res.AdvanceInvoiceSchedules
    }
}
```

#### 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.chargeFutureRenewals("__test__8asukSOXdtV2MX")
            .termsToCharge(5)
            .request();

        Subscription subscription = result.subscription();
        Customer customer = result.customer();
        Card card = result.card();
        Invoice invoice = result.invoice();
        List<AdvanceInvoiceSchedule> advanceInvoiceSchedules = result.advanceInvoiceSchedules();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.advanceInvoiceSchedule.AdvanceInvoiceSchedule;
import com.chargebee.v4.models.card.Card;
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.SubscriptionChargeFutureRenewalsParams;
import com.chargebee.v4.models.subscription.responses.SubscriptionChargeFutureRenewalsResponse;
import java.util.List;

public class SubscriptionChargeFutureRenewals {

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

        SubscriptionChargeFutureRenewalsParams params = SubscriptionChargeFutureRenewalsParams.builder()
            .termsToCharge(5)
            .build();

        SubscriptionChargeFutureRenewalsResponse response = client
            .subscriptions()
            .chargeFutureRenewals("__test__8asukSOXdtV2MX", params);

        Subscription subscription = response.getSubscription();
        Customer customer = response.getCustomer();
        Card card = response.getCard();
        Invoice invoice = response.getInvoice();
        List<AdvanceInvoiceSchedule> advanceInvoiceSchedules = response.getAdvanceInvoiceSchedules();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.subscription.chargeFutureRenewals("__test__8asukSOXdtV2MX", {
        terms_to_charge: 5
    });

    console.log(result);
    const subscription = result.subscription;
    const customer = result.customer;
    const card = result.card;
    const invoice = result.invoice;
    const advanceInvoiceSchedules = result.advance_invoice_schedules;
} 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()->chargeFutureRenewals("__test__8asukSOXdtV2MX", [
    "terms_to_charge" => 5
]);
$subscription = $result->subscription;
$customer = $result->customer;
$card = $result->card;
$invoice = $result->invoice;
$advanceInvoiceSchedules = $result->advance_invoice_schedules;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Subscription.charge_future_renewals("__test__8asukSOXdtV2MX",
    cb_client.Subscription.ChargeFutureRenewalsParams(
        terms_to_charge=5
    )
)
subscription = response.subscription
customer = response.customer
card = response.card
invoice = response.invoice
advance_invoice_schedules = response.advance_invoice_schedules
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Subscription.charge_future_renewals("__test__8asukSOXdtV2MX",{
  :terms_to_charge => 5
})

subscription = result.subscription
customer = result.customer
card = result.card
invoice = result.invoice
advance_invoice_schedules = result.advance_invoice_schedules
```

## Sample Response

```json
{
  "customer": {
    "allow_direct_debit": false,
    "auto_collection": "off",
    "card_status": "no_card",
    "created_at": 1612890911,
    "deleted": false,
    "excess_payments": 0,
    "first_name": "John",
    "id": "__test__8asukSOXdtPJMU",
    "last_name": "Doe",
    "net_term_days": 0,
    "object": "customer",
    "pii_cleared": "active",
    "preferred_currency_code": "USD",
    "promotional_credits": 0,
    "refundable_credits": 0,
    "resource_version": 1612890911000,
    "taxability": "taxable",
    "unbilled_charges": 0,
    "updated_at": 1612890911
  },
  "invoice": {
    "adjustment_credit_notes": {},
    "amount_adjusted": 0,
    "amount_due": 5500,
    "amount_paid": 0,
    "amount_to_collect": 5500,
    "applied_credits": {},
    "base_currency_code": "USD",
    "billing_address": {
      "first_name": "John",
      "last_name": "Doe",
      "object": "billing_address",
      "validation_status": "not_validated"
    },
    "credits_applied": 0,
    "currency_code": "USD",
    "customer_id": "__test__8asukSOXdtPJMU",
    "date": 1612890912,
    "deleted": false,
    "due_date": 1612890912,
    "dunning_attempts": {},
    "exchange_rate": 1,
    "first_invoice": false,
    "has_advance_charges": true,
    "id": "__demo_inv__6",
    "is_gifted": false,
    "issued_credit_notes": {},
    "line_items": [
      {
        "amount": 1000,
        "customer_id": "__test__8asukSOXdtPJMU",
        "date_from": 1615310111,
        "date_to": 1617988511,
        "description": "basic USD",
        "discount_amount": 0,
        "entity_id": "basic-USD",
        "entity_type": "plan_item_price",
        "id": "li___test__8asukSOXdthZMf",
        "is_taxed": false,
        "item_level_discount_amount": 0,
        "object": "line_item",
        "pricing_model": "per_unit",
        "quantity": 1,
        "subscription_id": "__test__8asukSOXdtV2MX",
        "tax_amount": 0,
        "tax_exempt_reason": "tax_not_configured",
        "unit_amount": 1000
      },
      {..}
    ],
    "linked_orders": {},
    "linked_payments": {},
    "net_term_days": 0,
    "object": "invoice",
    "price_type": "tax_exclusive",
    "recurring": true,
    "resource_version": 1612890912000,
    "round_off_amount": 0,
    "status": "payment_due",
    "sub_total": 5500,
    "subscription_id": "__test__8asukSOXdtV2MX",
    "tax": 0,
    "term_finalized": true,
    "total": 5500,
    "updated_at": 1612890912,
    "write_off_amount": 0
  },
  "subscription": {
    "activated_at": 1612890911,
    "billing_period": 1,
    "billing_period_unit": "month",
    "created_at": 1612890911,
    "currency_code": "USD",
    "current_term_end": 1615310111,
    "current_term_start": 1612890911,
    "customer_id": "__test__8asukSOXdtPJMU",
    "deleted": false,
    "due_invoices_count": 2,
    "due_since": 1612890911,
    "has_scheduled_changes": false,
    "id": "__test__8asukSOXdtV2MX",
    "mrr": 0,
    "next_billing_at": 1628529311,
    "object": "subscription",
    "resource_version": 1612890911000,
    "started_at": 1612890911,
    "status": "active",
    "subscription_items": [
      {
        "amount": 1000,
        "free_quantity": 0,
        "item_price_id": "basic-USD",
        "item_type": "plan",
        "object": "subscription_item",
        "quantity": 1,
        "unit_price": 1000
      },
      {..}
    ],
    "total_dues": 6600,
    "updated_at": 1612890911
  }
}
```

## URL Format

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

## Input Parameters

- `terms_to_charge` (optional, integer, default=1, min=1)
  The number of billing cycles to charge, depending on the `schedule_type`:
  
  -   For `schedule_type = immediate`: The number of future billing cycles to be invoiced in advance. The invoicing is done for the [`remaining_billing_cycles`](/docs/api/subscriptions/subscription-object#subscription_remaining_billing_cycles) of the subscription if that is less than `terms_to_charge`.
  -   For `schedule_type = fixed_intervals`: The number of future billing cycles in one interval. The schedule is created such that the total number of billing cycles in the schedule does not exceed the `remaining_billing_cycles` of the subscription.
  
  **Constraints**
  
  -   Must be greater than 0.
  -   Must not exceed the maximum terms allowed for advance invoicing (configured in [site settings](https://www.chargebee.com/docs/billing/2.0/invoices-credit-notes-and-quotes/advance-invoices)).
  -   The value must not exceed the `remaining_billing_cycles` of the subscription.
  
  **Default value**
  
  -   `1`

- `invoice_immediately` (optional, boolean)
  Whether the charge should be invoiced immediately or added to [`unbilled_charges`](/docs/api/unbilled_charges).
  
  **Prerequisite**
  
  -   If `invoice_immediately` is `true` and `auto_collection` is `on` for the subscription, there must be a valid and active online [`payment_source`](/docs/api/payment_sources) associated with the [subscription](/docs/api/subscriptions/subscription-object#subscription_payment_source_id) or the customer.
  
  **Constraints**
  
  -   The `schedule_type` must be `immediate`.
  
  **Default value**
  
  -   `true`

- `schedule_type` (optional, enumerated string)
  The type of advance invoice or advance invoicing schedule.
  
  **Default value**
  
  -   `immediate`
  Possible enum values:
    - `immediate`
      Bill immediately for the number of billing cycles specified by `terms_to_charge`.
      
      **Prerequisite**
      
      -   There must not be an existing advance invoice or an advance invoice schedule for the subscription.
    - `specific_dates`
      Invoice on specific dates.
      
      **Prerequisite**
      
      -   There should not be an existing advance invoice schedule of `schedule_type` = `fixed_intervals` for the subscription.
      -   The total number of advance invoice schedules (existing and new ones scheduled through this API) of `schedule_type` = `specific_dates` must not exceed 5.
      
      **Constraints**
      
      -   When this option is selected, you must provide `specific_dates_schedule[date]`.
    - `fixed_intervals`
      Invoice at fixed intervals of time.
      
      **Prerequisite**
      
      -   There should not be any existing advance invoice schedule for the subscription.
      
      **Constraints**
      
      -   When this option is selected, you must provide the following parameters:
          -   `terms_to_charge`
          -   `fixed_interval_schedule[days_before_renewal]`
          -   `fixed_interval_schedule[end_schedule_on]`

- `fixed_interval_schedule` (optional, integer)
  Parameters for fixed\_interval\_schedule.
  
  **Required if**
  
  -   `schedule_type` is `fixed_intervals`.
  
  **Constraint**
  
  -   There must be exactly one element in the `fixed_interval_schedule` array.
  - `number_of_occurrences` (optional, integer, min=1)
    The number of advance invoices to generate.
    
    **Required if**
    
    -   `fixed_interval_schedule[end_schedule_on]` is set to `after_number_of_intervals`.
    
    **Impact**
    
    -   The schedule is created such that the total number of billing cycles in the schedule does not exceed the [`remaining_billing_cycles`](/docs/api/subscriptions/subscription-object#subscription_remaining_billing_cycles) of the subscription.
  - `days_before_renewal` (optional, integer, min=1)
    The number of days before each interval that advance invoices are generated.
    
    **Constraints**
    
    -   For weekly billing periods: Must be less than or equal to `5` days.
    -   For monthly billing periods: Must be less than or equal to `25` days for 1-month periods.
    -   For yearly billing periods: Must be less than or equal to `363` days.
    -   For daily billing periods: `days_before_renewal` should not be provided.
  - `end_schedule_on` (optional, enumerated string)
    Specifies when the advance invoicing schedule ends.
    Possible enum values:
      - `after_number_of_intervals`
        Advance invoices are generated a specified number of times.
        
        **Constraint**
        
        -   You must provide `fixed_interval_schedule[number_of_occurrences]`.
      - `specific_date`
        The advance invoicing schedule ends on a specific date.
        
        **Constraint**
        
        -   You must provide `fixed_interval_schedule[end_date]`.
      - `subscription_end`
        Advance invoices are generated for as long as the subscription is active.
  - `end_date` (optional, timestamp(UTC) in seconds)
    The date when the advance invoicing schedule ends. Advance invoices are not generated beyond this date.
    
    **Constraints**
    
    -   `fixed_interval_schedule[end_schedule_on]` must be set to `specific_date`.
    -   Must be a future date.
    -   Must be at least 1 day before the start of the last billing cycle of the subscription.
    -   Must be within 5 years from the current date.

- `specific_dates_schedule` (optional, array)
  Parameters for specific\_dates\_schedule.
  
  **Required if**
  
  -   `schedule_type` is `specific_dates`.
  
  **Constraints**
  
  -   The total number of schedules on the subscription (existing and new ones scheduled through this API) must not exceed 5.
  - `terms_to_charge` (optional, integer)
    The number of billing cycles to charge for on the specified date.
    
    **Constraints**
    
    -   The `schedule_type` must be `specific_dates`.
    -   Must be greater than 0.
    -   Must not exceed the maximum terms allowed for advance invoicing (configured in [site settings](https://www.chargebee.com/docs/billing/2.0/invoices-credit-notes-and-quotes/advance-invoices)).
    -   The total number of billing cycles across all schedules must not exceed the [`remaining_billing_cycles`](/docs/api/subscriptions/subscription-object#subscription_remaining_billing_cycles) of the subscription.
    
    **Default value**
    
    -   `1`
  - `date` (optional, timestamp(UTC) in seconds)
    The date on which the advance invoice should be generated. This is the scheduled date for generating the invoice for the specified number of billing cycles.
    
    **Constraints**
    
    -   The `schedule_type` must be `specific_dates`.
    -   Must be before the start of the billing period(s) that will be invoiced.
    -   Must be a future date within 5 years 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

- `advance_invoice_schedules` (optional)
  Resource object representing advance\_invoice\_schedule
