# Payment API

## General Information

{% hint style="danger" %}
AquaPay will recycle the generated payment address. Please DO NOT keep it for a prolonged period of time for receiving additional deposits.
{% endhint %}

## Create Payment Bill

<mark style="color:green;">`POST`</mark> `https://api.aquanow.io/payment/v1/requestPaymentAddress`

This endpoint allows you request a payment address by using a fiat quantity (*fiatReceivable*) to generate the executable price.

#### Request Body

| Name                                             | Type    | Description                                                                                                                               |
| ------------------------------------------------ | ------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| cryptoType<mark style="color:red;">\*</mark>     | string  | Symbol deposited ie. "BTC". Look at Crypto & Currency Support for a full list of supported cryptos.                                       |
| fiat<mark style="color:red;">\*</mark>           | string  | Designated currency which the cryptocurrency will be converted into. Look at Crypto & Currency Support for a full list of supported fiat. |
| fiatReceivable<mark style="color:red;">\*</mark> | number  | Amount (in fiat) you want to receive as a result of payment execution.                                                                    |
| subaccount<mark style="color:red;">\*</mark>     | string  | Payment service provider's user who initiate the deposit request.                                                                         |
| networkType                                      | enum    | Network Type of `USDT`. `eth` or `tron`. Default to `eth`.                                                                                |
| bech32                                           | boolean | Defaults to false. If set to true, it will return **bech32 segwit address** for BTC address, or **BCH cash address** for BCH.             |
| strategy                                         | enum    | `"RAI" \| "LMT" \| "ACA"`. See below for more information.                                                                                |
| feeModel                                         | enum    | `"SPREAD" \| "EXPLICIT"`. See below for more information                                                                                  |

{% tabs %}
{% tab title="200 Successfully created using ETH" %}

```javascript
{
    "deposit_address": "0xfbc341964BC644944EDfE51798CEb441260B0CcC",
    "price": 2994.8982,
    "quantity": 0.004123,
    "expiryTime": 1632197603530
}
```

{% endtab %}

{% tab title="400 If you provide a networkType that does not exist." %}

```javascript
{
    "message": "Provided network type does not exist"
}
```

{% endtab %}
{% endtabs %}

## Get Payment

<mark style="color:blue;">`GET`</mark> `https://api.aquanow.io/payment/v1/payment`

Get all payment bills by time range, address or paymentId.

#### Query Parameters

| Name        | Type   | Description                                                     |
| ----------- | ------ | --------------------------------------------------------------- |
| startTime   | number | Time in epoch. Required when query for all bills by time range. |
| endTime     | number | Time in epoch. Must within 90 days of startTime.                |
| startsAfter | string | Pagination token                                                |
| address     | string | Query for all bills under an address                            |
| paymentId   | string | Query for single bill                                           |

{% tabs %}
{% tab title="200: OK " %}

```javascript
{
    "data": [
        {
            "quantity": 0.00048385,
            "paymentId": "1dad9864-a235-47f5-997a-b4674fda3e42",
            "subaccount": "testing-event-4",
            "fiatReceivable": 1,
            "symbol": "ETH",
            "createdAt": 1662576446318,
            "fiat": "CAD",
            "address": "0xaf91e342A29D92C7667D85782C36a0D806529025_ETH",
            "paymentStatus": "DONE",
            "updatedAt": 1662576446318,
            "expirationTime": 1662577646316,
            "tradePrice": 2066.75820001996,
            "username": "jeffen",
            "transactions": [
                {
                    "quantity": 0.001,
                    "sourceAddress": "0xf6aCc5f06BCE41860B425bcaDfD7ce5ABcc19ECa",
                    "paymentId": "1dad9864-a235-47f5-997a-b4674fda3e42",
                    "subaccount": "testing-event-4",
                    "fiatReceivable": 1,
                    "executableQuantity": 0.00048385,
                    "txId": "7170e2da-2b68-4abd-bc9e-16dd057e7051",
                    "symbol": "ETH",
                    "txHash": "0xf29ebf7ccb1b9c993ecb49ad1e4641a566af98a3886abda89f723b578eca576e",
                    "createdAt": 1662576607008,
                    "fiat": "CAD",
                    "txTime": 1662576704421,
                    "address": "0xaf91e342A29D92C7667D85782C36a0D806529025",
                    "fiatReceived": 1,
                    "transactionType": "DEPOSIT",
                    "riskLevel": 0,
                    "tradePrice": 2066.75820001996,
                    "username": "jeffen",
                    "adminApproval": "DONE",
                    "quantityReceived": 0.001,
                    "quantityConverted": 0.00048385,
                    "quantityUnconverted": 0.00051615
                }
            ],
            "summary": {
                "fiatReceivable": 1,
                "riskLevel": 0,
                "quantityReceived": 0.001,
                "quantityConverted": 0.00048385,
                "quantityUnconverted": 0.00051615,
                "quantityConvertible": 0.00051615,
                "fiatReceived": 1,
                "fiatConverted": 0
            }
        }
    ],
    "pagination": {
        "startsAfter": "eyJ0eElkIjoiNTg2YjZiZWUtNjAzMy00OThjLTlkMzEtZjQyYTBmNTAzMDMxIn0="
    }
}
```

{% endtab %}
{% endtabs %}

## Payment Strategy

#### Default

Request parameter: `"RFQ"`. Applicable for all supported coins. Received crypto deposits are converted to fiat when the bill is within the expiry time.

#### Receive As Is

Request parameter: `"RAI"`. Applicable for all supported coins. Received crypto deposits are not converted to fiat.

#### Always Convert All

Request parameter: `"ACA"`. Applicable for all supported coins. All received crypto will be converted by RFQ or market order to fiat depending on the bill expiry time.

#### Limit Price

Request parameter: `"LMT"`. Only applicable to stablecoins, i.e. `USDC` and `USDT` as a risk factor. Received crypto deposits will be converted to fiat only when the guaranteed trade price in bill is better than the user-configured limit price. Crypto deposits received after the bill expiry time are not converted to fiat.

{% hint style="info" %}
Unconverted payments received through the RAI and LMT strategies are subject to a transaction fee.
{% endhint %}

## Fee Model

#### Default

Request parameter: `"SPREAD"`. Service fee is charged by spread.

#### Explicit Fee

Request parameter: `"EXPLICIT"`. Service fee is charged by crypto amount from the conversion. Not affecting non-conversion transactions. Not supported by `ACA` strategy market order yet.

## Supported Network Types

For symbols that support multiple networks, please specify `networkType` parameter in request body. If you provide a network type for a symbol that is NOT USDT, a **400 HTTP** error will be thrown with the response.

| CryptoType | NetworkType     | Description      |
| ---------- | --------------- | ---------------- |
| USDT       | `eth` (Default) | Ethereum network |
| USDT       | `tron`          | Tron network     |
