# Invoice creation

## Request

```bash
curl -X POST https://api.bitsby.app/invoices/create \
  -H "Authorization: Token MSvL2ltaDZdWVjmZURURMVWhqSJLT2NURjhL2Fla1Z1T1IxQTltKs1T3Ay" \
	-F "projectId=9deea1e2-0c08-41a3-bdc2-a34eada3892d" \
	-F "amountFiat=10.55" \
	-F "currencyFiat=EUR" \
	-F "description=12 months license for BITSBY" \
	-F "serviceData={\"userId\":100,\"orderId\":500}" \
	-F "timeToPay=6"
```

## Request parameters

<table data-full-width="true"><thead><tr><th>Parameter</th><th>Data type</th><th>Description</th><th>Example</th><th>Mandatory?</th></tr></thead><tbody><tr><td><code>projectId</code></td><td>UUID</td><td>Project ID in UUID format</td><td>1c48b092-9878-48f5-b441-07a8a48e7b54</td><td>yes</td></tr><tr><td><code>amountFiat</code></td><td>Float</td><td>Amount in fiat currency</td><td>10.55</td><td>yes</td></tr><tr><td><code>currencyFiat</code></td><td>String</td><td>Fiat currency. Valid values: USD, EUR, RUB</td><td>EUR</td><td>yes</td></tr><tr><td><code>description</code></td><td>String</td><td>Description of the product or service. Displayed to the buyer on the payment page</td><td>12 months license for BITSBY</td><td>no</td></tr><tr><td><code>serviceData</code></td><td>String</td><td>Service data. NOT displayed to the buyer. When paying the invoice, it is passed to the webhook URL of the store. This data is used to link the invoice and payment to the buyer in the merchant's webhook. It is convenient to use data in JSON format</td><td>{"userId":100,"orderId":500}</td><td>no</td></tr><tr><td><code>timeToPay</code></td><td>Float</td><td>Time in hours to pay the invoice. Valid values: 0.5, 1, 3, 6, 12</td><td>1</td><td>yes</td></tr></tbody></table>

## Example answer

```json
{
   "result":"success",
   "data":{
      "id":"ade9550d-3dc7-4fd3-b94e-3b4c12aaaa0c",
      "uid":"MXNj4m8HhcM4",
      "createDatetime":"2024-02-29 15:20:24",
      "timeToPayDatetime":"2024-03-01 03:20:24",
      "commissionFiatUSD":"0.10",
      "amountFiatUSD":"10.00",
      "url":"https:\/\/dash.bitsby.app\/invoices\/pay\/MXNj4m8HhcM4"
   }
}
```

## Answer parameters

| Parameter           | Description                                                                                                                        |
| ------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| `id`                | Invoice ID in UUID format                                                                                                          |
| `uid`               | Invoice ID (for buyer)                                                                                                             |
| `createDatetime`    | Date and time of invoice creation (UTC)                                                                                            |
| `timeToPayDatetime` | The date and time until which the invoice is valid (UTC). The buyer must have time to pay the invoice before this date             |
| `commissionFiatUSD` | The amount of the service commission. Calculated relative to the amount `invoice.amountFiatUSD`                                    |
| `amountFiatUSD`     | Amount in USD currency calculated during invoice creation at the current exchange rate relative to the `invoice.amountFiat` amount |
| `url`               | A link to the payment page for the buyer. This link must be given to the buyer to pay the invoice                                  |
