# Create invoice for a one-time charge

> 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 one-time charge using this API.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/invoices/charge \
     -u {site_api_key}:\
     -d subscription_id="__test__KyVnHhSBWlaML2hj" \
     -d amount=1000 \
     -d description="Support Charge"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Invoice.Charge()
		.SubscriptionId("__test__KyVnHhSBWlaML2hj")
		.Amount(1000)
		.Description("Support Charge")
		.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.Charge(&invoice.ChargeRequestParams{
        SubscriptionId : "__test__KyVnHhSBWlaML2hj",
        Amount : chargebee.Int64(1000),
        Description : "Support Charge",
    }).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.InvoiceChargeRequest{
    SubscriptionId : "__test__KyVnHhSBWlaML2hj",
    Amount : chargebee.Int64(1000),
    Description : "Support Charge",
}
  res, err := client.Invoice.Charge(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.charge()
            .subscriptionId("__test__KyVnHhSBWlaML2hj")
            .amount(1000L)
            .description("Support Charge")
            .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.InvoiceChargeParams;
import com.chargebee.v4.models.invoice.responses.InvoiceChargeResponse;

public class InvoiceCharge {

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

        InvoiceChargeParams params = InvoiceChargeParams.builder()
            .subscriptionId("__test__KyVnHhSBWlaML2hj")
            .amount(1000L)
            .description("Support Charge")
            .build();

        InvoiceChargeResponse response = client.invoices().charge(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.charge({
        subscription_id: "__test__KyVnHhSBWlaML2hj",
        amount: 1000,
        description: "Support Charge"
    });

    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()->charge([
    "subscription_id" => "__test__KyVnHhSBWlaML2hj",
    "amount" => 1000,
    "description" => "Support Charge"
]);
$invoice = $result->invoice;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Invoice.charge(
    cb_client.Invoice.ChargeParams(
        subscription_id="__test__KyVnHhSBWlaML2hj",
        amount=1000,
        description="Support Charge"
    )
)
invoice = response.invoice
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Invoice.charge({
  :subscription_id => "__test__KyVnHhSBWlaML2hj",
  :amount => 1000,
  :description => "Support Charge"
})

invoice = result.invoice
```

## Sample Response

```json
{
  "invoice": {
    "adjustment_credit_notes": {},
    "amount_adjusted": 0,
    "amount_due": 0,
    "amount_paid": 1000,
    "amount_to_collect": 0,
    "applied_credits": {},
    "base_currency_code": "USD",
    "credits_applied": 0,
    "currency_code": "USD",
    "customer_id": "__test__XpbBxQiS4HD1QKXn",
    "date": 1517429429,
    "deleted": false,
    "due_date": 1517429429,
    "dunning_attempts": {},
    "exchange_rate": 1,
    "first_invoice": true,
    "has_advance_charges": false,
    "id": "__demo_inv__18",
    "is_gifted": false,
    "issued_credit_notes": {},
    "line_items": [
      {
        "amount": 1000,
        "customer_id": "__test__XpbBxQiS4HD1QKXn",
        "date_from": 1517429429,
        "date_to": 1517429429,
        "description": "Support Charge",
        "discount_amount": 0,
        "entity_type": "adhoc",
        "id": "li___test__XpbBxQiS4HD1TtY2",
        "is_taxed": false,
        "item_level_discount_amount": 0,
        "object": "line_item",
        "pricing_model": "flat_fee",
        "quantity": 1,
        "subscription_id": "__test__XpbBxQiS4HD1QKXn",
        "tax_amount": 0,
        "tax_exempt_reason": "tax_not_configured",
        "unit_amount": 1000
      },
      {..}
    ],
    "linked_orders": {},
    "linked_payments": [
      {
        "applied_amount": 1000,
        "applied_at": 1517429429,
        "txn_amount": 1000,
        "txn_date": 1517429429,
        "txn_id": "txn___test__XpbBxQiS4HD1UAY3",
        "txn_status": "success"
      },
      {..}
    ],
    "net_term_days": 0,
    "new_sales_amount": 1000,
    "object": "invoice",
    "paid_at": 1517429429,
    "price_type": "tax_exclusive",
    "recurring": false,
    "resource_version": 1517429429000,
    "round_off_amount": 0,
    "status": "paid",
    "sub_total": 1000,
    "subscription_id": "__test__XpbBxQiS4HD1QKXn",
    "tax": 0,
    "term_finalized": true,
    "total": 1000,
    "updated_at": 1517429429,
    "write_off_amount": 0
  }
}
```

## URL Format

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

## 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 needs to be created. Should be specified if 'customer\_id' is not specified.(not applicable for consolidated invoice).

- `currency_code` (required if Multicurrency is enabled, string, max chars=3)
  The currency code (ISO 4217 format) of the invoice amount. Applicable only while creating an invoice for a customer (by specifying _customer\_id_ ).

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

- `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/v2/pcv-1/currencies) is enabled.

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

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

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

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

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

- `tax_providers_fields` (optional, array)
  Parameters for tax\_providers\_fields
  - `provider_name` (optional, string, max chars=50)
    Name of the tax provider currently supported.
  - `field_id` (optional, string, max chars=50)
    Field id of the attribute which tax vendor has provided while getting onboarded with us.
  - `field_value` (optional, string, max chars=50)
    The value of the corresponding tax field.

## Returns

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