> 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/ms-my/pesanan/penciptaan-pesanan.md).

# Penciptaan pesanan

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

Selepas pesanan dibuat, antara muka akan mengembalikan pautan pembayaran, dan pengguna akan memasuki mesin juruwang melalui pautan untuk membayar. Jika pedagang telah menyediakan aplikasi label putih, kod bahagian hadapan juga perlu disambungkan ke JS-SDK. [Lihat SDK](https://www.npmjs.com/package/@ttpay/payment_modal)
{% endhint %}

#### Alamat antara muka (Interface address)

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

#### Parameter antara muka (Interface parameters)

| Nama            | Lokasi | Jenis   | Dikehendaki | Penerangan                                                                                                                                                                                                                  |
| --------------- | ------ | ------- | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `app_id`        | header | string  | Ya          | ID Aplikasi, nilai contoh: `8e4b8c2e7cxxxxxxxx1a1cbd3d59e0bd`                                                                                                                                                               |
| `mch_id`        | body   | string  | Ya          | ID Pedagang, nilai contoh: `12345678`                                                                                                                                                                                       |
| `description`   | body   | string  | Tidak       | Penerangan pesanan, nilai contoh: `recharge`                                                                                                                                                                                |
| `out_trade_no`  | body   | string  | Ya          | Nombor pesanan pedagang, pedagang menjana nombor pesanan uniknya sendiri                                                                                                                                                    |
| `expire_second` | body   | integer | Ya          | Masa tamat tempoh (saat), nilai contoh: `3600`                                                                                                                                                                              |
| `amount`        | body   | number  | Ya          | Jumlah pesanan, nilai contoh: `15000000`                                                                                                                                                                                    |
| `chain`         | body   | string  | Ya          | Rantaian awam yang dimiliki, nilai contoh: `TRON`                                                                                                                                                                           |
| `currency`      | body   | string  | Ya          | Mata wang, nilai contoh: `TRX`. [Lihat mata wang yang disokong](/ms-my/mata-wang/maklumat-mata-wang.md)                                                                                                                     |
| `to_address`    | body   | string  | Tidak       | Dompet kutipan (Nota: dompet pembayaran diperlukan untuk aplikasi `monitor order`)                                                                                                                                          |
| `attach`        | body   | string  | Tidak       | Parameter tersuai (seperti pengecam unik seperti ID pengguna) dikembalikan tanpa perubahan dalam API pertanyaan dan pemberitahuan pembayaran. Secara amali, medan ini hanya dikembalikan apabila status pembayaran selesai. |
| `locale`        | body   | string  | Tidak       | Bahasa: `zh_cn` Cina, `en` Inggeris. Menggunakan mesin juruwang akan memaparkan bahasa lalai berdasarkan tetapan ini.                                                                                                       |
| `notify_url`    | body   | string  | Tidak       | URL Panggilan Balik, nilai contoh: `https://xxx/xxx`. [Cadangkan menggunakan https](/ms-my/penerangan/maklumat-keselamatan.md)                                                                                              |
| `return_url`    | body   | string  | Tidak       | Alamat pemulangan, apabila pembayaran selesai atau gagal, klik butang kembali pada alamat. Ia boleh menjadi pautan https atau laluan aplikasi.                                                                              |
| `order_type`    | body   | string  | Ya          | Kaedah pembayaran, nilai contoh: `platform_order` kutipan platform                                                                                                                                                          |

**Contoh parameter (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" %}
PETUA (TIP)

`app_id` boleh didapati melalui pejabat belakang pedagang dengan [mencipta aplikasi](https://ttpay.io/console/pages/app-list/pay-app).
{% endhint %}

#### Pulangan antara muka (Interface return)

| Nama          | Jenis   | Penerangan                                   | Penerangan                                                                                                                                                                                                                                                           |
| ------------- | ------- | -------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `code`        | integer | [Kod status](/ms-my/kod-ralat/kod-status.md) |                                                                                                                                                                                                                                                                      |
| `msg`         | string  | Penerangan status                            |                                                                                                                                                                                                                                                                      |
| `request_id`  | string  | ID Permintaan                                |                                                                                                                                                                                                                                                                      |
| `data`        | object  | Objek data                                   |                                                                                                                                                                                                                                                                      |
| `prepay_id`   | string  | ID Prabayar                                  | ID sesi transaksi prabayar. Ia digunakan untuk panggilan antara muka seterusnya, dan nilainya sah untuk tempoh parameter `expire_second` yang ditetapkan apabila pesanan dibuat, atau anda boleh mengakses `payment_url` secara terus untuk melengkapkan pembayaran. |
| `payment_url` | string  | URL Mesin juruwang pembayaran                | `payment_url` adalah untuk memaparkan halaman tengah mesin juruwang pembayaran, anda boleh melengkapkan pembayaran dengan melawati url ini. `payment_url` sah untuk tempoh parameter `expire_second` yang ditetapkan apabila pesanan dibuat.                         |

#### Contoh pulangan (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"
    }
}
```

#### Contoh kod (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 %}
