# Remove credit note from an invoice

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


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

Removes the specified adjustment credit or refundable credit allocation applied to the invoice.

### Prerequisites & Constraints

-   The invoice status must not be `voided` or `pending`.
-   The credit note status must not be `voided`.
-   The credit note type must be `adjustment` or `refundable`.
-   Refundable credit allocation cannot be removed if the amount allocated exceeds the refundable amount on the invoice. See **Implementation Notes** for more details.

### Impacts

**

Invoice

**

-   The [`amount_due`](/docs/api/invoices/invoice-object#amount_due) increases by the [`allocations[i].allocated_amount`](/docs/api/credit_notes/credit-note-object#allocations) of the credit note.
-   The [`amount_adjusted`](/docs/api/invoices/invoice-object#amount_adjusted) decreases by the `allocations[i].allocated_amount` of the credit note if the `credit_note.type` is `adjustment`.
-   The [`write_off_amount`](/docs/api/invoices/invoice-object#write_off_amount) decreases by the `allocations[i].allocated_amount` of the credit note if the `credit_note.create_reason_code` is `Write Off`.
-   If the invoice [status](/docs/api/invoices/invoice-object#status) was `payment_due`, `not_paid`, or `posted`, the status does not change after the credit note is removed.
-   If the invoice status was `paid`:
    -   The status changes to `posted` if the [`due_date`](/docs/api/invoices/invoice-object#due_date) is in the future.
    -   The status changes to `not_paid` if the due date is in the past.

**

Credit note

**

-   The `amount_allocated` decreases and the `amount_available` increases by the `allocations[i].allocated_amount`, where `i` is such that `allocations[i].invoice_id` = `invoice.id`.

### Implementation Notes

Before you call this API, make sure that:

-   The invoice status is not `voided` or `pending`.
-   The credit note status is not `voided`.
-   The credit note type is `adjustment` or `refundable`.
-   For refundable credit notes, the amount allocated to the invoice via the credit note must not exceed the refundable amount on the invoice. The refundable amount on the invoice is calculated as: (total amount paid) + (total refundable credits allocated to the invoice) + (total tax withheld recorded on the invoice) - (total refundable credits issued against the invoice). Each of these amounts can be obtained as follows:
    -   amount allocated to the invoice via the credit note: `credit_note.allocations[i].allocated_amount` where `credit_note.allocations[i].invoice_id` == `invoice.id`.
    -   total amount paid: `invoice.amount_paid`.
    -   total refundable credits allocated to the invoice: sum of `invoice.applied_credits[i].applied_amount`
    -   total tax withheld recorded on the invoice: sum of `invoice.linked_taxes_withheld[i].amount`
    -   total refundable credits issued against the invoice: sum of `invoice.issued_credit_notes[i].cn_total`

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/invoices/__demo_inv__16/remove_credit_note \
     -u {site_api_key}:\
     -d "credit_note[id]"="__demo_cn__5"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Invoice.RemoveCreditNote("__demo_inv__16")
		.CreditNoteId("__demo_cn__5")
		.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"
    "github.com/chargebee/chargebee-go/v3/models/invoice"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := invoiceAction.RemoveCreditNote("__demo_inv__16", &invoice.RemoveCreditNoteRequestParams{
        CreditNote : &invoice.RemoveCreditNoteCreditNoteParams{
            Id : "__demo_cn__5",
        },
    }).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.InvoiceRemoveCreditNoteRequest{
    CreditNote : &chargebee.InvoiceRemoveCreditNoteCreditNote{
        Id : "__demo_cn__5",
    },
}
  res, err := client.Invoice.RemoveCreditNote("__demo_inv__16", 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.removeCreditNote("__demo_inv__16")
            .creditNoteId("__demo_cn__5")
            .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.InvoiceRemoveCreditNoteParams;
import com.chargebee.v4.models.invoice.responses.InvoiceRemoveCreditNoteResponse;

public class InvoiceRemoveCreditNote {

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

        InvoiceRemoveCreditNoteParams.CreditNoteParams creditNoteParams =
            InvoiceRemoveCreditNoteParams.CreditNoteParams.builder()
                .id("__demo_cn__5")
                .build();

        InvoiceRemoveCreditNoteParams params = InvoiceRemoveCreditNoteParams.builder()
            .creditNote(creditNoteParams)
            .build();

        InvoiceRemoveCreditNoteResponse response = client
            .invoices()
            .removeCreditNote("__demo_inv__16", params);

        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.removeCreditNote("__demo_inv__16", {
        credit_note: {
            id: "__demo_cn__5"
        }
    });

    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()->removeCreditNote("__demo_inv__16", [
    "credit_note" => [
        "id" => "__demo_cn__5"
    ]
]);
$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.remove_credit_note("__demo_inv__16",
    cb_client.Invoice.RemoveCreditNoteParams(
        credit_note=cb_client.Invoice.RemoveCreditNoteCreditNoteParams(
            id="__demo_cn__5"
        )
    )
)
invoice = response.invoice
credit_note = response.credit_note
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Invoice.remove_credit_note("__demo_inv__16",{
  :credit_note => {
    :id => "__demo_cn__5"
  }
})

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

## Sample Response

```json
{
  "credit_note": {
    "allocations": {},
    "amount_allocated": 0,
    "amount_available": 3000,
    "amount_refunded": 0,
    "base_currency_code": "USD",
    "create_reason_code": "Service Unsatisfactory",
    "currency_code": "USD",
    "customer_id": "__test__8asyKSOcTKTb3h",
    "date": 1517490275,
    "deleted": false,
    "exchange_rate": 1,
    "fractional_correction": 0,
    "id": "__demo_cn__5",
    "line_item_discounts": {},
    "line_item_taxes": {},
    "line_items": [
      {
        "amount": 3000,
        "customer_id": "__test__8asyKSOcTKTb3h",
        "date_from": 1517490275,
        "date_to": 1517490275,
        "description": "SSL Charge USD Monthly",
        "discount_amount": 0,
        "entity_id": "ssl-charge-USD",
        "entity_type": "charge_item_price",
        "id": "li___test__8asyKSOcTKdj3w",
        "is_taxed": false,
        "item_level_discount_amount": 0,
        "object": "line_item",
        "pricing_model": "flat_fee",
        "quantity": 1,
        "tax_amount": 0,
        "tax_exempt_reason": "tax_not_configured",
        "unit_amount": 3000
      },
      {..}
    ],
    "linked_refunds": {},
    "object": "credit_note",
    "price_type": "tax_exclusive",
    "reason_code": "service_unsatisfactory",
    "reference_invoice_id": "__demo_inv__15",
    "resource_version": 1517490276708,
    "round_off_amount": 0,
    "status": "refund_due",
    "sub_total": 3000,
    "taxes": {},
    "total": 3000,
    "type": "refundable",
    "updated_at": 1517490276
  },
  "invoice": {
    "adjustment_credit_notes": {},
    "amount_adjusted": 0,
    "amount_due": 4000,
    "amount_paid": 0,
    "amount_to_collect": 4000,
    "applied_credits": {},
    "base_currency_code": "USD",
    "billing_address": {
      "first_name": "John",
      "last_name": "Mathew",
      "object": "billing_address",
      "validation_status": "not_validated"
    },
    "credits_applied": 0,
    "currency_code": "USD",
    "customer_id": "__test__8asyKSOcTKTb3h",
    "date": 1517490276,
    "deleted": false,
    "due_date": 1517490276,
    "dunning_attempts": {},
    "exchange_rate": 1,
    "first_invoice": false,
    "has_advance_charges": false,
    "id": "__demo_inv__16",
    "is_gifted": false,
    "issued_credit_notes": {},
    "line_items": [
      {
        "amount": 4000,
        "customer_id": "__test__8asyKSOcTKTb3h",
        "date_from": 1517490276,
        "date_to": 1517490276,
        "description": "Encryption Charge USD Monthly",
        "discount_amount": 0,
        "entity_id": "encryption-charge-USD",
        "entity_type": "charge_item_price",
        "id": "li___test__8asyKSOcTKia42",
        "is_taxed": false,
        "item_level_discount_amount": 0,
        "object": "line_item",
        "pricing_model": "flat_fee",
        "quantity": 1,
        "tax_amount": 0,
        "tax_exempt_reason": "tax_not_configured",
        "unit_amount": 4000
      },
      {..}
    ],
    "linked_orders": {},
    "linked_payments": {},
    "net_term_days": 0,
    "object": "invoice",
    "price_type": "tax_exclusive",
    "recurring": false,
    "resource_version": 1517490276709,
    "round_off_amount": 0,
    "status": "not_paid",
    "sub_total": 4000,
    "tax": 0,
    "term_finalized": true,
    "total": 4000,
    "updated_at": 1517490276,
    "write_off_amount": 0
  }
}
```

## URL Format

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

## Input Parameters

- `credit_note` (optional, string)
  Parameters for credit\_note
  - `id` (required, string, max chars=50)
    Credit-note id.

## Returns

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

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