# Simulate Refunds

A refund is a request by a merchant to return money to a virtual card. The refund must be associated with a previously created debit.

## Create a Simulated Refund

A simulated refund is created by calling the simulate refund API and supplying the identifier of a previous debit and the amount to refund.

The `debitId` is the identifier of a debit that was created by calling the [Create a Simulated Debit](/guides/virtual-cards-simulator/manage-debits.md#create-a-simulated-debit) API. The `amount` supplied as input is expressed as a multiple of the smallest unit of currency the merchant accepts. For example if the currency is US dollar then the amount is the number of US cents.

An example implementation of creating a simulated refund is:

{% tabs %}
{% tab title="TypeScript" %}

```typescript
try {
  const result = await simulatorClient.simulateRefund({
    debitId: debit.id,
    amount: 1200,
  })
} catch (error) {
  // Handle error
}
```

{% endtab %}

{% tab title="Swift" %}

```swift
do {
    let refundInput = SimulateRefundInput(
        amount: 1200,
        debitId: debit.id
    )
    let response = try await simulatorClient.simulateRefundWithInput(
        refundInput
    )
    // Refund has been created
} catch let error {
    // Handle/notify the user of error
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val refundInput = SimulateRefundInput(
    debitId = debit.id,
    amount = 1200
)
launch {
    try {
        val refund = withContext(Dispatchers.IO) {
             simulatorClient.simulateRefund(refundInput)
        }
        // Refund has been created
    } catch (e: RefundException) {
        // Handle/notify the user of exception
    }
}
```

{% endtab %}
{% endtabs %}

This API call creates a simulated refund against a virtual card. If an exception occurs, the error or exception will contain a description of the fault that caused the exception.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sudoplatform.com/guides/virtual-cards-simulator/manage-refunds.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
