# Void an invoice

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


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

[Asynchronous](/docs/api/async_response/async-response-object)

Voids the specified invoice.

Use this operation when:

-   The invoice was generated in error.
-   The invoice amount is incorrect.
-   The customer requests a change to the invoice.
-   The customer cancels the order.

Voiding preserves the audit trail and allows for future reference and compliance without removing the original record.

#### Regenerate or import an invoice[](#regenerate-or-import-an-invoice)

-   If the invoice is for the current term of a subscription, you can regenerate it using the [Regenerate an invoice API](/docs/api/subscriptions/regenerate-an-invoice).
-   If the invoice is not for the current term of a subscription, you can import it using the [Import an invoice API](/docs/api/invoices/import-invoice) or the UI [bulk import](https://www.chargebee.com/docs/2.0/bulk-operations.html#overview_available-bulk-operations) action.

### Prerequisites & Constraints

-   The invoice `status` must be `payment_due`, `posted`, or `not_paid`.
-   The invoice must not have any [`linked_payments`](/docs/api/invoices/invoice-object#linked_payments) with `txn_status` set to `success` or `in_progress`.
-   The `amount_adjusted` on the invoice must be zero.
-   The invoice must not have any [`applied_credits`](/docs/api/invoices/invoice-object#applied_credits) with `cn_status` set to `refunded` or `refund_due`.
-   The invoice must not have any [`issued_credit_notes`](/docs/api/invoices/invoice-object#issued_credit_notes) with `cn_status` set to `refunded` or `refund_due`.
-   The invoice must not have any [`linked_taxes_withheld`](/docs/api/invoices/invoice-object#linked_taxes_withheld).

### Impacts

**

Invoices

**

-   Chargebee sets the invoice `status` to `voided`.

**

Subscription

**

-   If the invoice is for the current term of a subscription and you change the subscription later within the same term with [proration](/docs/api/subscriptions/update-subscription-for-items#prorate) enabled, Chargebee does not issue prorated credits.

**

Customer

**

-   Chargebee adds back any promotional credits that were applied to the invoice to [`customer.balances.promotional_credits`](/docs/api/customers/customer-object#balances).

**

Credit Note

**

-   If the [**Void invoices with credit note**](https://www.chargebee.com/docs/billing/2.0/kb/billing/how-to-enable-void-invoice-with-credit-note-setting) setting is enabled, Chargebee creates a credit note for the voided invoice:
    -   The credit note `type` is `adjustment`.
    -   The credit note `status` is `adjusted`.
    -   The credit note `create_reason_code` is `Invoice Void`.

**

Usages

**

-   Chargebee delinks the [`usage`](/docs/api/usages) resources associated with the invoice by clearing the `invoice_id` attribute.

**

Integrations

**

-   Review how voiding an invoice impacts your [accounting](https://www.chargebee.com/docs/billing/2.0/integrations/finance-integration-index) integrations.

### Implementation Notes

Before calling this API, ensure the following:

-   The invoice `status` is `payment_due`, `posted`, or `not_paid`.
-   [Remove](/docs/api/invoices/remove-payment-from-an-invoice) any `linked_payments` with `txn_status` set to `success` or `in_progress`.
-   [Remove](/docs/api/invoices/remove-credit-note-from-an-invoice) the following credits:
    -   any `applied_credits` with `cn_status` set to `refunded` or `refund_due`
    -   any `issued_credit_notes` with `cn_status` set to `refunded` or `refund_due`
    -   any `adjustment_credit_notes` with `cn_status` set to `adjusted`
-   [Remove](/docs/api/invoices/remove-tax-withheld-for-an-invoice) any `linked_taxes_withheld`.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/invoices/__demo_inv__4/void \
     -X POST  \
     -u {site_api_key}:
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Invoice.VoidInvoice("__demo_inv__4").Request();

Invoice invoice = result.Invoice;
CreditNote creditNote = result.CreditNote;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    invoiceAction "github.com/chargebee/chargebee-go/v3/actions/invoice"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := invoiceAction.VoidInvoice("__demo_inv__4", nil).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Invoice := res.Invoice
        CreditNote := res.CreditNote
    }
}
```

#### 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.InvoiceVoidInvoiceRequest{}
  res, err := client.Invoice.VoidInvoice("__demo_inv__4", req)
      if err != nil {
        fmt.Println(err)
    } else {
        Invoice := res.Invoice
        CreditNote := res.CreditNote
    }
}
```

#### 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.voidInvoice("__demo_inv__4").request();

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

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.creditNote.CreditNote;
import com.chargebee.v4.models.invoice.Invoice;
import com.chargebee.v4.models.invoice.params.VoidInvoiceParams;
import com.chargebee.v4.models.invoice.responses.VoidInvoiceResponse;

public class VoidInvoice {

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

        VoidInvoiceResponse response = client.invoices().voidInvoice("__demo_inv__4");

        Invoice invoice = response.getInvoice();
        CreditNote creditNote = response.getCreditNote();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.invoice.voidInvoice("__demo_inv__4");

    console.log(result);
    const invoice = result.invoice;
    const creditNote = result.credit_note;
} 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()->voidInvoice("__demo_inv__4");
$invoice = $result->invoice;
$creditNote = $result->credit_note;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Invoice.void_invoice("__demo_inv__4")
invoice = response.invoice
credit_note = response.credit_note
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Invoice.void_invoice("__demo_inv__4")

invoice = result.invoice
credit_note = result.credit_note
```

## Sample Response

```json
{
  "invoice": {
    "adjustment_credit_notes": {},
    "amount_adjusted": 0,
    "amount_due": 1000,
    "amount_paid": 0,
    "amount_to_collect": 1000,
    "applied_credits": {},
    "base_currency_code": "USD",
    "billing_address": {
      "first_name": "Rachel",
      "last_name": "Green",
      "object": "billing_address",
      "validation_status": "not_validated"
    },
    "credits_applied": 0,
    "currency_code": "USD",
    "customer_id": "__test__8at01SOcUsFk2s",
    "date": 1612797047,
    "deleted": false,
    "due_date": 1612797047,
    "dunning_attempts": [
      {
        "attempt": 0,
        "created_at": 1612797048,
        "dunning_type": "auto_collect",
        "retry_engine": "chargebee",
        "transaction_id": "txn___test__8at01SOcUuIQ3v",
        "txn_amount": 1000,
        "txn_status": "failure"
      },
      {..}
    ],
    "dunning_status": "stopped",
    "exchange_rate": 1,
    "first_invoice": false,
    "has_advance_charges": false,
    "id": "__demo_inv__4",
    "is_gifted": false,
    "issued_credit_notes": {},
    "line_items": [
      {
        "amount": 1000,
        "customer_id": "__test__8at01SOcUsFk2s",
        "date_from": 1612797047,
        "date_to": 1612883447,
        "description": "Basic USD 2",
        "discount_amount": 0,
        "entity_id": "basic-USD2",
        "entity_type": "plan_item_price",
        "id": "li___test__8at01SOcUuFN3u",
        "is_taxed": false,
        "item_level_discount_amount": 0,
        "object": "line_item",
        "pricing_model": "per_unit",
        "quantity": 1,
        "subscription_id": "__test__8at01SOcUsFk2s",
        "tax_amount": 0,
        "tax_exempt_reason": "tax_not_configured",
        "unit_amount": 1000
      },
      {..}
    ],
    "linked_orders": {},
    "linked_payments": [
      {
        "applied_amount": 1000,
        "applied_at": 1612797048,
        "txn_amount": 1000,
        "txn_date": 1612797048,
        "txn_id": "txn___test__8at01SOcUuIQ3v",
        "txn_status": "failure"
      },
      {..}
    ],
    "net_term_days": 0,
    "object": "invoice",
    "price_type": "tax_exclusive",
    "recurring": true,
    "resource_version": 1517490652136,
    "round_off_amount": 0,
    "status": "voided",
    "sub_total": 1000,
    "subscription_id": "__test__8at01SOcUsFk2s",
    "tax": 0,
    "term_finalized": true,
    "total": 1000,
    "updated_at": 1517490652,
    "voided_at": 1517490652,
    "write_off_amount": 0
  }
}
```

## URL Format

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

## Input Parameters

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

- `void_reason_code` (optional, string, max chars=100)
  Reason code for voiding the invoice. Select from a list of reason codes set in the Chargebee app in **Settings > Configure Chargebee > Reason Codes > Invoices > Void invoice**. Must be passed if set as mandatory in the app. The codes are case-sensitive.

## Returns

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

- `credit_note` (Credit note object)
  Resource object representing credit\_note
