# Refund a payment

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


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

Refunds an online payment. Applicable only for `transaction`s of `[type](/docs/api/transactions/transaction-object#type)` = `payment`. You can only refund a `transaction` whose `[status](/docs/api/transactions/transaction-object#status)` is `success`.

-   Not supported for ach\_credit, sepa\_credit, cash, check, bank\_transfer, other.
-   Contact [Chargebee Support](https://www.chargebee.com/docs/billing/2.0/kb/getting-started/how-to-contact-chargebees-support-team?utm_source=docs_api&utm_medium=content&utm_campaign=support) to enable this endpoint.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/transactions/txn___test__KyVnpGSCut0cY8/refund \
     -u {site_api_key}:\
     -d comment="Refunding a transaction"
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Transaction.Refund("txn___test__KyVnpGSCut0cY8")
		.Comment("Refunding a transaction")
		.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"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := transactionAction.Refund("txn___test__KyVnpGSCut0cY8", &transaction.RefundRequestParams{
        Comment : "Refunding a transaction",
    }).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.TransactionRefundRequest{
    Comment : "Refunding a transaction",
}
  res, err := client.Transaction.Refund("txn___test__KyVnpGSCut0cY8", 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;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = Transaction.refund("txn___test__KyVnpGSCut0cY8")
            .comment("Refunding a transaction")
            .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.TransactionRefundParams;
import com.chargebee.v4.models.transaction.responses.TransactionRefundResponse;

public class TransactionRefund {

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

        TransactionRefundParams params = TransactionRefundParams.builder()
            .comment("Refunding a transaction")
            .build();

        TransactionRefundResponse response = client
            .transactions()
            .refund("txn___test__KyVnpGSCut0cY8", 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.refund("txn___test__KyVnpGSCut0cY8", {
        comment: "Refunding a transaction"
    });

    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()->refund("txn___test__KyVnpGSCut0cY8", [
    "comment" => "Refunding a transaction"
]);
$transaction = $result->transaction;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Transaction.refund("txn___test__KyVnpGSCut0cY8",
    cb_client.Transaction.RefundParams(
        comment="Refunding a transaction"
    )
)
transaction = response.transaction
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Transaction.refund("txn___test__KyVnpGSCut0cY8",{
  :comment => "Refunding a transaction"
})

transaction = result.transaction
```

## Sample Response

```json
{
  "transaction": {
    "amount": 1000,
    "currency_code": "USD",
    "customer_id": "__test__KyVnpGSCuszos1",
    "date": 1517482377,
    "deleted": false,
    "exchange_rate": 1,
    "gateway": "stripe",
    "gateway_account_id": "gw___test__KyVnw0SCuszXd2I",
    "id": "txn___test__KyVnpGSCut11oF",
    "id_at_gateway": "re_1HaJDZJv9j0DyntJA2VZNft4",
    "linked_credit_notes": {},
    "masked_card_number": "************1111",
    "object": "transaction",
    "payment_method": "card",
    "payment_source_id": "pm___test__KyVnpGSCut0FD2",
    "reference_transaction_id": "txn___test__KyVnpGSCut0cY8",
    "refunded_txn_id": "txn___test__KyVnpGSCut0cY8",
    "resource_version": 1517482378000,
    "status": "success",
    "type": "refund",
    "updated_at": 1517482378
  }
}
```

## URL Format

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

## Input Parameters

- `amount` (optional, in cents, min=1)
  The amount to be 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 refunded.

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

## Returns

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