# Using the Public API for checkout

Use the CPAY Public API for checkout creating. When you create a charge, we generate payment addresses on your behalf for each cryptocurrency that’s enabled and provide you with a hosted page you can send to customers to complete the payment.

### Login to merchant

You need to get api keys for your merchant and login to your merchant in order to get the token necessary for creating checkout and further actions on them.

## Endpoint POST /public/auth

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

Endpoint allows you to log in to the system under the merchant. publicKey and privateKey can be obtained from the merchant. There is a corresponding endpoint that generates these keys for the merchant.

#### Request Body

| Name                                          | Type   | Description |
| --------------------------------------------- | ------ | ----------- |
| 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 If request body parameters are empty or have incorrect type (not string)" %}

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

{% endtab %}

{% tab title="401: Unauthorized If you use incorrect merchant token" %}

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

{% endtab %}
{% endtabs %}

### Checkout(donation) creating

## Endpoint POST /api/public/checkout/donation

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

You need to log in to the merchant.

#### Request Body

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

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

```javascript
{
  "data": {
    "identifier": "string",
    "merchant": {},
    "createdAt": "2021-10-04T14:20:37.949Z",
    "updatedAt": "2021-10-04T14:20:37.949Z",
    "organizationName": "string",
    "description": "string"
  }
}
```

{% endtab %}

{% tab title="400: Bad Request If request body parameters are empty or have incorrect type (not string)" %}

```javascript
{
    "status": "fail",
    "data": {
        "message": [
            "organizationName should not be empty",
            "description must be a string"
        ]
    }
}
```

{% endtab %}

{% tab title="401: Unauthorized If you use incorrect merchant token" %}

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

{% endtab %}
{% endtabs %}

### Checkout(sale) creating

## Endpoint /api​/public​/checkout​/sale

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

You need to log in to the merchant.

#### Request Body

| Name                                           | Type   | Description             |
| ---------------------------------------------- | ------ | ----------------------- |
| productName<mark style="color:red;">\*</mark>  | String |                         |
| description<mark style="color:red;">\*</mark>  | String |                         |
| price<mark style="color:red;">\*</mark>        | number | must not be less than 1 |
| fiatCurrency<mark style="color:red;">\*</mark> | string | must be only USD        |

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

```javascript
{
  "data": {
    "identifier": "string",
    "merchant": {},
    "createdAt": "2021-10-04T14:42:12.328Z",
    "updatedAt": "2021-10-04T14:42:12.328Z",
    "productName": "string",
    "description": "string",
    "price": 0,
    "fiatCurrency": "string"
  }
}
```

{% endtab %}

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

```javascript
{
    "status": "fail",
    "data": {
        "message": [
            "description should not be empty",
            "price must not be less than 1",
            "price must be a number conforming to the specified constraints",
            "fiatCurrency must be a valid enum value"
        ]
    }
}
```

{% endtab %}

{% tab title="401 " %}

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

{% endtab %}
{% endtabs %}

### Get all checkouts list

## Endpoint /api/public/checkout

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

You need to log in to the merchant.

#### Query Parameters

| Name  | Type   | Description                                     |
| ----- | ------ | ----------------------------------------------- |
| order | string | Available values: ASC, DESC. Defaule value: ASC |
| page  | number | Default value: 1                                |
| limit | number | Default value : 10                              |

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

```
{
  "data": {
    "page": 0,
    "pages": 0,
    "countItems": 0,
    "entities": [
      {
        "identifier": "string",
        "merchant": {},
        "createdAt": "2021-10-04T14:50:27.706Z",
        "updatedAt": "2021-10-04T14:50:27.706Z"
      }
    ]
  }
}
```

{% endtab %}

{% tab title="401 " %}

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

{% endtab %}
{% endtabs %}

### Get a specific checkout

## Endpoint /api/public/checkout/{checkoutId}

<mark style="color:blue;">`GET`</mark> `https://api.cpay.world/api/public/checkout/{checkoutId}`

You need to log in to the merchant.

#### Path Parameters

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

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

```
{
  "data": {
    "identifier": "string",
    "merchant": {},
    "createdAt": "2021-10-04T15:49:56.601Z",
    "updatedAt": "2021-10-04T15:49:56.601Z"
  }
}
```

{% endtab %}

{% tab title="401 " %}

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

{% endtab %}

{% tab title="404 " %}

```
{
    "status": "fail",
    "data": {
        "message": "Checkout not found."
    }
}
```

{% endtab %}
{% endtabs %}

### Checkout deleting

## Endpoint /api/public/checkout{checkoutId}

<mark style="color:red;">`DELETE`</mark> `https://api.cpay.world/api/public/checkout{checkoutId}`

You need to log in to the merchant.

#### Path Parameters

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

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

```
{
  "data": true
}
```

{% endtab %}

{% tab title="401 " %}

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

{% endtab %}

{% tab title="404 " %}

```
{
    "status": "fail",
    "data": {
        "message": "Checkout not found."
    }
}
```

{% endtab %}
{% endtabs %}

### Checkout(donation) editing

## Endpoint PATCH /api/public/checkout/{checkoutId}/donation

<mark style="color:purple;">`PATCH`</mark> `https://api.cpay.world/api/public/checkout/{checkoutId}/donation`

You need to log in to the merchant.

#### Path Parameters

| Name       | Type   | Description |
| ---------- | ------ | ----------- |
| checkoutId | string |             |

#### Request Body

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

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

