設定 API 可讓您管理 PaymentKit 中的各種組態,例如建立捐贈小工具或設定通知處理程式。每個設定都是一個可設定的資源,由其 type 和 mountLocation 識別。
設定物件
設定物件包含特定功能的組態。
| Attribute | Type | Description |
|---|---|---|
id | string | 設定物件的唯一識別碼。 |
type | string | 設定的類型,例如 'donate'、'notification'。 |
mount_location | string | 設定使用位置的唯一識別碼,通常是 URL 路徑或元件名稱。 |
description | string | 設定的人類可讀描述。 |
settings | object | 包含此設定類型特定組態的物件。詳情請見下文。 |
active | boolean | 設定目前是否處於作用中狀態。 |
livemode | boolean | 如果物件存在於正式模式,則為 true;如果存在於測試模式,則為 false。 |
component_did | string | 建立此設定的元件的 DID。 |
created_at | string | 設定建立時的時間戳。 |
updated_at | string | 設定上次更新時的時間戳。 |
donate 的 settings 物件
| Attribute | Type | Description |
|---|---|---|
amount | object | 捐贈金額的組態。 |
btnText | string | 捐贈按鈕上顯示的文字。預設:'Donate'。 |
historyType | 'table' | 'avatar' | 捐贈歷史的顯示樣式。預設:'avatar'。 |
amount 物件屬性
| Attribute | Type | Description |
|---|---|---|
presets | string[] | 預定義捐贈金額的陣列。如果 custom 為 false,則為必填。 |
preset | string | 從預設金額中選定的預設金額。 |
custom | boolean | 是否允許自訂捐贈金額。 |
minimum | string | 自訂捐贈的最低允許金額。如果 custom 為 true,則為必填。 |
maximum | string | 自訂捐贈的最高允許金額。如果 custom 為 true,則為必填。 |
notification 的 settings 物件
| Attribute | Type | Description |
|---|---|---|
self_handle | boolean | 如果為 true,表示元件將自行處理通知事件。 |
include_events | string[] | 要包含在通知中的事件類型陣列。 |
exclude_events | string[] | 要從通知中排除的事件類型陣列。 |
建立設定
建立一個新的設定物件。
Create a new setting
const setting = await payment.settings.create({
type: 'donate',
mountLocation: '/community/donate',
description: 'Community Donation Page',
settings: {
amount: {
presets: ['5', '10', '25'],
preset: '10',
custom: true,
minimum: '1',
maximum: '1000',
},
btnText: 'Support Us',
},
});參數
| Name | Type | Description |
|---|---|---|
type | string | 必填。 要建立的設定類型(例如 'donate'、'notification')。 |
mountLocation | string | 必填。 設定將使用位置的唯一識別碼。 |
description | string | 必填。 設定的描述。 |
settings | object | 選填。包含特定於 type 的組態物件。 |
active | boolean | 選填。設定是否處於作用中狀態。預設為 true。 |
livemode | boolean | 選填。指定模式。預設為 true。 |
componentDid | string | 選填。建立設定的元件的 DID。 |
傳回值
新建立的設定物件。
Response
{
"id": "set_1a2b3c4d5e6f7g8h",
"type": "donate",
"mount_location": "/community/donate",
"description": "Community Donation Page",
"settings": {
"amount": {
"presets": ["5", "10", "25"],
"preset": "10",
"custom": true,
"minimum": "1",
"maximum": "1000"
},
"btnText": "Support Us",
"historyType": "avatar"
},
"active": true,
"livemode": true,
"component_did": "z1...",
"created_at": "2023-10-27T10:00:00.000Z",
"updated_at": "2023-10-27T10:00:00.000Z"
}擷取設定
透過其 ID 或 mountLocation 擷取現有設定的詳細資訊。
Retrieve a setting
const settingId = 'set_1a2b3c4d5e6f7g8h';
const setting = await payment.settings.retrieve(settingId);參數
| Name | Type | Description |
|---|---|---|
id | string | 必填。 要擷取的設定的唯一識別碼或 mountLocation。 |
傳回值
如果找到,則傳回設定物件,否則會拋出錯誤。
Response
{
"id": "set_1a2b3c4d5e6f7g8h",
"type": "donate",
"mount_location": "/community/donate",
"description": "Community Donation Page",
"settings": {
"amount": {
"presets": ["5", "10", "25"],
"preset": "10",
"custom": true,
"minimum": "1",
"maximum": "1000"
},
"btnText": "Support Us",
"historyType": "avatar"
},
"active": true,
"livemode": true,
"component_did": "z1...",
"created_at": "2023-10-27T10:00:00.000Z",
"updated_at": "2023-10-27T10:00:00.000Z"
}更新設定
透過設定傳入參數的值來更新指定的設定。任何未提供的參數將保持不變。
Update a setting
const settingId = 'set_1a2b3c4d5e6f7g8h';
const updatedSetting = await payment.settings.update(settingId, {
description: 'Updated Community Donation Page',
active: false,
settings: {
btnText: 'Donate Now',
},
});參數
| Name | Type | Description |
|---|---|---|
id | string | 必填。 要更新的設定的唯一識別碼或 mountLocation。 |
data | object | 必填。 包含要更新欄位的物件。 |
data 物件屬性
| Name | Type | Description |
|---|---|---|
description | string | 選填。設定的更新描述。 |
active | boolean | 選填。設定是否處於作用中狀態。 |
settings | object | 選填。包含要更新的特定設定欄位的物件。這將與現有設定合併。 |
傳回值
更新後的設定物件。
Response
{
"id": "set_1a2b3c4d5e6f7g8h",
"type": "donate",
"mount_location": "/community/donate",
"description": "Updated Community Donation Page",
"settings": {
"amount": {
"presets": ["5", "10", "25"],
"preset": "10",
"custom": true,
"minimum": "1",
"maximum": "1000"
},
"btnText": "Donate Now",
"historyType": "avatar"
},
"active": false,
"livemode": true,
"component_did": "z1...",
"created_at": "2023-10-27T10:00:00.000Z",
"updated_at": "2023-10-27T10:05:00.000Z"
}刪除設定
永久刪除一個設定。此操作無法復原。
Delete a setting
const settingId = 'set_1a2b3c4d5e6f7g8h';
const response = await payment.settings.del(settingId);參數
| Name | Type | Description |
|---|---|---|
id | string | 必填。 要刪除的設定的唯一識別碼或 mountLocation。 |
傳回值
一則確認訊息。
Response
{
"message": "Setting set_1a2b3c4d5e6f7g8h deleted"
}