> 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/ja-jp/zhu-wen/zhu-wen-zuo-cheng.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`。[サポートされている通貨を表示](/ja-jp/tong-huo/tong-huo-qing-bao.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の使用を推奨](/ja-jp/yue-ming/an-quan-qing-bao.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 | [ステータスコード](/ja-jp/erkdo/suttasukdo.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 %}
