> For the complete documentation index, see [llms.txt](https://cpay-2.gitbook.io/cpay-1/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cpay-2.gitbook.io/cpay-1/public-api/using-the-public-api-for-public-wallet.md).

# Using the Public API for public wallet

You can integrate CPAY in your system as payment method. After you've signed up you should to create a merchant and get API keys for client(public) wallet creation in your system.

### Client wallet creating

## Endpoint POST ​/api​/public​/wallet​/{currencyId}

<mark style="color:green;">`POST`</mark> `https://api.cpay.world/api​/public​/wallet​/{currencyId}`

You need to log in to the merchant.

#### Path Parameters

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

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

```javascript
{
  "data": {
    "id": "string",
    "address": "string",
    "balance": 0,
    "balanceUSD": 0,
    "passphrase": "string"
  }
}
```

{% endtab %}

{% tab title="400: Bad Request " %}

```javascript
{
    "message": "This currency is not supported."
}
```

{% endtab %}

{% tab title="401 " %}

```javascript
{
    "status": "fail",
    "data": {
        "message": "Unauthorized"
    }
}
```

{% endtab %}
{% endtabs %}

You can login to wallet and get wallet access token necessary for witdrawal from wallet and for getting wallet ballance. You need to get api keys for your merchant, also you need wallet Id and wallet passphrase.

### Wallet login

## Endpoint POST /api/public/auth

<mark style="color:green;">`POST`</mark> `https://api.cpay.world/api/public/auth`

#### Request Body

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

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

```javascript
{
  "token": "string"
}
```

{% endtab %}

{% tab title="400: Bad Request " %}

```javascript
{
    "status": "fail",
    "data": {
        "message": [
            "publicKey should not be empty"
        ]
    }
}
```

{% endtab %}

{% tab title="401: Unauthorized " %}

```javascript
{
    "status": "fail",
    "data": {
        "message": "Unauthorized"
    }
}
```

{% endtab %}
{% endtabs %}

### Withdrawal from public wallet

## Endpoint POST ​/api​/public​/withdrawal

<mark style="color:green;">`POST`</mark> `https://api.cpay.world​/api​/public​/withdrawal`

Endpoint allows you to withdraw funds to another wallet outside the system. The header contains the Bearer token, which can be obtained upon authorization under the merchant in conjunction with the wallet. You need to log in with the wallet in conjunction with the merchant.

#### Request Body

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

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

```javascript
{
  "data": {
    "id": "string"
  }
}
```

{% endtab %}

{% tab title="400: Bad Request " %}

```javascript
{
  "data": {
    "id": "string"
  }
}
```

{% endtab %}

{% tab title="401 " %}

```javascript
{
    "status": "fail",
    "data": {
        "message": "Unauthorized"
    }
}
```

{% endtab %}
{% endtabs %}

### Get wallet ballance

## Endpoint GET ​/api​/public​/wallet

<mark style="color:blue;">`GET`</mark> `https://api.cpay.world/api/public/wallet`

The endpoint allows you to get the current balance of the wallet. You need to log in with the wallet in conjunction with the merchant.

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

```javascript
{
  "data": {
    "balance": 0,
    "balanceUSD": 0
  }
}
```

{% endtab %}

{% tab title="401: Unauthorized " %}

```javascript
{
    "status": "fail",
    "data": {
        "message": "Unauthorized"
    }
}
```

{% endtab %}
{% endtabs %}
