# Refund a credit note

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


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

Refunds a specified amount from a refundable credit note back to the customer's payment source.

This operation supports only refunds against online payments. The refund amount is returned to the customer through the [`payment_source`](/docs/api/payment_sources) associated with the transaction. If multiple transactions are associated with the credit note, call this API once for each transaction.

To record offline refunds, including those for [`linked_taxes_withheld`](/docs/api/invoices/invoice-object#linked_taxes_withheld), use the [Record refund for a credit note](/docs/api/credit_notes/refund-a-credit-note) API.

### Prerequisites & Constraints

-   The credit note [`type`](/docs/api/credit_notes/credit_note-object#type) is `refundable`.
-   The credit note [`status`](/docs/api/credit_notes/credit_note-object#status) is `refund_due`.
-   The credit note has an `amount_available` greater than 0.
-   Part or all of the credit note's `amount_available` is from online payments.
-   The credit note is not [standalone](https://www.chargebee.com/docs/billing/2.0/invoices-credit-notes-and-quotes/credit-notes#creating-standalone-credits); it has an associated invoice.
-   You can process partial refunds only if the associated payment gateway supports partial refund operations.

### Impacts

**

Credit note

**

-   The credit note's `amount_available` is reduced by the refunded amount.
-   The credit note's `status` is updated to `refunded` if the refunded amount is equal to the credit note's `amount_available`.
-   The credit note's [`linked_refunds`](/docs/api/credit_notes/credit_note-object#linked_refunds) is updated with the details of the refund transaction.

**

Transaction

**

Chargebee creates a transaction of [`type`](/docs/api/transactions/transaction-object#type) `refund` and links it to the credit note under `credit_note.linked_refunds`.

### Implementation Notes

Before you call this API, make sure the following conditions are met:

-   The credit note [`type`](/docs/api/credit_notes/credit_note-object#type) is `refundable`.
-   The credit note [`status`](/docs/api/credit_notes/credit_note-object#status) is `refund_due`.
-   The credit note has an `amount_available` greater than 0.
-   The credit note has the `reference_invoice_id` set.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/credit_notes/__demo_cn__6/refund \
     -u {site_api_key}:\
     -d customer_notes="Refunding as customer canceled the order." \
     -d refund_amount=1000
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = CreditNote.Refund("__demo_cn__6")
		.CustomerNotes("Refunding as customer canceled the order.")
		.RefundAmount(1000)
		.Request();

CreditNote creditNote = result.CreditNote;
Transaction transaction = result.Transaction;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    creditnoteAction "github.com/chargebee/chargebee-go/v3/actions/creditnote"
    "github.com/chargebee/chargebee-go/v3/models/creditnote"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := creditnoteAction.Refund("__demo_cn__6", &creditnote.RefundRequestParams{
        CustomerNotes : "Refunding as customer canceled the order.",
        RefundAmount : chargebee.Int64(1000),
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        CreditNote := res.CreditNote
        Transaction := res.Transaction
    }
}
```

#### 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.CreditNoteRefundRequest{
    CustomerNotes : "Refunding as customer canceled the order.",
    RefundAmount : chargebee.Int64(1000),
}
  res, err := client.CreditNote.Refund("__demo_cn__6", req)
      if err != nil {
        fmt.Println(err)
    } else {
        CreditNote := res.CreditNote
        Transaction := res.Transaction
    }
}
```

#### 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 = CreditNote.refund("__demo_cn__6")
            .customerNotes("Refunding as customer canceled the order.")
            .refundAmount(1000L)
            .request();

        CreditNote creditNote = result.creditNote();
        Transaction transaction = result.transaction();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.creditNote.CreditNote;
import com.chargebee.v4.models.creditNote.params.CreditNoteRefundParams;
import com.chargebee.v4.models.creditNote.responses.CreditNoteRefundResponse;
import com.chargebee.v4.models.transaction.Transaction;

public class CreditNoteRefund {

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

        CreditNoteRefundParams params = CreditNoteRefundParams.builder()
            .customerNotes("Refunding as customer canceled the order.")
            .refundAmount(1000L)
            .build();

        CreditNoteRefundResponse response = client
            .creditNotes()
            .refund("__demo_cn__6", params);

        CreditNote creditNote = response.getCreditNote();
        Transaction transaction = response.getTransaction();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

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

try {
    const result = await chargebee.creditNote.refund("__demo_cn__6", {
        customer_notes: "Refunding as customer canceled the order.",
        refund_amount: 1000
    });

    console.log(result);
    const creditNote = result.credit_note;
    const transaction = result.transaction;
} 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->creditNote()->refund("__demo_cn__6", [
    "customer_notes" => "Refunding as customer canceled the order.",
    "refund_amount" => 1000
]);
$creditNote = $result->credit_note;
$transaction = $result->transaction;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.CreditNote.refund("__demo_cn__6",
    cb_client.CreditNote.RefundParams(
        customer_notes="Refunding as customer canceled the order.",
        refund_amount=1000
    )
)
credit_note = response.credit_note
transaction = response.transaction
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::CreditNote.refund("__demo_cn__6",{
  :customer_notes => "Refunding as customer canceled the order.",
  :refund_amount => 1000
})

credit_note = result.credit_note
transaction = result.transaction
```

## Sample Response

```json
{
  "credit_note": {
    "allocations": {},
    "amount_allocated": 0,
    "amount_available": 0,
    "amount_refunded": 1000,
    "base_currency_code": "USD",
    "create_reason_code": "Product Unsatisfactory",
    "currency_code": "USD",
    "customer_id": "__test__KyVnHhSBWT0N17C",
    "date": 1517501413,
    "deleted": false,
    "exchange_rate": 1,
    "fractional_correction": 0,
    "id": "__demo_cn__6",
    "line_item_discounts": {},
    "line_item_taxes": {},
    "line_items": [
      {
        "amount": 1000,
        "customer_id": "__test__KyVnHhSBWT0N17C",
        "date_from": 1517501413,
        "date_to": 1517501413,
        "description": "Support Charge",
        "discount_amount": 0,
        "entity_type": "adhoc",
        "id": "li___test__KyVnHhSBWT0Rm7P",
        "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": 1000
      },
      {..}
    ],
    "linked_refunds": [
      {
        "applied_amount": 1000,
        "applied_at": 1517501413,
        "txn_amount": 1000,
        "txn_date": 1517501413,
        "txn_id": "txn___test__KyVnHhSBWT0Tk7T",
        "txn_status": "success"
      },
      {..}
    ],
    "object": "credit_note",
    "price_type": "tax_exclusive",
    "reason_code": "product_unsatisfactory",
    "reference_invoice_id": "__demo_inv__6",
    "refunded_at": 1517501413,
    "resource_version": 1517501413000,
    "round_off_amount": 0,
    "status": "refunded",
    "sub_total": 1000,
    "taxes": {},
    "total": 1000,
    "type": "refundable",
    "updated_at": 1517501413
  },
  "transaction": {
    "amount": 1000,
    "base_currency_code": "USD",
    "currency_code": "USD",
    "customer_id": "__test__KyVnHhSBWT0N17C",
    "date": 1517501413,
    "deleted": false,
    "exchange_rate": 1,
    "gateway": "chargebee",
    "gateway_account_id": "gw___test__KyVnGlSBWSxm7Jj",
    "id": "txn___test__KyVnHhSBWT0Tk7T",
    "id_at_gateway": "cb___test__KyVnHhSBWT0Q57L",
    "linked_credit_notes": [
      {
        "applied_amount": 1000,
        "applied_at": 1517501413,
        "cn_create_reason_code": "Product Unsatisfactory",
        "cn_date": 1517501413,
        "cn_id": "__demo_cn__6",
        "cn_reason_code": "product_unsatisfactory",
        "cn_reference_invoice_id": "__demo_inv__6",
        "cn_status": "refunded",
        "cn_total": 1000
      },
      {..}
    ],
    "masked_card_number": "************1111",
    "object": "transaction",
    "payment_method": "card",
    "payment_source_id": "pm___test__KyVnHhSBWT0Ni7E",
    "refunded_txn_id": "txn___test__KyVnHhSBWT0Py7K",
    "resource_version": 1517501413000,
    "status": "success",
    "type": "refund",
    "updated_at": 1517501413
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/credit_notes/{credit-note-id}/refund

## Input Parameters

- `refund_amount` (optional, in cents, min=1)
  The amount to be refunded.
  
  **Constraints**
  
  -   If multiple [transactions](/docs/api/invoices/invoice-object#linked_payments) are associated with the credit note, the refund can be processed only for one transaction at a time.
  -   Offline refunds, including those for [`linked_taxes_withheld`](/docs/api/invoices/invoice-object#linked_taxes_withheld), cannot be refunded via this operation. Use the [Record refund for a credit note](/docs/api/credit_notes/refund-a-credit-note) API instead.
  
  **Default behavior**
  
  -   If not specified, the `amount_available` for this credit note is implied.

- `customer_notes` (optional, string, max chars=2000)
  A note to be added for this operation, to the credit note. This note is displayed on customer-facing documents such as the [Credit Note PDF](/docs/api/credit_notes/retrieve-credit-note-as-pdf) .

- `refund_reason_code` (optional, string, max chars=100)
  Reason code for the refund. Must be one from a list of reason codes set in the Chargebee app in **Settings > Configure Chargebee > Reason Codes > Credit Notes > Refund Credit Note**. Must be passed if set as mandatory in the app. The codes are case-sensitive.

## Returns

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

- `transaction` (Transaction object)
  Resource object representing transaction
