# Record refund for a credit note

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

Records a refund for a refundable credit note.

This API does not process an actual refund for online payments by returning money to customers.

Use this API to record refunds processed outside Chargebee (for example, directly through a payment gateway or via offline methods such as bank transfers or checks) so you can reconcile them in Chargebee.

To process refunds via Chargebee for online payments and automatically return money to customers, use the [Refund a credit note](/docs/api/credit_notes/refund-a-credit-note) API instead.

### Prerequisites & Constraints

-   The credit note [`type`](/docs/api/credit_notes/credit_note-object#type) must be `refundable`.
-   The credit note [`status`](/docs/api/credit_notes/credit_note-object#status) must be `refund_due`.

### Impacts

**

Transactions

**

Chargebee records the refunds by creating transactions of [`type`](/docs/api/transactions/transaction-object#type) `refund` and links them to the credit note. The refund transactions are recorded in the following order:

1.  [`linked_payments`](/docs/api/invoices/invoice-object#linked_payments) of the invoice associated with the credit note. This is recorded as [`linked_refunds[]`](/docs/api/credit_notes/credit_note-object#linked_refunds) in the credit note.
2.  [`linked_taxes_withheld`](/docs/api/invoices/invoice-object#linked_taxes_withheld) (if available). This is recorded as [`linked_tax_withheld_refunds[]`](/docs/api/credit_notes/credit_note-object#linked_tax_withheld_refunds) in the credit note.

### Implementation Notes

Before using this API, ensure:

-   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`.
-   If [reason codes](https://www.chargebee.com/docs/billing/2.0/site-configuration/reason-codes#managing-reason-codes-for-credit-notes) are mandatory in Chargebee Billing, include the `refund_reason_code` parameter with a value from the configured list of codes.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/credit_notes/__demo_cn__5/record_refund \
     -u {site_api_key}:\
     -d comment="Refunding as customer canceled the order." \
     -d "transaction[amount]"=100 \
     -d "transaction[payment_method]"="BANK_TRANSFER" \
     -d "transaction[date]"=1517501412
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = CreditNote.RecordRefund("__demo_cn__5")
		.Comment("Refunding as customer canceled the order.")
		.TransactionAmount(100)
		.TransactionPaymentMethod(PaymentMethodEnum.BankTransfer)
		.TransactionDate(1517501412)
		.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"
    enum "github.com/chargebee/chargebee-go/v3/enum"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := creditnoteAction.RecordRefund("__demo_cn__5", &creditnote.RecordRefundRequestParams{
        Comment : "Refunding as customer canceled the order.",
        Transaction : &creditnote.RecordRefundTransactionParams{
            Amount : chargebee.Int64(100),
            PaymentMethod : enum.PaymentMethodBankTransfer,
            Date : chargebee.Int64(1517501412),
        },
    }).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.CreditNoteRecordRefundRequest{
    Comment : "Refunding as customer canceled the order.",
    Transaction : &chargebee.CreditNoteRecordRefundTransaction{
        Amount : chargebee.Int64(100),
        PaymentMethod : chargebee.PaymentMethodBankTransfer,
        Date : chargebee.Int64(1517501412),
    },
}
  res, err := client.CreditNote.RecordRefund("__demo_cn__5", 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;
import java.sql.Timestamp;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = CreditNote.recordRefund("__demo_cn__5")
            .comment("Refunding as customer canceled the order.")
            .transactionAmount(100L)
            .transactionPaymentMethod(PaymentMethod.BANK_TRANSFER)
            .transactionDate(new Timestamp(1517501412L * 1000))
            .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.CreditNoteRecordRefundParams;
import com.chargebee.v4.models.creditNote.responses.CreditNoteRecordRefundResponse;
import com.chargebee.v4.models.transaction.Transaction;
import java.sql.Timestamp;

public class CreditNoteRecordRefund {

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

        CreditNoteRecordRefundParams.TransactionParams transactionParams =
            CreditNoteRecordRefundParams.TransactionParams.builder()
                .amount(100L)
                .paymentMethod(CreditNoteRecordRefundParams.TransactionParams.PaymentMethod.BANK_TRANSFER)
                .date(new Timestamp(1517501412L * 1000))
                .build();

        CreditNoteRecordRefundParams params = CreditNoteRecordRefundParams.builder()
            .comment("Refunding as customer canceled the order.")
            .transaction(transactionParams)
            .build();

        CreditNoteRecordRefundResponse response = client
            .creditNotes()
            .recordRefund("__demo_cn__5", 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.recordRefund("__demo_cn__5", {
        comment: "Refunding as customer canceled the order.",
        transaction: {
            amount: 100,
            payment_method: "bank_transfer",
            date: 1517501412
        }
    });

    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()->recordRefund("__demo_cn__5", [
    "comment" => "Refunding as customer canceled the order.",
    "transaction" => [
        "amount" => 100,
        "payment_method" => "bank_transfer",
        "date" => 1517501412
    ]
]);
$creditNote = $result->credit_note;
$transaction = $result->transaction;
```

#### Python

```python
import chargebee
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.CreditNote.record_refund("__demo_cn__5",
    cb_client.CreditNote.RecordRefundParams(
        comment="Refunding as customer canceled the order.",
        transaction=cb_client.CreditNote.RecordRefundTransactionParams(
            amount=100,
            payment_method=chargebee.PaymentMethod.BANK_TRANSFER,
            date=1517501412
        )
    )
)
credit_note = response.credit_note
transaction = response.transaction
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::CreditNote.record_refund("__demo_cn__5",{
  :comment => "Refunding as customer canceled the order.",
  :transaction => {
    :amount => 100,
    :payment_method => "BANK_TRANSFER",
    :date => 1517501412
  }
})

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

## Sample Response

```json
{
  "credit_note": {
    "allocations": {},
    "amount_allocated": 0,
    "amount_available": 400,
    "amount_refunded": 100,
    "base_currency_code": "USD",
    "create_reason_code": "Product Unsatisfactory",
    "currency_code": "USD",
    "customer_id": "__test__KyVnHhSBWT0B66o",
    "date": 1517501412,
    "deleted": false,
    "exchange_rate": 1,
    "fractional_correction": 0,
    "id": "__demo_cn__5",
    "line_item_discounts": {},
    "line_item_taxes": {},
    "line_items": [
      {
        "amount": 500,
        "customer_id": "__test__KyVnHhSBWT0B66o",
        "date_from": 1517501412,
        "date_to": 1517501412,
        "description": "Support Charge",
        "discount_amount": 0,
        "entity_type": "adhoc",
        "id": "li___test__KyVnHhSBWT0IE71",
        "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": 500
      },
      {..}
    ],
    "linked_refunds": [
      {
        "applied_amount": 100,
        "applied_at": 1517501412,
        "txn_amount": 100,
        "txn_date": 1517501412,
        "txn_id": "txn___test__KyVnHhSBWT0Jm75",
        "txn_status": "success"
      },
      {..}
    ],
    "object": "credit_note",
    "price_type": "tax_exclusive",
    "reason_code": "product_unsatisfactory",
    "reference_invoice_id": "__demo_inv__5",
    "resource_version": 1517501413000,
    "round_off_amount": 0,
    "status": "refund_due",
    "sub_total": 500,
    "taxes": {},
    "total": 500,
    "type": "refundable",
    "updated_at": 1517501413
  },
  "transaction": {
    "amount": 100,
    "base_currency_code": "USD",
    "currency_code": "USD",
    "customer_id": "__test__KyVnHhSBWT0B66o",
    "date": 1517501412,
    "deleted": false,
    "exchange_rate": 1,
    "gateway": "not_applicable",
    "id": "txn___test__KyVnHhSBWT0Jm75",
    "linked_credit_notes": [
      {
        "applied_amount": 100,
        "applied_at": 1517501412,
        "cn_create_reason_code": "Product Unsatisfactory",
        "cn_date": 1517501412,
        "cn_id": "__demo_cn__5",
        "cn_reason_code": "product_unsatisfactory",
        "cn_reference_invoice_id": "__demo_inv__5",
        "cn_status": "refund_due",
        "cn_total": 500
      },
      {..}
    ],
    "object": "transaction",
    "payment_method": "bank_transfer",
    "resource_version": 1517501413000,
    "status": "success",
    "type": "refund",
    "updated_at": 1517501413
  }
}
```

## URL Format

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

## Input Parameters

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

- `comment` (optional, string, max chars=300)
  Remarks, if any, on the refund.

- `transaction` (optional, string)
  Parameters for transaction
  - `id` (optional, string, max chars=40)
    The payment transaction ID.
  - `amount` (optional, in cents, min=0)
    The amount to be recorded as refunded. If not specified, the entire [refundable amount](/docs/api/credit_notes/credit_note-object#amount_available) for this `credit_note` is assumed.
  - `payment_method` (required, enumerated string)
    The payment method of this transaction
    Possible enum values:
      - `cash`
        Cash
      - `check`
        Check
      - `chargeback`
        Only applicable for a transaction of `[type](/docs/api/transactions/transaction-object#type)` = `refund`. This value is set by Chargebee when an automated [chargeback](https://www.chargebee.com/docs/chargeback.html#chargeback-process) occurs. You can also set this explicitly when [recording a refund](/docs/api/transactions/record-an-offline-refund) .
      - `bank_transfer`
        Bank Transfer
      - `other`
        Payment Methods other than the above types
      - `custom`
        Custom
      - `dana`
      - `touch_n_go`
      - `tamara`
      - `qpay`
      - `ovo`
      - `momo`
      - `mercado_pago`
      - `nequi`
      - `nupay`
      - `picpay`
      - `thai_qr`
      - `blik`
      - `fpx`
      - `wero`
      - `p24`
      - `affirm_pay`
      - `rakuten_pay`
  - `reference_number` (optional, string, max chars=100)
    The reference number for this transaction. For example, the check number when `[payment_method](/docs/api/transactions/transaction-object#payment_method)` = `check` .
  - `custom_payment_method_id` (optional, string, max chars=50)
    Identifier of the custom payment method of this transaction.
  - `date` (required, timestamp(UTC) in seconds)
    Indicates when this transaction occurred.

## Returns

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

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