> For the complete documentation index, see [llms.txt](https://apidoc.tokenpay.me/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://apidoc.tokenpay.me/ko-kr/undefined-3/undefined.md).

# 주문 생성

{% hint style="info" %}
팁 (TIP)

주문이 생성된 후 인터페이스는 결제 링크를 반환하며, 사용자는 해당 링크를 통해 계산대에 진입하여 결제할 수 있습니다. 가맹점이 화이트 라벨 애플리케이션을 설정한 경우 프런트엔드 코드도 JS-SDK에 연결해야 합니다. [SDK 보기](https://www.npmjs.com/package/@ttpay/payment_modal)
{% endhint %}

#### 인터페이스 주소 (Interface address)

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

#### 인터페이스 매개변수 (Interface parameters)

| 이름              | 위치     | 유형      | 필수  | 설명                                                                                            |
| --------------- | ------ | ------- | --- | --------------------------------------------------------------------------------------------- |
| `app_id`        | header | string  | 예   | 애플리케이션 ID, 예시 값: `8e4b8c2e7cxxxxxxxx1a1cbd3d59e0bd`                                           |
| `mch_id`        | body   | string  | 예   | 가맹점 ID, 예시 값: `12345678`                                                                      |
| `description`   | body   | string  | 아니요 | 주문 설명, 예시 값: `recharge`                                                                       |
| `out_trade_no`  | body   | string  | 예   | 가맹점 주문 번호, 가맹점이 자체적으로 생성하는 고유 주문 번호                                                           |
| `expire_second` | body   | integer | 예   | 만료 시간(초), 예시 값: `3600`                                                                        |
| `amount`        | body   | number  | 예   | 주문 금액, 예시 값: `15000000`                                                                       |
| `chain`         | body   | string  | 예   | 소속 퍼블릭 체인, 예시 값: `TRON`                                                                       |
| `currency`      | body   | string  | 예   | 통화, 예시 값: `TRX`. [지원되는 통화 보기](/ko-kr/undefined-2/undefined.md)                                |
| `to_address`    | body   | string  | 아니요 | 수금 지갑 (참고: `주문 모니터링(monitor order)` 애플리케이션의 경우 수금 지갑이 필수입니다)                                  |
| `attach`        | body   | string  | 아니요 | 사용자 정의 매개변수(사용자 ID와 같은 고유 식별자 등)는 조회 API 및 결제 알림에서 그대로 반환됩니다. 실제로는 결제가 완료된 상태에서만 이 필드가 반환됩니다. |
| `locale`        | body   | string  | 아니요 | 언어: `zh_cn` 중국어, `en` 영어. 계산대를 사용하면 이 설정에 따라 기본 언어가 표시됩니다.                                    |
| `notify_url`    | body   | string  | 아니요 | 콜백 URL, 예시 값: `https://xxx/xxx`. [https 사용 권장](/ko-kr/undefined-1/undefined-1.md)             |
| `return_url`    | body   | string  | 아니요 | 반환 주소, 결제가 완료되거나 실패했을 때 주소의 반환 버튼을 클릭합니다. https 링크나 앱의 라우트일 수 있습니다.                           |
| `order_type`    | body   | string  | 예   | 결제 방식, 예시 값: `platform_order` 플랫폼 수납                                                          |

#### 매개변수 예시 (Parameters example)

```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`는 가맹점 관리자 페이지에서 [애플리케이션 생성](https://ttpay.io/console/pages/app-list/pay-app)을 통해 얻을 수 있습니다.
{% endhint %}

#### 인터페이스 반환 (Interface return)

| 이름            | 유형      | 설명                                       | 설명                                                                                                                                 |
| ------------- | ------- | ---------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| `code`        | integer | [상태 코드](/ko-kr/undefined-5/undefined.md) |                                                                                                                                    |
| `msg`         | string  | 상태 설명                                    |                                                                                                                                    |
| `request_id`  | string  | 요청 ID                                    |                                                                                                                                    |
| `data`        | object  | 데이터 객체                                   |                                                                                                                                    |
| `prepay_id`   | string  | 선결제 ID                                   | 선결제 트랜잭션 세션 ID입니다. 후속 인터페이스 호출에 사용되며, 이 값은 주문 생성 시 설정된 `expire_second` 매개변수 시간 동안 유효합니다. 또는 `payment_url`에 직접 접근하여 결제를 완료할 수 있습니다. |
| `payment_url` | string  | 결제 계산대 URL                               | `payment_url`은 결제 계산대의 중간 페이지를 불러오는 용도이며, 이 URL에 접속하여 결제를 완료할 수 있습니다. `payment_url`은 주문 생성 시 설정된 `expire_second` 매개변수 시간 동안 유효합니다. |

#### 반환 예시 (Return example)

```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)

{% 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 %}
