# Order creation

{% hint style="info" %}
TIP

After the order is created, the interface will return the payment link, and the user will enter the cash register through the link to pay.

If the merchant has set up a white label application, the front-end code also needs to be connected to JS-SDK. View [SDK](https://www.npmjs.com/package/@ttpay/payment_modal)
{% endhint %}

### Interface address <a href="#interface-address" id="interface-address"></a>

```
POST https://api.tokenpay.me/v1/transaction/prepayment
```

### Interface parameters <a href="#interface-parameters" id="interface-parameters"></a>

| Name           | Location | Type    | Required | Description                                                                                                                                                                                                |
| -------------- | -------- | ------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| app\_id        | header   | string  | Yes      | Application ID, example value:`8e4b8c2e7cxxxxxxxx1a1cbd3d59e0bd`                                                                                                                                           |
| mch\_id        | body     | string  | Yes      | Merchant ID, example value:`12345678`                                                                                                                                                                      |
| description    | body     | string  | No       | Order description, example value:`recharge`                                                                                                                                                                |
| out\_trade\_no | body     | string  | Yes      | Merchant order number, the merchant generates its own unique order number                                                                                                                                  |
| expire\_second | body     | integer | Yes      | Expiry date(second), example value:`3600`                                                                                                                                                                  |
| amount         | body     | number  | Yes      | Order amount, example value:`15000000`                                                                                                                                                                     |
| chain          | body     | string  | Yes      | Owned public chain, example value:`TRON`                                                                                                                                                                   |
| currency       | body     | string  | Yes      | Currency, example value:`TRX`. [View supported currencies](/currency/currency-information.md)                                                                                                              |
| to\_address    | body     | string  | No       | Collection wallet( Notes: payment wallet is required for the application of `monitor order`)                                                                                                               |
| attach         | body     | string  | No       | Custom parameters (such as unique identifiers like user IDs) are returned unchanged in query APIs and payment notifications. In practice, this field is only returned when the payment status is complete. |
| locale         | body     | string  | No       | Language: `zh_cn` Chinese、 `en` English.Using cash register will display the default language based on this setting.                                                                                       |
| notify\_url    | body     | string  | No       | Callback url, example value:`https://xxx/xxx`. [Suggest using https](/description/safety-information.md)                                                                                                   |
| return\_url    | body     | string  | No       | Return address, when payment is complete or fails, click the return button on the address. And it can be the https or the route of the app.                                                                |
| order\_type    | body     | string  | Yes      | Payment method, example value: `platform_order` platform collection                                                                                                                                        |

#### Parameters example <a href="#parameters-example" id="parameters-example"></a>

```json
{
  "app_id": "d549a3ac0e4641f998c6675fc539ba21",
  "mch_id": "12345678",
  "description": "recharge",
  "out_trade_no": "fb72xxxx-xxxx-xxxx-xxxx-xxxx8a7b52cb",
  "expire_second": 600,
  "amount": 9,
  "chain": "TRON",
  "currency": "USDT",
  "to_address": "TQjxEW2Z3p9wjoxxxxxxxxgJUrWXBun91w",
  "attach": "anim dolore",
  "locale": "zh_cn",
  "notify_url": "https://xxx/xxx",
  "return_url": "https://xxxx/xxx?id=xxxx",
  "order_type": "platform_order"
}
```

{% hint style="info" %}
TIP

app\_id through the merchant backstage [creating an application](https://ttpay.io/console/pages/app-list/pay-app) to obtain.
{% endhint %}

### Interface return <a href="#interface-return" id="interface-return"></a>

| Name         | Type    | Description                               | Description                                                                                                                                                                                                                                           |
| ------------ | ------- | ----------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| code         | integer | [Status code](/error-code/status-code.md) |                                                                                                                                                                                                                                                       |
| msg          | string  | Status description                        |                                                                                                                                                                                                                                                       |
| request\_id  | string  | Request ID                                |                                                                                                                                                                                                                                                       |
| data         | object  | Data object                               |                                                                                                                                                                                                                                                       |
| prepay\_id   | string  | Prepayment ID                             | Prepayment transaction session ID. It is used for subsequent interface calls, and its value is valid for the `expire_second` parameter set when the order is created, or you can access the `payment_url` directly to complete the payment.           |
| payment\_url | string  | Paymwnt cash register URL                 | `payment_url` is to pull up the middle page of the payment cash register, you can complete the payment by visiting this url. You can pay by visiting the url. `payment_url` is valid for the `expire_second` parameter set when the order is created. |

### Return example <a href="#return-example" id="return-example"></a>

```json
{
    "code": 0,
    "msg": "ok",
    "request_id": "9b9e08ab-48e5-4efa-83e7-97e5e3fe3d0c",
    "data": {
        "prepay_id": "15809074c5bbc36bce27exxxxxxxxxxxxxxxxxxxxa4ca0a281d7e1260624a1c2",
        "payment_url": "/pay/order?prepay_id=15809074c5bbc36bce27exxxxxxxxxxxxxxxxxxxxa4ca0a281d7e1260624a1c2"
    }
}
```

### Example code <a href="#example-code" id="example-code"></a>

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

```sh
curl --location --request POST 'https://api.tokenpay.me/v1/transaction/prepayment' \
--header 'Authorization: <Authorization>' \
--header 'User-Agent: tokenpay API (https://tokenpay.me)' \
--header 'Content-Type: application/json' \
--data-raw '<body data here>'
```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
   "fmt"
   "strings"
   "net/http"
   "io/ioutil"
)

func main() {

   url := "https://api.tokenpay.me/v1/transaction/prepayment"
   method := "POST"

   payload := strings.NewReader(`<body data here>`)

   client := &http.Client {
   }
   req, err := http.NewRequest(method, url, payload)

   if err != nil {
      fmt.Println(err)
      return
   }
   req.Header.Add("Authorization", "<Authorization>")
   req.Header.Add("User-Agent", "tokenpay API (https://tokenpay.me)")
   req.Header.Add("Content-Type", "application/json")

   res, err := client.Do(req)
   if err != nil {
      fmt.Println(err)
      return
   }
   defer res.Body.Close()

   body, err := ioutil.ReadAll(res.Body)
   if err != nil {
      fmt.Println(err)
      return
   }
   fmt.Println(string(body))
}
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
   CURLOPT_URL => 'https://api.tokenpay.me/v1/transaction/prepayment',
   CURLOPT_RETURNTRANSFER => true,
   CURLOPT_ENCODING => '',
   CURLOPT_MAXREDIRS => 10,
   CURLOPT_TIMEOUT => 0,
   CURLOPT_FOLLOWLOCATION => true,
   CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
   CURLOPT_CUSTOMREQUEST => 'POST',
   CURLOPT_POSTFIELDS =>'<body data here>',
   CURLOPT_HTTPHEADER => array(
      'Authorization: <Authorization>',
      'User-Agent: tokenpay API (https://tokenpay.me)',
      'Content-Type: application/json'
   ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
```

<br>
{% endtab %}

{% tab title="Python" %}

```python
import http.client
import json

conn = http.client.HTTPSConnection("https://api.tokenpay.me")
payload = "<body data here>"
headers = {
   'Authorization': '<Authorization>',
   'User-Agent': 'tokenpay API (https://tokenpay.me)',
   'Content-Type': 'application/json'
}
conn.request("POST", "/v1/transaction/prepayment", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
```

{% endtab %}

{% tab title="Java" %}

```java
OkHttpClient client = new OkHttpClient().newBuilder()
   .build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "<body data here>");
Request request = new Request.Builder()
   .url("https://api.tokenpay.me/v1/transaction/prepayment")
   .method("POST", body)
   .addHeader("Authorization", "<Authorization>")
   .addHeader("User-Agent", "tokenpay API (https://tokenpay.me)")
   .addHeader("Content-Type", "application/json")
   .build();
Response response = client.newCall(request).execute();
```

{% endtab %}
{% endtabs %}


---

# 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://apidoc.tokenpay.me/order/order-creation.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.