```
{
  "data": {
    "identifier": "string",
    "merchant": {},
    "createdAt": "2021-10-04T16:08:23.049Z",
    "updatedAt": "2021-10-04T16:08:23.049Z",
    "organizationName": "string",
    "description": "string"
  }
}
```

{% endtab %}

{% tab title="400 " %}

```
{
    "status": "fail",
    "data": {
        "message": [
            "organizationName should not be empty",
            "description must be a string"
        ]
    }
}
```

{% endtab %}

{% tab title="401 " %}

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

{% endtab %}

{% tab title="404 " %}

```
{
    "status": "fail",
    "data": {
        "message": "Checkout not found."
    }
}
```

{% endtab %}
{% endtabs %}

### Checkout(sale) editing

## Endpoint PATCH /api/public/checkout/{checkoutId}/sale

<mark style="color:purple;">`PATCH`</mark> `https://api.cpay.world/api/public/checkout/{checkoutId}/sale`

You need to log in to the merchant.

#### Path Parameters

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

#### Request Body

| Name                                           | Type   | Description             |
| ---------------------------------------------- | ------ | ----------------------- |
| productName<mark style="color:red;">\*</mark>  | string |                         |
| description<mark style="color:red;">\*</mark>  | string |                         |
| price<mark style="color:red;">\*</mark>        | number | must not be less than 1 |
| fiatCurrency<mark style="color:red;">\*</mark> | string | must be only USD        |

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

```
{
  "data": {
    "identifier": "string",
    "merchant": {},
    "createdAt": "2021-10-04T16:18:44.588Z",
    "updatedAt": "2021-10-04T16:18:44.588Z",
    "productName": "string",
    "description": "string",
    "price": 0,
    "fiatCurrency": "string"
  }
}
```

{% endtab %}

{% tab title="400 " %}

```
{
    "status": "fail",
    "data": {
        "message": [
            "description should not be empty",
            "price must not be less than 1",
            "price must be a number conforming to the specified constraints",
            "fiatCurrency must be a valid enum value"
        ]
    }
}
```

{% endtab %}

{% tab title="401 " %}

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

{% endtab %}

{% tab title="404 " %}

```
{
    "status": "fail",
    "data": {
        "message": "Checkout not found."
    }
}
```

{% endtab %}
{% endtabs %}

A checkout object is returned with a URL to a hosted page where a customer can complete their charge. The customer is able to send any amount for donation or fixed amount for sale.

## Receive a payment

After creating a charge, Coinbase Commerce will continuously monitor each blockchain network for a payment. Since cryptocurrencies are push payments, we set an expiration time for the charge which is currently 1 hour after the creation date. If the customer does not make a payment within that timeframe, we consider the charge to be expired.

After the user opens the widget, two requests are sent: the first to receive the chargeId, and the second to receive all the information on the charge.

### Get the chargeId

## Endpoint /api/checkout-client/{identifier}/charge

<mark style="color:green;">`POST`</mark> `https://api.cpay.world/api/checkout-client/{identifier}/charge`

#### Path Parameters

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

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

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

{% endtab %}

{% tab title="404 " %}

```
{
    "status": "fail",
    "data": {
        "message": "Checkout not found."
    }
}
```

{% endtab %}
{% endtabs %}

### Get the charge

## Endpoint /api/checkout-client/{chargeId}/charge

<mark style="color:blue;">`GET`</mark> `https://api.cpay.world​/api​/checkout-client​/{chargeId}​/charge`

#### Path Parameters

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

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

```
{
  "data": {
    "id": "string",
    "typeNetwork": "string",
    "expiredDate": "string",
    "systemStatus": "string",
    "checkout": {
      "type": "string",
      "organizationName": "string",
      "description": "string"
    },
    "wallets": [
      {
        "address": "string",
        "currency": {
          "name": "string",
          "title": "string",
          "nodeType": "string",
          "currencyType": "string"
        }
      }
    ],
    "replenish": {
      "price": 0,
      "currency": "string",
      "amount": {
        "value": 0,
        "usd": 0
      }
    }
  }
}
```

{% endtab %}

{% tab title="401 " %}

```
{
    "status": "fail",
    "data": {
        "message": "Charge not found."
    }
}
```

{% endtab %}
{% endtabs %}

Also you can get information about checkout by identifier

## Endpoint /api/checkout-client/{identifier}

<mark style="color:blue;">`GET`</mark> `https://api.cpay.world/api​/checkout-client​/{identifier}`

#### Path Parameters

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

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

```
{
  "data": {
    "type": "string",
    "organizationName": "string",
    "description": "string"
  }
}
```

{% endtab %}

{% tab title="404 " %}

```
{
    "status": "fail",
    "data": {
        "message": "Checkout not found."
    }
}
```

{% endtab %}
{% endtabs %}

The user opens a charge with an available list of currencies and expired time. After selecting the currency, a unique client wallet is generated. In this case, the status of the charge is accepted as New. When the user sends funds to the selected wallet, the charge status is accepted as Pending. After successful payment, the status of the charge is accepted as Done. If the user has not paid for the charge at the specified time, then the status of the charge is accepted as Expired. If any error or failure has occurred in the network, then the status of the transaction is accepted as Failed. After successful replenishment, the user needs to click on the "Back" button to generate new wallets or replenish the previous wallet, but in this case the transaction will not be displayed in the widget.


---

# 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://cpay-2.gitbook.io/cpay-1/public-api/using-the-public-api-for-checkout.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.
