# Record an offline refund

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


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

Records a refund made offline. Applicable only for `transaction`s of `[type](/docs/api/transactions/transaction-object#type)` = `payment`.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/transactions/txn___test__KyVnHhSBWlwT42q7/record_refund \
     -u {site_api_key}:\
     -d date=1601054726 \
     -d amount=1000 \
     -d payment_method="CHARGEBACK" \
     -d reference_number="5266787652" \
     -d comment="payment disputed"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Transaction.RecordRefund("txn___test__KyVnHhSBWlwT42q7")
		.Date(1601054726)
		.Amount(1000)
		.PaymentMethod(PaymentMethodEnum.Chargeback)
		.ReferenceNumber("5266787652")
		.Comment("payment disputed")
		.Request();

Transaction transaction = result.Transaction;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    transactionAction "github.com/chargebee/chargebee-go/v3/actions/transaction"
    "github.com/chargebee/chargebee-go/v3/models/transaction"
    enum "github.com/chargebee/chargebee-go/v3/enum"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := transactionAction.RecordRefund("txn___test__KyVnHhSBWlwT42q7", &transaction.RecordRefundRequestParams{
        Date : chargebee.Int64(1601054726),
        Amount : chargebee.Int64(1000),
        PaymentMethod : enum.PaymentMethodChargeback,
        ReferenceNumber : "5266787652",
        Comment : "payment disputed",
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        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.TransactionRecordRefundRequest{
    Date : chargebee.Int64(1601054726),
    Amount : chargebee.Int64(1000),
    PaymentMethod : chargebee.PaymentMethodChargeback,
    ReferenceNumber : "5266787652",
    Comment : "payment disputed",
}
  res, err := client.Transaction.RecordRefund("txn___test__KyVnHhSBWlwT42q7", req)
      if err != nil {
        fmt.Println(err)
    } else {
        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 = Transaction.recordRefund("txn___test__KyVnHhSBWlwT42q7")
            .date(new Timestamp(1601054726L * 1000))
            .amount(1000L)
            .paymentMethod(PaymentMethod.CHARGEBACK)
            .referenceNumber("5266787652")
            .comment("payment disputed")
            .request();

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

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.transaction.Transaction;
import com.chargebee.v4.models.transaction.params.TransactionRecordRefundParams;
import com.chargebee.v4.models.transaction.responses.TransactionRecordRefundResponse;
import java.sql.Timestamp;

public class TransactionRecordRefund {

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

        TransactionRecordRefundParams params = TransactionRecordRefundParams.builder()
            .date(new Timestamp(1601054726L * 1000))
            .amount(1000L)
            .paymentMethod(TransactionRecordRefundParams.PaymentMethod.CHARGEBACK)
            .referenceNumber("5266787652")
            .comment("payment disputed")
            .build();

        TransactionRecordRefundResponse response = client
            .transactions()
            .recordRefund("txn___test__KyVnHhSBWlwT42q7", params);

        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.transaction.recordRefund("txn___test__KyVnHhSBWlwT42q7", {
        date: 1601054726,
        amount: 1000,
        payment_method: "chargeback",
        reference_number: "5266787652",
        comment: "payment disputed"
    });

    console.log(result);
    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->transaction()->recordRefund("txn___test__KyVnHhSBWlwT42q7", [
    "date" => 1601054726,
    "amount" => 1000,
    "payment_method" => "chargeback",
    "reference_number" => "5266787652",
    "comment" => "payment disputed"
]);
$transaction = $result->transaction;
```

#### Python

```python
import chargebee
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Transaction.record_refund("txn___test__KyVnHhSBWlwT42q7",
    cb_client.Transaction.RecordRefundParams(
        date=1601054726,
        amount=1000,
        payment_method=chargebee.PaymentMethod.CHARGEBACK,
        reference_number="5266787652",
        comment="payment disputed"
    )
)
transaction = response.transaction
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Transaction.record_refund("txn___test__KyVnHhSBWlwT42q7",{
  :date => 1601054726,
  :amount => 1000,
  :payment_method => "CHARGEBACK",
  :reference_number => "5266787652",
  :comment => "payment disputed"
})

transaction = result.transaction
```

## Sample Response

```json
{
  "transaction": {
    "amount": 1000,
    "currency_code": "USD",
    "customer_id": "__test__KyVnHhSBWlwHl2q0",
    "date": 1601054726,
    "deleted": false,
    "exchange_rate": 1,
    "gateway": "not_applicable",
    "id": "txn___test__KyVnHhSBWlwhi2qE",
    "linked_credit_notes": {},
    "object": "transaction",
    "payment_method": "chargeback",
    "reference_number": "5266787652",
    "reference_transaction_id": "txn___test__KyVnHhSBWlwT42q7",
    "resource_version": 1517505927000,
    "status": "success",
    "type": "refund",
    "updated_at": 1517505927
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/transactions/{transaction-id}/record_refund

## Input Parameters

- `amount` (optional, in cents, min=1)
  The amount to be recorded as refunded. Must not exceed `[amount_unused](/docs/api/transactions/transaction-object#amount_unused)`. If not passed then all of `[amount_unused](/docs/api/transactions/transaction-object#amount_unused)` is recorded as refunded.

- `payment_method` (required, enumerated string)
  The payment method used to make the refund.
  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`

- `date` (required, timestamp(UTC) in seconds)
  The date when the refund was made.

- `reference_number` (optional, string, max chars=100)
  The reference number for this transaction. For example, the check number when `payment_method` = `check` .

- `custom_payment_method_id` (optional, string, max chars=50)
  Identifier of the custom payment method of this transaction.

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

## Returns

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