# Add one-time charge to a pending invoice

> 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 a [pending](/docs/api/invoices/invoice-object#status) invoice. A one-time charge is a charge that is added ad hoc to the invoice and does not represent a predefined [item price](/docs/api/item_prices). It appears in the invoice as a `[line_item](/docs/api/invoices/invoice-object#line_items)` of `[entity_type](/docs/api/invoices/invoice-object#line_items_entity_type)` `adhoc`.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/invoices/__demo_inv__4/add_charge \
     -u {site_api_key}:\
     -d amount=150 \
     -d description="$0.05 each for 30 messages"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Invoice.AddCharge("__demo_inv__4")
		.Amount(150)
		.Description("$0.05 each for 30 messages")
		.Request();

Invoice invoice = result.Invoice;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    invoiceAction "github.com/chargebee/chargebee-go/v3/actions/invoice"
    "github.com/chargebee/chargebee-go/v3/models/invoice"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := invoiceAction.AddCharge("__demo_inv__4", &invoice.AddChargeRequestParams{
        Amount : chargebee.Int64(150),
        Description : "$0.05 each for 30 messages",
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Invoice := res.Invoice
    }
}
```

#### 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.InvoiceAddChargeRequest{
    Amount : chargebee.Int64(150),
    Description : "$0.05 each for 30 messages",
}
  res, err := client.Invoice.AddCharge("__demo_inv__4", req)
      if err != nil {
        fmt.Println(err)
    } else {
        Invoice := res.Invoice
    }
}
```

#### 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 = Invoice.addCharge("__demo_inv__4")
            .amount(150L)
            .description("$0.05 each for 30 messages")
            .request();

        Invoice invoice = result.invoice();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.invoice.Invoice;
import com.chargebee.v4.models.invoice.params.InvoiceAddChargeParams;
import com.chargebee.v4.models.invoice.responses.InvoiceAddChargeResponse;

public class InvoiceAddCharge {

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

        InvoiceAddChargeParams params = InvoiceAddChargeParams.builder()
            .amount(150L)
            .description("$0.05 each for 30 messages")
            .build();

        InvoiceAddChargeResponse response = client
            .invoices()
            .addCharge("__demo_inv__4", params);

        Invoice invoice = response.getInvoice();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.invoice.addCharge("__demo_inv__4", {
        amount: 150,
        description: "$0.05 each for 30 messages"
    });

    console.log(result);
    const invoice = result.invoice;
} 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->invoice()->addCharge("__demo_inv__4", [
    "amount" => 150,
    "description" => "$0.05 each for 30 messages"
]);
$invoice = $result->invoice;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Invoice.add_charge("__demo_inv__4",
    cb_client.Invoice.AddChargeParams(
        amount=150,
        description="$0.05 each for 30 messages"
    )
)
invoice = response.invoice
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Invoice.add_charge("__demo_inv__4",{
  :amount => 150,
  :description => "$0.05 each for 30 messages"
})

invoice = result.invoice
```

## Sample Response

```json
{
  "invoice": {
    "adjustment_credit_notes": {},
    "amount_adjusted": 0,
    "amount_due": 29731,
    "amount_paid": 0,
    "amount_to_collect": 29731,
    "applied_credits": {},
    "base_currency_code": "USD",
    "credits_applied": 0,
    "currency_code": "USD",
    "customer_id": "__test__XpbBxViS4HCzob2f",
    "date": 1517429423,
    "deleted": false,
    "dunning_attempts": {},
    "exchange_rate": 1,
    "first_invoice": false,
    "has_advance_charges": false,
    "id": "__demo_inv__4",
    "is_gifted": false,
    "issued_credit_notes": {},
    "line_items": [
      {
        "amount": 29581,
        "customer_id": "__test__XpbBxViS4HCzob2f",
        "date_from": 1517429423,
        "date_to": 1596658222,
        "description": "Basic - Prorated Charges",
        "discount_amount": 0,
        "entity_id": "basic",
        "entity_type": "plan",
        "id": "li___test__XpbBxQiS4HCztAVi",
        "is_taxed": false,
        "item_level_discount_amount": 0,
        "object": "line_item",
        "pricing_model": "per_unit",
        "quantity": 1,
        "subscription_id": "__test__XpbBxViS4HCzob2f",
        "tax_amount": 0,
        "unit_amount": 29581
      },
      {..}
    ],
    "linked_orders": {},
    "linked_payments": {},
    "net_term_days": 0,
    "object": "invoice",
    "price_type": "tax_exclusive",
    "recurring": true,
    "resource_version": 1517429423000,
    "round_off_amount": 0,
    "status": "pending",
    "sub_total": 29731,
    "subscription_id": "__test__XpbBxViS4HCzob2f",
    "tax": 0,
    "term_finalized": true,
    "total": 29731,
    "updated_at": 1517429423,
    "write_off_amount": 0
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/invoices/{invoice-id}/add_charge

## Input Parameters

- `amount` (required, 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)
  Detailed description about this lineitem.

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

- `avalara_tax_code` (optional, string, max chars=50)
  This represents the Avalara tax code to which the one-time charge is mapped. Applicable only if you use Chargebee's [AvaTax for Sales integration](https://www.chargebee.com/docs/avatax-for-sales.html) .

- `hsn_code` (optional, string, max chars=50)
  The [HSN code](https://cbic-gst.gov.in/gst-goods-services-rates.html) to which the one-time charge is mapped for calculating the customer's tax in India. Applicable when both the conditions are true:
  
  -   [**India**](https://www.chargebee.com/docs/indian-gst.html#configuring-indian-gst) has been enabled as a **Tax Region**. (An error is returned when this condition is not true.)
  -   The [**AvaTax for Sales** integration](https://www.chargebee.com/docs/avalara.html) has been enabled in Chargebee. .

- `taxjar_product_code` (optional, string, max chars=50)
  This represents the TaxJar product code to which the one-time charge is mapped. Applicable only if you use Chargebee's [TaxJar integration](https://www.chargebee.com/docs/taxjar.html) .

- `comment` (optional, string, max chars=300)
  An internal [comment](/docs/api/comments) to be added for this operation, to the invoice. This comment is displayed on the Chargebee UI. It is not displayed on any customer-facing [Hosted Page](/docs/api/hosted_pages) or any document such as the [Invoice PDF](/docs/api/invoices/retrieve-invoice-as-pdf) .

- `subscription_id` (optional, string, max chars=50)
  Identifier of the subscription for which this charge needs to be created. Applicable for consolidated invoice.

- `line_item` (optional, timestamp(UTC) in seconds)
  Parameters for line\_item
  - `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

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