# Basic Fiat Operations

{% hint style="warning" %}
Every request listed on this page requires [authorization](https://docs.0xpay.app/public-api/endpoints/broken-reference) to be successfully completed.&#x20;
{% endhint %}

## Withdrawal fee

<mark style="color:blue;">`GET`</mark> `https://public.api.0xpay.app/merchants/withdrawals/fiat/fee`

This method is used to get a fee for sending a desired *amount of assets* (`ticker`) on a chosen *blockchain*. Learn how fees work [here](https://docs.0xpay.app/general/transaction-fees)

#### Request Body

| Name                                     | Type   | Description              |
| ---------------------------------------- | ------ | ------------------------ |
| ticker<mark style="color:red;">\*</mark> | string | KZT only                 |
| amount<mark style="color:red;">\*</mark> | string | amount in decimal format |

{% tabs %}
{% tab title="200: OK Fee value is calculated successfully" %}
{% code overflow="wrap" %}

```javascript
{
  "value":  "0.1" //decimal fee value
}
```

{% endcode %}
{% endtab %}

{% tab title="400: Bad Request Asset is not supported" %}
{% code title="Error codes:" overflow="wrap" %}

```json
{
    code: 0 
    description: "Asset not supported"
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Supported fiat assets

<mark style="color:blue;">`GET`</mark> `https://public.api.0xpay.app/merchants/assets/fiat`

This method is used to fetch all available fiat assets of your merchant.

{% tabs %}
{% tab title="200: OK Fee value is calculated successfully" %}
{% code overflow="wrap" %}

```javascript
//In response, you'll get an Array of all assets with their ticker , name, price, and blockchain network: 
[
    {
        "name": "Ukrainian hryvnia",
        "ticker": "UAH",
        "price": {
            "value": "40.21",
            "ticker": "USD"
        }
    }
    
    {
        "name": "Kazakhstan Tenhe",
        "ticker": "KZT",
        "price": {
            "value": "1640.21",
            "ticker": "USD"
        }
    }
]
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Send fiat (single tx)

<mark style="color:green;">`POST`</mark> `https://public.api.0xpay.app/merchants/withdrawals/fiat`

Creates an outgoing fiat transaction (for example, UAH or KZT payment to a banking card)&#x20;

**Amount limits:** \
**For KZT: 20000** KZT.

After creation, 0xpay API will produce [notifications](https://docs.0xpay.app/notifications#withdrawal) according to status updates on your withdrawal.

#### Request Body

| Name                                     | Type   | Description                                                                                                                                                                                            |
| ---------------------------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| ticker<mark style="color:red;">\*</mark> | string | **`UAH`**` ``or`` `**`KZT`**                                                                                                                                                                           |
| to<mark style="color:red;">\*</mark>     | string | Destination card address                                                                                                                                                                               |
| amount<mark style="color:red;">\*</mark> | string | amount in decimal format                                                                                                                                                                               |
| fee                                      | string | you can specify withdrawal fees that have to be greater than the actual fee, which can be useful for better fee calculation options on your side. If not the specified – fee will be set automatically |
| localId                                  | string | if was specified error will be thrown if not unique, can be useful on your side to avoid the [double-spend](https://en.wikipedia.org/wiki/Double-spending) issue                                       |
| meta                                     | string | *your metadata* that will be passed along to you later with a notification                                                                                                                             |

{% tabs %}
{% tab title="200: OK Transaction created & sent to processing" %}
{% code overflow="wrap" %}

```javascript
{
    "id": "123e4567-e89b-12d3-a456-426614174000" //internal ID has been assigned to the tx
}
```

{% endcode %}
{% endtab %}

{% tab title="400: Bad Request One of the following errors occured:" %}
{% code title="Error codes:" %}

```json
//List of error codes:
//0 - Local id already placed 
//1 – Not enough balance
//2 – Fee less than required
//3 – Withdraw limit exceeded
//4 – Merchant not found

{
    code: 0 
    description: "Local id already placed"
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Send fiat assets as batch (no amount limits)

<mark style="color:green;">`POST`</mark> `https://public.api.0xpay.app/merchants/withdrawals/fiat/batch`

Splits large fiat transactions into several smaller payments and sends them to destination. You can also send KZT transactions as a batch withdrawal, with amount limits ranging from **KZT 20000-299000.** &#x20;

After creation, 0xpay API will produce [notifications](https://docs.0xpay.app/notifications#fiat-batch-withdrawal) according to status updates on your withdrawal.

**Example:** You want to send KZT 100,000 to a banking card. Normally, that'd require creating 7 different requests of \~KZT 14,500. With batched payments, your transaction amount will be automatically split into smaller portions (13800 + 13611 + 14120 + 13900 + 13831 + 13822 + 8447 + 8469 = 100 000), then sent as a batch of payments.&#x20;

#### Request Body

| Name                                     | Type   | Description                                                                                                                                                                                            |
| ---------------------------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| ticker<mark style="color:red;">\*</mark> | string | `KZT`                                                                                                                                                                                                  |
| to<mark style="color:red;">\*</mark>     | string | Receiving card number                                                                                                                                                                                  |
| amount<mark style="color:red;">\*</mark> | string | amount in decimal format                                                                                                                                                                               |
| fee                                      | string | you can specify withdrawal fees that have to be greater than the actual fee, which can be useful for better fee calculation options on your side. If not the specified – fee will be set automatically |
| localId                                  | string | if was specified error will be thrown if not unique, can be useful on your side to avoid the [double-spend](https://en.wikipedia.org/wiki/Double-spending) issue                                       |
| meta                                     | string | *your metadata* that will be passed along to you later with a notification                                                                                                                             |

{% tabs %}
{% tab title="200: OK Transaction created & sent to processing" %}
{% code overflow="wrap" %}

```javascript
{
    "id": "123e4567-e89b-12d3-a456-426614174000" //internal ID has been assigned to the tx
}
```

{% endcode %}
{% endtab %}

{% tab title="400: Bad Request One of the following errors occured:" %}
{% code title="Error codes:" %}

```json
//List of error codes:
//0 - Local id already placed 
//1 – Not enough balance
//2 – Fee less than required
//3 – Withdraw limit exceeded
//4 – Merchant not found

{
    code: 0 
    description: "Local id already placed"
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Check details of fiat batch withdrawal and tx's status&#x20;

<mark style="color:blue;">`GET`</mark> `https://public.api.0xpay.app/merchants/withdrawals/fiat/batch/:id`

Send this request to receive info about all payments in a selected fiat batch withdrawals.&#x20;

#### Path Parameters

| Name                               | Type   | Description |
| ---------------------------------- | ------ | ----------- |
| <mark style="color:red;">\*</mark> | String |             |

{% tabs %}
{% tab title="200: OK Tx's details & statuses" %}
In response, you'll receive this information regarding each transaction from a selected batch withdrawal.

```
{
  id: string
  ticker: FiatBalanceTicker
  status: FiatWithdrawStatus
  to: { cardNumber?: string }
  time: number
  withdraws: Array<{ amount: string; id: string; fee: string; status: FiatWithdrawStatus }>
  localId?: string
  meta?: string
}
```

Example of such request:

{% code overflow="wrap" %}

```javascript
{
    "id": "bc5e1e74-8a8c-4b0e-96c3-941c9cd2ffcf",
    "ticker": "UAH",
    "status": "QUEUED",
    "to": {
        "cardNumber": "4441114418446124"
    },
    "time": 1677591616602,
    "withdraws": [
        {
            "id": "ffc06f31-df21-48ac-97c0-9044ae707543",
            "status": "QUEUED",
            "amount": "4769.05",
            "fee": "47.69"
        },
        {
            "id": "b87da903-c7b2-484f-953c-f5c5c8af1f8e",
            "status": "QUEUED",
            "amount": "4899.02",
            "fee": "48.99"
        },
        {
            "id": "b6fe2e07-5852-436e-bb36-6a311c194c63",
            "status": "QUEUED",
            "amount": "4844.04",
            "fee": "48.44"
        },
        {
            "id": "ad151b77-378a-44f2-b741-08da8f644f13",
            "status": "QUEUED",
            "amount": "487.89",
            "fee": "4.88"
        }
    ],
    "localId": "your_info_123",
    "meta": "your_info"
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Check details of fiat withdrawal and tx's status&#x20;

<mark style="color:blue;">`GET`</mark> `https://public.api.0xpay.app/merchants/withdrawals/fiat/:id`

Send this request to receive info about withdrawal. \
\
Statuses (strings):\
1\. "CREATED" – withdraw was just created\
2\. "QUEUED" – withdraw is in the queue and will be processed soon\
3\. "DONE" – final status, withdrawal happened\
4\. "FAILED" – final status, withdrawal not happened: something goes wrong, refunded to merchant's balance<br>

#### Path Parameters

| Name                               | Type   | Description |
| ---------------------------------- | ------ | ----------- |
| <mark style="color:red;">\*</mark> | String |             |

{% tabs %}
{% tab title="200: OK Tx's details & statuses" %}
In response, you'll receive this information regarding each transaction from a selected batch withdrawal.

```
{
  id: string
  ticker: FiatBalanceTicker
  status: FiatWithdrawStatus
  to: { cardNumber?: string }
  time: number
  amount: string 
  fee: string
  localId?: string
  meta?: string
}
```

Example of such request:

{% code overflow="wrap" %}

```javascript
{
    "id": "ffc06f31-df21-48ac-97c0-9044ae707543",
    "ticker": "UAH",
    "status": "QUEUED",
    "to": {
        "cardNumber": "4441114418446124"
    },
    "time": 1677591616602,
    "amount": "487.89",
    "fee": "4.88"
    "localId": "your_info_123",
    "meta": "your_info"
}
```

{% endcode %}
{% endtab %}
{% endtabs %}
