Settings APIを使用すると、PaymentKit内のさまざまな設定を管理できます。例えば、寄付ウィジェットの作成や通知ハンドラーの設定などです。各設定は、そのtypeとmountLocationによって識別される設定可能なリソースです。
Settingオブジェクト
Settingオブジェクトには、特定の機能の設定が含まれています。
| 属性 | 型 | 説明 |
|---|---|---|
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: 'Community Donation Page',
settings: {
amount: {
presets: ['5', '10', '25'],
preset: '10',
custom: true,
minimum: '1',
maximum: '1000',
},
btnText: 'Support Us',
},
});パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
type | string | 必須。 作成する設定のタイプ(例:'donate'、'notification')。 |
mountLocation | string | 必須。 設定が使用される場所の一意の識別子。 |
description | string | 必須。 設定の説明。 |
settings | object | オプション。typeに固有の設定を持つオブジェクト。 |
active | boolean | オプション。設定がアクティブかどうか。デフォルトはtrueです。 |
livemode | boolean | オプション。モードを指定します。デフォルトはtrueです。 |
componentDid | string | オプション。設定を作成するコンポーネントのDID。 |
戻り値
新しく作成された設定オブジェクト。
レスポンス
{
"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によって既存の設定の詳細を取得します。
設定を取得する
const settingId = 'set_1a2b3c4d5e6f7g8h';
const setting = await payment.settings.retrieve(settingId);パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
id | string | 必須。 取得する設定の一意の識別子またはmountLocation。 |
戻り値
設定オブジェクトが見つかった場合はそのオブジェクト。見つからない場合はエラーがスローされます。
レスポンス
{
"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"
}設定の更新
渡されたパラメータの値を設定して、指定された設定を更新します。提供されなかったパラメータは変更されません。
設定を更新する
const settingId = 'set_1a2b3c4d5e6f7g8h';
const updatedSetting = await payment.settings.update(settingId, {
description: 'Updated Community Donation Page',
active: false,
settings: {
btnText: 'Donate Now',
},
});パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
id | string | 必須。 更新する設定の一意の識別子またはmountLocation。 |
data | object | 必須。 更新するフィールドを含むオブジェクト。 |
dataオブジェクトのプロパティ
| 名前 | 型 | 説明 |
|---|---|---|
description | string | オプション。設定の更新された説明。 |
active | boolean | オプション。設定がアクティブかどうか。 |
settings | object | オプション。更新する設定固有のフィールドを持つオブジェクト。これは既存の設定とマージされます。 |
戻り値
更新された設定オブジェクト。
レスポンス
{
"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"
}設定の削除
設定を完全に削除します。この操作は元に戻すことはできません。
設定を削除する
const settingId = 'set_1a2b3c4d5e6f7g8h';
const response = await payment.settings.del(settingId);パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
id | string | 必須。 削除する設定の一意の識別子またはmountLocation。 |
戻り値
確認メッセージ。
レスポンス
{
"message": "設定 set_1a2b3c4d5e6f7g8h は削除されました"
}