# Execute Payment External Platform (server-to-server)

This section of the documentation outlines the necessary steps for server-to-server payment initiation using the CoinbarPay API. It details the process of creating a new payment request and receiving a payment string token for transaction processing.

**Once the payment request is processed, the CoinbarPay API will return a response.** \
**This response includes a payment string token that represents the transaction.**

**The total amount is calculated by input\_coin and the products field, with the current conversion rate for the destination\_coin selected.**&#x20;

### Create new payment

To make the API request, use the following :

## Generate a new payment request token

<mark style="color:green;">`POST`</mark> `https://sandbox.coinbar.io/coinbar/api/v2/pay/gateway/initiate`

#### Headers

| Name                                            | Type   | Description                                                              |
| ----------------------------------------------- | ------ | ------------------------------------------------------------------------ |
| CBPAY-API-KEY<mark style="color:red;">\*</mark> | String | {{<mark style="color:purple;">`SERVICE_CLIENT_ID`</mark>}}               |
| Content-Type<mark style="color:red;">\*</mark>  | String | application/json                                                         |
| SIGNATURE<mark style="color:red;">\*</mark>     | String | <p>{{<code>SIGNATURE\_TOKEN</code>}}<br>HMAC SHA-256 body validation</p> |
| source<mark style="color:red;">\*</mark>        | String | String "web"                                                             |

#### Request Body

| Name                                                   | Type   | Description                                                                                                                                      |
| ------------------------------------------------------ | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| service\_client\_id<mark style="color:red;">\*</mark>  | String | {{<mark style="color:purple;">`SERVICE_CLIENT_ID`</mark>}}                                                                                       |
| payment\_request\_id<mark style="color:red;">\*</mark> | String | Generated by Your application                                                                                                                    |
| input\_coin<mark style="color:red;">\*</mark>          | String | `"EUR"`                                                                                                                                          |
| products<mark style="color:red;">\*</mark>             | Array  | <p>Products, can be provided products details or just one product with total billing receipt. <br><br>See the section below for more details</p> |
| email<mark style="color:red;">\*</mark>                | String | Customer email                                                                                                                                   |
| surname                                                | String | Customer Last Name                                                                                                                               |
| name                                                   | String | Customer Name                                                                                                                                    |
| user\_id<mark style="color:red;">\*</mark>             | String | Generated by Your application                                                                                                                    |
| timestamp<mark style="color:red;">\*</mark>            | Number | `TIMESTAMP` of your request in milliseconds                                                                                                      |
| destination\_coin<mark style="color:red;">\*</mark>    | String | Destination coin (Available coins, example XDB, BTC, USDT...)                                                                                    |

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

```json
{
    "result": "success",
    "request_token": "WlpZSkE3d3ZKa2NSTTl0V....",
    "payment_id_coinbar": "ca900413-.....",
    "payment_total_price": 1.2,
    "trade_pair": "BTC/EUR",
    "payment_string": "bitcoin:....",
    "destination_coin_change": 50000,
    "destination_amount": 0.000024
    "destination_address" : "address",
    "destination_memo" : "memo"
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Valid response will include the payment string with coin protocol and all other variables needed to execute the transaction in blockchain, the trade pair and the destination coin price used for the conversion
{% endhint %}

### **Input Products example:**&#x20;

Here's an example of products JSON body parameter :

{% code overflow="wrap" %}

```json
"products": [
    {
      "product_name": "Product 1",
      "product_price": 1.99,
      "product_amount": 1,
      "product_id": "id1",
      "product_type": "general"
    },
    {
      "product_name": "Product 2",
      "product_price": 0.99,
      "product_amount": 2,
      "product_id": "id2",
      "product_type": "general"
    }
]
```

{% endcode %}
