# Create invoice for a non-recurring addon

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


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

Generate invoices for a non-recurring addon using this API.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/invoices/charge_addon \
     -u {site_api_key}:\
     -d subscription_id="__test__XpbBxQiS4HD1ImXT" \
     -d addon_id="non_recurring_addon" \
     -d addon_unit_price=2000 \
     -d addon_quantity=2
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Invoice.ChargeAddon()
		.SubscriptionId("__test__XpbBxQiS4HD1ImXT")
		.AddonId("non_recurring_addon")
		.AddonUnitPrice(2000)
		.AddonQuantity(2)
		.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.ChargeAddon(&invoice.ChargeAddonRequestParams{
        SubscriptionId : "__test__XpbBxQiS4HD1ImXT",
        AddonId : "non_recurring_addon",
        AddonUnitPrice : chargebee.Int64(2000),
        AddonQuantity : chargebee.Int32(2),
    }).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.InvoiceChargeAddonRequest{
    SubscriptionId : "__test__XpbBxQiS4HD1ImXT",
    AddonId : "non_recurring_addon",
    AddonUnitPrice : chargebee.Int64(2000),
    AddonQuantity : chargebee.Int32(2),
}
  res, err := client.Invoice.ChargeAddon(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.chargeAddon()
            .subscriptionId("__test__XpbBxQiS4HD1ImXT")
            .addonId("non_recurring_addon")
            .addonUnitPrice(2000L)
            .addonQuantity(2)
            .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.InvoiceChargeAddonParams;
import com.chargebee.v4.models.invoice.responses.InvoiceChargeAddonResponse;

public class InvoiceChargeAddon {

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

        InvoiceChargeAddonParams params = InvoiceChargeAddonParams.builder()
            .subscriptionId("__test__XpbBxQiS4HD1ImXT")
            .addonId("non_recurring_addon")
            .addonUnitPrice(2000L)
            .addonQuantity(2)
            .build();

        InvoiceChargeAddonResponse response = client.invoices().chargeAddon(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.chargeAddon({
        subscription_id: "__test__XpbBxQiS4HD1ImXT",
        addon_id: "non_recurring_addon",
        addon_unit_price: 2000,
        addon_quantity: 2
    });

    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()->chargeAddon([
    "subscription_id" => "__test__XpbBxQiS4HD1ImXT",
    "addon_id" => "non_recurring_addon",
    "addon_unit_price" => 2000,
    "addon_quantity" => 2
]);
$invoice = $result->invoice;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Invoice.charge_addon(
    cb_client.Invoice.ChargeAddonParams(
        subscription_id="__test__XpbBxQiS4HD1ImXT",
        addon_id="non_recurring_addon",
        addon_unit_price=2000,
        addon_quantity=2
    )
)
invoice = response.invoice
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Invoice.charge_addon({
  :subscription_id => "__test__XpbBxQiS4HD1ImXT",
  :addon_id => "non_recurring_addon",
  :addon_unit_price => 2000,
  :addon_quantity => 2
})

invoice = result.invoice
```

## Sample Response

```json
{
  "invoice": {
    "adjustment_credit_notes": {},
    "amount_adjusted": 0,
    "amount_due": 0,
    "amount_paid": 4000,
    "amount_to_collect": 0,
    "applied_credits": {},
    "base_currency_code": "USD",
    "credits_applied": 0,
    "currency_code": "USD",
    "customer_id": "__test__XpbBxQiS4HD1ImXT",
    "date": 1517429428,
    "deleted": false,
    "due_date": 1517429428,
    "dunning_attempts": {},
    "exchange_rate": 1,
    "first_invoice": true,
    "has_advance_charges": false,
    "id": "__demo_inv__16",
    "is_gifted": false,
    "issued_credit_notes": {},
    "line_items": [
      {
        "amount": 4000,
        "customer_id": "__test__XpbBxQiS4HD1ImXT",
        "date_from": 1517429428,
        "date_to": 1517429428,
        "description": "non_recurring_addon",
        "discount_amount": 0,
        "entity_id": "non_recurring_addon",
        "entity_type": "addon",
        "id": "li___test__XpbBxQiS4HD1MQXi",
        "is_taxed": false,
        "item_level_discount_amount": 0,
        "object": "line_item",
        "pricing_model": "per_unit",
        "quantity": 2,
        "subscription_id": "__test__XpbBxQiS4HD1ImXT",
        "tax_amount": 0,
        "tax_exempt_reason": "tax_not_configured",
        "unit_amount": 2000
      },
      {..}
    ],
    "linked_orders": {},
    "linked_payments": [
      {
        "applied_amount": 4000,
        "applied_at": 1517429428,
        "txn_amount": 4000,
        "txn_date": 1517429428,
        "txn_id": "txn___test__XpbBxQiS4HD1MkXj",
        "txn_status": "success"
      },
      {..}
    ],
    "net_term_days": 0,
    "new_sales_amount": 4000,
    "object": "invoice",
    "paid_at": 1517429428,
    "price_type": "tax_exclusive",
    "recurring": false,
    "resource_version": 1517429428000,
    "round_off_amount": 0,
    "status": "paid",
    "sub_total": 4000,
    "subscription_id": "__test__XpbBxQiS4HD1ImXT",
    "tax": 0,
    "term_finalized": true,
    "total": 4000,
    "updated_at": 1517429428,
    "write_off_amount": 0
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/invoices/charge_addon

## Input Parameters

- `customer_id` (optional, string, max chars=50)
  Identifier of the customer for which this invoice needs to be created. Should be specified if 'subscription\_id' is not specified.

- `subscription_id` (optional, string, max chars=50)
  Identifier of the subscription for which this invoice(not applicable for consolidated invoice) needs to be created. Should be specified if 'customer\_id' is not specified.

- `addon_id` (required, string, max chars=100)
  The ID of the non-recurring addon to be charged.

- `addon_quantity` (optional, integer, min=1)
  The number of addon units to be charged. Mandatory for quantity based addons.

- `addon_unit_price` (optional, in cents, min=0)
  Amount that will override the Addon's default price. The unit depends on the [type of currency](/docs/api/getting-started) .

- `addon_quantity_in_decimal` (optional, string, max chars=33)
  The number of addon units to be charged in decimal.

- `addon_unit_price_in_decimal` (optional, string, max chars=39)
  Addon Amount in Decimal.

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

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

- `coupon_ids` (optional, string, max chars=100)
  List of Coupons to be added.

- `po_number` (optional, string, max chars=100)
  Purchase Order Number for this invoice.

- `invoice_date` (optional, timestamp(UTC) in seconds)
  The document date displayed on the invoice PDF. By default, it is the date of creation of the invoice or, when Metered Billing is enabled, it can be the date of closing the invoice. Provide this value to backdate the invoice (set the invoice date to a value in the past). Backdating an invoice is done for reasons such as booking revenue for a previous date or when the non-recurring charge is effective as of a past date. `taxes` and `line_item_taxes` are computed based on the tax configuration as of this date. The date should not be 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.

- `payment_source_id` (optional, string, max chars=40)
  Payment source to be used for this payment.

- `payment_initiator` (optional, enumerated string)
  The type of initiator to be used for the payment request triggered by this operation.
  Possible enum values:
    - `customer`
      Pass this value to indicate that the request is initiated by the customer
    - `merchant`
      Pass this value to indicate that the request is initiated by the merchant

## Returns

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