---
# System prepended metadata

title: 交易成立/更新

---

# 交易成立/更新

[詳業務提供之文件](https://developers.aftee.tw/v1/reference-cn/)
交易成立/更新 均使用 2-3-1-1. 交易更新API


## 交易成立

| 項目（表示名稱） | 項目（實際名稱）     |  型別   | 必填 | 格式確認                                 | 範例                                   |
| ------------- | ----------------   | --- | ---- | ---------------------------------------- | -------------------------------------- |
| 付款認證token    | authentication_token |  String   | O    | "tk_" + URL safe的24位數字串 ※不含空白鍵 | tk_a2c4e6c8zPl2E+#5@=89s2q4            |
| 消費金額         | amount               |  Integer   | O    | 1以上不超過7位數的整數（左側不須填入0）     | 2000                                   |
| 店舖訂單編號     | shop_transaction_no  |  String   | O    | 半形英文或數字（100字以内）※不含空白鍵      | shop-tran-00000000001                  |
| 商家會員ID       | user_no              |  String   | O    | 半形英文或數字（255字以内）※不含空白鍵     | user-00000001                          |
| 交易選項         | transaction_options  | Array    | O    | 0以上1~2位數的整数（左側不須填入0）       | ※ 以Raingo的使用情境需固定帶[2,4]  |
| 店舖交易備註     | description_trans    |   String  | -    | 255字以内文字                          | 使用點數                               |
| 消費者           | customer             |  Hash   | O    |                                     | ※項目下欄位詳細說明請參考正式文件      |
| 商品明細         | items                | Hash    | O    |                                      | ※註一 項目下欄位詳細說明請參考正式文件 |


※註一
若有優惠券，請在商品明細新增一個hash，以負的金額表示
※文件中的dest_customers以Raingo的交易情境不用填寫


範例
```
{
  "authentication_token": "tk_gzQAiT4cxS8MwXySSP-XouQM",
  "amount": 45,
  "user_no": "10023456",
  "sales_settled": false,
  "customer": {
    "email": "aftee001@gmail.com",
    "phone_number": "0937511716",
    "customer_name": "RaingoUSER",
    "address": "RaingoUSER"
  },
  "description_trans": "RaingoUSER",
  "items": [
    {
      "item_count": 1,
      "item_name": "Raingo_FEE",
      "item_price": 45,
      "shop_item_id": "AFTEE4"
    },
    {
      "item_count": 1,
      "item_name": "Raingo_DISCOUNT",
      "item_price": -5,
      "shop_item_id": "AFTEE5"
    }
  ],
  "shop_transaction_no": "20230823000004",
  "transaction_options": [2,4]
}
```
response 範例
```
{
    "id": "tr_LaIR_-ruKQFp0uZt",
    "object": "transaction",
    "livemode": false,
    "authentication_token": "tk_gzQAiT4cxS8MwXySSP-XouQM",
    "aftee_transaction_no": "aft00377-00001-230823000133",
    "np_transaction_no": "aft00377-00001-230823000133",
    "shop_transaction_no": "20230823000008",
    "amount": 40,
    "japanese_yen_amount": null,
    "authorization_result": 1,
    "authorization_result_ng_reason": null,
    "amount_refund_total": 0,
    "registration_datetime": "2023-08-23 16:18:10",
    "sales_settled_datetime": null,
    "transaction_options": [
        2,
        4
    ],
    "related_transaction": null,
    "updated_transactions": null,
    "description": "RaingoUSER",
    "customer": {
        "object": "customer",
        "customer_name": "RaingoUSER",
        "customer_family_name": null,
        "customer_given_name": null,
        "phone_number": "0937511716",
        "birthday": null,
        "sex_division": null,
        "company_name": null,
        "department": null,
        "zip_code": null,
        "address": "RaingoUSER",
        "email": "aftee001@gmail.com",
        "total_purchase_count": null,
        "total_purchase_amount": null,
        "user_no": "10023456",
        "information_code": null
    },
    "dest_customers": [],
    "items": [
        {
            "object": "item",
            "shop_item_id": "AFTEE4",
            "item_name": "Raingo_FEE",
            "item_price": 45,
            "item_count": 1,
            "item_url": null
        },
        {
            "object": "item",
            "shop_item_id": "AFTEE5",
            "item_name": "Raingo_DISCOUNT",
            "item_price": -5,
            "item_count": 1,
            "item_url": null
        }
    ],
    "refunds": null
```


## 交易更新
|     項目（表示名稱） | 項目（實際名稱）     | 必填 | 格式確認                                 | 範例                                   |
| ---------------- | -------------------- | ---- | ---------------------------------------- | ------------------------------------- |
|  變更交易ID                |     	updated_transactions                 |  O    |   "tr_" + URL safe的16位數字串※不含空白鍵                                       |      ※來自交易成立response的"id"欄位  tr_1b3D5g7$9A1X3y5z                               |
| 付款認證token    | authentication_token | O    | "tk_" + URL safe的24位數字串 ※不含空白鍵 | tk_a2c4e6c8zPl2E+#5@=89s2q4           |
| 消費金額         | amount               | O    | 1以上不超過7位數的整數（左側不須填入0）  | 2000                                  |
| 店舖訂單編號     | shop_transaction_no  | O    | 半形英文或數字（100字以内）※不含空白鍵   | shop-tran-00000000001                 |
| 商家會員ID       | user_no              | O    | 半形英文或數字（255字以内）※不含空白鍵   | user-00000001                         |
| 店舖交易備註     | description_trans    | -    | 255字以内文字                            | 使用點數                              |
| 消費者           | customer             | O    |                                          | ※項目下欄位詳細說明請參考正式文件                   |
|  商品明細                |     items                 |  O    |                                          |      ※註一 項目下欄位詳細說明請參考正式文件                                 |

※註一
商品明細要帶一樣的，僅變更金額
※與成立交易相比，需加上「變更交易ID」，去掉交易選項

範例

```
{
  "updated_transactions": "tr_LaIR_-ruKQFp0uZt",
  "authentication_token": "tk_gzQAiT4cxS8MwXySSP-XouQM",
  "amount": 80,
  "user_no": "10023456",
  "customer": {
    "email": "aftee001@gmail.com",
    "phone_number": "0937511716",
    "customer_name": "RaingoUSER",
    "address": "RaingoUSER"
  },
  "description_trans": "RaingoUSER",
  "items": [
    {
      "item_count": 1,
      "item_name": "Raingo_FEE",
      "item_price": 85,
      "shop_item_id": "AFTEE4"
    },
    {
      "item_count": 1,
      "item_name": "Raingo_DISCOUNT",
      "item_price": -5,
      "shop_item_id": "AFTEE5"
    }
  ],
  "shop_transaction_no": "20230823000008"
}
```

response 範例
```
{
    "id": "tr_6nC701hJuY7eKxcn",
    "object": "transaction",
    "livemode": false,
    "authentication_token": "tk_gzQAiT4cxS8MwXySSP-XouQM",
    "aftee_transaction_no": "aft00377-00001-230823000166",
    "np_transaction_no": "aft00377-00001-230823000166",
    "shop_transaction_no": "20230823000008",
    "amount": 80,
    "japanese_yen_amount": null,
    "authorization_result": 1,
    "authorization_result_ng_reason": null,
    "amount_refund_total": 0,
    "registration_datetime": "2023-08-23 16:27:29",
    "sales_settled_datetime": null,
    "transaction_options": null,
    "related_transaction": null,
    "updated_transactions": [
        "tr_LaIR_-ruKQFp0uZt"
    ],
    "description": "RaingoUSER",
    "customer": {
        "object": "customer",
        "customer_name": "RaingoUSER",
        "customer_family_name": null,
        "customer_given_name": null,
        "phone_number": "0937511716",
        "birthday": null,
        "sex_division": null,
        "company_name": null,
        "department": null,
        "zip_code": null,
        "address": "RaingoUSER",
        "email": "aftee001@gmail.com",
        "total_purchase_count": null,
        "total_purchase_amount": null,
        "user_no": "10023456",
        "information_code": null
    },
    "dest_customers": [],
    "items": [
        {
            "object": "item",
            "shop_item_id": "AFTEE4",
            "item_name": "Raingo_FEE",
            "item_price": 85,
            "item_count": 1,
            "item_url": null
        },
        {
            "object": "item",
            "shop_item_id": "AFTEE5",
            "item_name": "Raingo_DISCOUNT",
            "item_price": -5,
            "item_count": 1,
            "item_url": null
        }
    ],
    "refunds": null
}

```





## Api範例



交易成立：
```shell
> curl --location 'https://ct-api.np-pay.com/v1/transactions' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic aE9KX3FsSVVDd0MtTnBHd0JyNk5xUTo=' \
--data-raw '{
  "authentication_token": "tk_m9yG3noT3e02Xkpht-2jtBif",
  "amount": 323,
  "user_no": "10023456",
  "shop_transaction_no": "test_001",
  "transaction_options": [
    2,
    4
  ],
  "sales_settled": false,
  "customer": {
    "customer_name": "Korxd Wjdnaeo",
    "address": "Fgabjuqgwwncivjtsdqh, Qzyuukdqiv, Lvwjo",
    "email": "pvtoj@chgoa.com"
  },
  "items": [
    {
      "shop_item_id": "ngjsliikvp",
      "item_name": "Item wjzmm",
      "item_price": 323,
      "item_count": "1"
    }
  ]
}
'

{"id":"tr_J6Fgm1juz9NLgjlx","object":"transaction","livemode":false,"authentication_token":"tk_m9yG3noT3e02Xkpht-2jtBif","aftee_transaction_no":"mcc00225-00001-230915000014","np_transaction_no":"mcc00225-00001-230915000014","shop_transaction_no":"test_001","amount":323,"japanese_yen_amount":null,"authorization_result":2,"authorization_result_ng_reason":1,"amount_refund_total":0,"registration_datetime":"2023-09-15 15:43:26","sales_settled_datetime":null,"transaction_options":[2,4],"related_transaction":null,"updated_transactions":null,"description":null,"customer":{"object":"customer","customer_name":"Korxd Wjdnaeo","customer_family_name":null,"customer_given_name":null,"phone_number":null,"birthday":null,"sex_division":null,"company_name":null,"department":null,"zip_code":null,"address":"Fgabjuqgwwncivjtsdqh, Qzyuukdqiv, Lvwjo","email":"pvtoj@chgoa.com","total_purchase_count":null,"total_purchase_amount":null,"user_no":"10023456","information_code":null},"tenant":null,"dest_customers":[],"items":[{"object":"item","shop_item_id":"ngjsliikvp","item_name":"Item wjzmm","item_price":323,"item_count":1,"item_url":null}],"refunds":null}%    
```




交易更新

```shell
curl --location 'https://ct-api.np-pay.com/v1/transactions' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic aE9KX3FsSVVDd0MtTnBHd0JyNk5xUTo=' \
--data-raw '{
  "authentication_token": "tk_m9yG3noT3e02Xkpht-2jtBif",
  "updated_transactions": "tr_J6Fgm1juz9NLgjlx" , 
  "amount": 99,
  "user_no": "10023456",
  "shop_transaction_no": "test_001",
  "transaction_options": [
    
  ],
  "sales_settled": false,
  "customer": {
    "customer_name": "Korxd Wjdnaeo",
    "address": "Fgabjuqgwwncivjtsdqh, Qzyuukdqiv, Lvwjo",
    "email": "pvtoj@chgoa.com"
  },
  "items": [
    {
      "shop_item_id": "ngjsliikvp",
      "item_name": "Item wjzmm",
      "item_price": 99,
      "item_count": "1"
    }
  ]
}
'

response

{
    "id": "tr_n4-6VzdXvwbGFj2S",
    "object": "transaction",
    "livemode": false,
    "authentication_token": "tk_m9yG3noT3e02Xkpht-2jtBif",
    "aftee_transaction_no": "mcc00225-00001-230915000016",
    "np_transaction_no": "mcc00225-00001-230915000016",
    "shop_transaction_no": "test_001",
    "amount": 99,
    "japanese_yen_amount": null,
    "authorization_result": 2,
    "authorization_result_ng_reason": 1,
    "amount_refund_total": 0,
    "registration_datetime": "2023-09-15 15:47:26",
    "sales_settled_datetime": null,
    "transaction_options": [
        2
    ],
    "related_transaction": null,
    "updated_transactions": [
        "tr_J6Fgm1juz9NLgjlx"
    ],
    "description": null,
    "customer": {
        "object": "customer",
        "customer_name": "Korxd Wjdnaeo",
        "customer_family_name": null,
        "customer_given_name": null,
        "phone_number": null,
        "birthday": null,
        "sex_division": null,
        "company_name": null,
        "department": null,
        "zip_code": null,
        "address": "Fgabjuqgwwncivjtsdqh, Qzyuukdqiv, Lvwjo",
        "email": "pvtoj@chgoa.com",
        "total_purchase_count": null,
        "total_purchase_amount": null,
        "user_no": "10023456",
        "information_code": null
    },
    "tenant": null,
    "dest_customers": [],
    "items": [
        {
            "object": "item",
            "shop_item_id": "ngjsliikvp",
            "item_name": "Item wjzmm",
            "item_price": 99,
            "item_count": 1,
            "item_url": null
        }
    ],
    "refunds": null
}
```
