> For the complete documentation index, see [llms.txt](https://e-gates.gitbook.io/crypto-payments-ot-e-gates-eng/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://e-gates.gitbook.io/crypto-payments-ot-e-gates-eng/creating-an-invoice-using-the-api.md).

# Creating an Invoice Using the API

API documentation for the method of creating an invoice using Crypto Payments from E-Gates:

#### Creating an Invoice

This method allows you to create an invoice for payment using Crypto Payments from E-Gates.

**Request**

URL: `/api/external/v1/gateway/create-payment-invoice` Method: POST

**Required Parameters:**

* `timestamp` (integer, required) - Current time in Unix timestamp format.
* `ticker` (string, required) - Cryptocurrency ticker for payment.
* `payment_method` (string, required) - Payment method, e.g., "ETHER".
* `amount` (string, required) - Payment amount.
* `order_number` (string, required) - Order number.

**Additional Parameters:**

* `success_url` (string, optional) - URL to redirect to after successful payment.
* `error_url` (string, optional) - URL to redirect to in case of payment error.
* `callback_url` (string, optional) - Callback URL.
* `sender_name` (string, optional) - Sender's name.
* `purpose_of_payment` (string, optional) - Purpose of the payment.
* `meta_data` (json, optional) - Additional metadata in JSON format.

**Example Request:**

```json
{
  "timestamp": 1691590025,
  "ticker": "USDT",
  "payment_method": "ETHER",
  "amount": "100",
  "order_number": "14556-HF1000-KL58",
  "meta_data": {"item1": "5", "item2": "12"},
  "success_url": "http://test.com/success",
  "error_url": "http://test.com/error",
  "callback_url": "http://test.com/callback",
  "sender_name": "user name",
  "purpose_of_payment": "payment for items",
}
```

**Response**

Successful response:

* `success` (boolean) - Indicates if the request was successful.
* `status` (null) - Response status (may be null).
* `response` (object) - Object containing data about the created invoice.
  * `invoice_id` (string) - Unique identifier of the invoice.
  * `redirect_link` (string) - Link to proceed with the invoice payment.
  * `currency` (string) - Invoice currency.
  * `payment_method` (string) - Payment method.
  * `amount` (string) - Invoice amount.
  * `address` (string) - Cryptocurrency send address.
  * `status` (string) - Invoice status (e.g., "PENDING").
  * `type` (string) - Invoice type (e.g., "CRYPTO").
  * `order_number` (string) - Order number.
  * `created_at` (integer) - Invoice creation time in Unix timestamp format.
  * `success_url`, `error_url`, `callback_url` (null or string) - URLs for redirecting after successful payment, error, or callback.

**Example Successful Response:**

```json
{
  "success": true,
  "status": null,
  "response": {
    "invoice_id": "1f264b83-90fc-4c3c-ad80-9d8f37e9083c",
    "redirect_link": "https://clct.itproject.dev/merchant-invoice/1f264b83-90fc-4c3c-ad80-9d8f37e9083c",
    "currency": "USDT",
    "payment_method": "ETHER",
    "amount": "100",
    "address": "0x9B3f260e560A7022152632E7e91A6d7caFcb6497",
    "status": "PENDING",
    "type": "CRYPTO",
    "order_number": "1aaa11",
    "created_at": 1691593020,
    "success_url": null,
    "error_url": null,
    "callback_url": null
  },
  "errors": null
}
```

**Possible Invoice Statuses:**

* PENDING - Invoice is awaiting payment.
* SUCCESS - Invoice payment was successfully completed.
* SUCCESS\_SMALL\_AMOUNT - Payment successfully completed, but the amount is less than expected.
* CANCEL - Invoice was canceled.

Note: To create a correct request signature, use the signature generation methods mentioned in the previous description (e.g., for PHP or JS).
