# Simulate Debits

A debit is a request by a merchant to charge a virtual card. The debit must be associated with a previously created authorization.

## Create a Simulated Debit

A simulated debit is created by calling the simulate debit API and supplying the identifier of the authorization and the amount to be debited.

The `authorizationId` is the identifier of an authorization that was created by calling the [Create a Simulated Authorization](https://docs.sudoplatform.com/guides/manage-authorizations#create-a-simulated-authorization) 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 debit is:

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

```typescript
try {
  const result = await simulatorClient.simulateDebit({
    authorizationId: authorization.id,
    amount: 1200,
  })
} catch (error) {
  // Handle error
}
```

{% endtab %}

{% tab title="Swift" %}

```swift
do {
    let debitInput = SimulateDebitInput(
        amount: 1200,
        authorizationId: authorization.id
    )
    let response = try await simulatorClient.simulateDebitWithInput(
        debitInput
    )
    // Debit has been created
} catch let error {
    // Handle/notify the user of error
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val debitInput = SimulateDebitInput(
    authorizationId = authorization.id,
    amount = 1200
)
launch {
    try {
        val debit = withContext(Dispatchers.IO) {
            simulatorClient.simulateDebit(debitInput)
        }
        // Debit has been created
    } catch (e: DebitException) {
        // Handle/notify the user of exception
    }
}
```

{% endtab %}
{% endtabs %}

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