设置 API 允许您管理 PaymentKit 中的各种配置,例如创建捐赠小部件或设置通知处理程序。每个设置都是一个可配置的资源,由其 type 和 mountLocation 标识。
设置对象
设置对象包含特定功能的配置。
| 属性 | 类型 | 描述 |
|---|---|---|
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 对象
| 属性 | 类型 | 描述 |
|---|---|---|
amount | object | 捐赠金额的配置。 |
btnText | string | 捐赠按钮上显示的文本。默认值:'Donate'。 |
historyType | 'table' | 'avatar' | 捐赠历史的显示样式。默认值:'avatar'。 |
amount 对象属性
| 属性 | 类型 | 描述 |
|---|---|---|
presets | string[] | 预定义捐赠金额的数组。如果 custom 为 false,则此项为必需。 |
preset | string | 从预设金额中默认选中的金额。 |
custom | boolean | 是否允许自定义捐赠金额。 |
minimum | string | 自定义捐赠允许的最小金额。如果 custom 为 true,则此项为必需。 |
maximum | string | 自定义捐赠允许的最大金额。如果 custom 为 true,则此项为必需。 |
用于 notification 的 settings 对象
| 属性 | 类型 | 描述 |
|---|---|---|
self_handle | boolean | 如果为 true,表示组件将自行处理通知事件。 |
include_events | string[] | 要包含在通知中的事件类型数组。 |
exclude_events | string[] | 要从通知中排除的事件类型数组。 |
创建设置
创建一个新的设置对象。
创建一个新设置
const setting = await payment.settings.create({
type: 'donate',
mountLocation: '/community/donate',
description: '社区捐赠页面',
settings: {
amount: {
presets: ['5', '10', '25'],
preset: '10',
custom: true,
minimum: '1',
maximum: '1000',
},
btnText: '支持我们',
},
});参数
| 名称 | 类型 | 描述 |
|---|---|---|
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": "社区捐赠页面",
"settings": {
"amount": {
"presets": ["5", "10", "25"],
"preset": "10",
"custom": true,
"minimum": "1",
"maximum": "1000"
},
"btnText": "支持我们",
"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 检索现有设置的详细信息。
检索设置
const settingId = 'set_1a2b3c4d5e6f7g8h';
const setting = await payment.settings.retrieve(settingId);参数
| 名称 | 类型 | 描述 |
|---|---|---|
id | string | 必需。 要检索的设置的唯一标识符或 mountLocation。 |
返回
如果找到,则返回设置对象,否则抛出错误。
Response
{
"id": "set_1a2b3c4d5e6f7g8h",
"type": "donate",
"mount_location": "/community/donate",
"description": "社区捐赠页面",
"settings": {
"amount": {
"presets": ["5", "10", "25"],
"preset": "10",
"custom": true,
"minimum": "1",
"maximum": "1000"
},
"btnText": "支持我们",
"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"
}更新设置
通过设置传入参数的值来更新指定的设置。任何未提供的参数将保持不变。
更新设置
const settingId = 'set_1a2b3c4d5e6f7g8h';
const updatedSetting = await payment.settings.update(settingId, {
description: '更新后的社区捐赠页面',
active: false,
settings: {
btnText: '立即捐赠',
},
});参数
| 名称 | 类型 | 描述 |
|---|---|---|
id | string | 必需。 要更新的设置的唯一标识符或 mountLocation。 |
data | object | 必需。 一个包含要更新字段的对象。 |
data 对象属性
| 名称 | 类型 | 描述 |
|---|---|---|
description | string | 可选。设置的更新描述。 |
active | boolean | 可选。设置是否处于活动状态。 |
settings | object | 可选。一个包含要更新的设置特定字段的对象。此对象将与现有设置合并。 |
返回
更新后的设置对象。
Response
{
"id": "set_1a2b3c4d5e6f7g8h",
"type": "donate",
"mount_location": "/community/donate",
"description": "更新后的社区捐赠页面",
"settings": {
"amount": {
"presets": ["5", "10", "25"],
"preset": "10",
"custom": true,
"minimum": "1",
"maximum": "1000"
},
"btnText": "立即捐赠",
"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"
}删除设置
永久删除一个设置。此操作无法撤销。
删除设置
const settingId = 'set_1a2b3c4d5e6f7g8h';
const response = await payment.settings.del(settingId);参数
| 名称 | 类型 | 描述 |
|---|---|---|
id | string | 必需。 要删除的设置的唯一标识符或 mountLocation。 |
返回
一条确认消息。
Response
{
"message": "设置 set_1a2b3c4d5e6f7g8h 已删除"
}