Skip to main content

Settings

The Settings API allows you to manage various configurations within PaymentKit, such as creating donation widgets or setting up notification handlers. Each setting is a configurable resource identified by its type and mountLocation.

The Setting Object

A Setting object contains the configuration for a specific feature.

AttributeTypeDescription
idstringUnique identifier for the setting object.
typestringThe type of setting, e.g., 'donate', 'notification'.
mount_locationstringA unique identifier for where the setting is used, often a URL path or component name.
descriptionstringA human-readable description of the setting.
settingsobjectAn object containing the specific configuration for this setting type. See details below.
activebooleanWhether the setting is currently active.
livemodebooleantrue if the object exists in live mode, false if it exists in test mode.
component_didstringThe DID of the component that created this setting.
created_atstringTimestamp of when the setting was created.
updated_atstringTimestamp of when the setting was last updated.

The settings object for donate

AttributeTypeDescription
amountobjectConfiguration for donation amounts.
btnTextstringThe text displayed on the donation button. Default: 'Donate'.
historyType'table' | 'avatar'The display style for donation history. Default: 'avatar'.

amount object properties

AttributeTypeDescription
presetsstring[]An array of predefined donation amounts. Required if custom is false.
presetstringThe default selected amount from the presets.
custombooleanWhether to allow custom donation amounts.
minimumstringThe minimum allowed amount for custom donations. Required if custom is true.
maximumstringThe maximum allowed amount for custom donations. Required if custom is true.

The settings object for notification

AttributeTypeDescription
self_handlebooleanIf true, indicates that the component will handle the notification events itself.
include_eventsstring[]An array of event types to be included in notifications.
exclude_eventsstring[]An array of event types to be excluded from notifications.

Create a Setting

Creates a new setting object.

Create a new setting

javascript
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',
  },
});

Parameters

NameTypeDescription
typestringRequired. The type of setting to create (e.g., 'donate', 'notification').
mountLocationstringRequired. A unique identifier for where the setting will be used.
descriptionstringRequired. A description for the setting.
settingsobjectOptional. An object with configuration specific to the type.
activebooleanOptional. Whether the setting is active. Defaults to true.
livemodebooleanOptional. Specifies the mode. Defaults to true.
componentDidstringOptional. The DID of the component creating the setting.

Returns

The newly created setting object.

Response

json
{
  "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"
}

Retrieve a Setting

Retrieves the details of an existing setting by its ID or mountLocation.

Retrieve a setting

javascript
const settingId = 'set_1a2b3c4d5e6f7g8h';
const setting = await payment.settings.retrieve(settingId);

Parameters

NameTypeDescription
idstringRequired. The unique identifier or mountLocation of the setting to retrieve.

Returns

The setting object if found, otherwise an error is thrown.

Response

json
{
  "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

Updates the specified setting by setting the values of the parameters passed. Any parameters not provided will be left unchanged.

Update a setting

javascript
const settingId = 'set_1a2b3c4d5e6f7g8h';
const updatedSetting = await payment.settings.update(settingId, {
  description: 'Updated Community Donation Page',
  active: false,
  settings: {
    btnText: 'Donate Now',
  },
});

Parameters

NameTypeDescription
idstringRequired. The unique identifier or mountLocation of the setting to update.
dataobjectRequired. An object containing the fields to update.

data object properties

NameTypeDescription
descriptionstringOptional. An updated description for the setting.
activebooleanOptional. Whether the setting is active.
settingsobjectOptional. An object with setting-specific fields to update. This will be merged with the existing settings.

Returns

The updated setting object.

Response

json
{
  "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

Permanently deletes a setting. It cannot be undone.

Delete a setting

javascript
const settingId = 'set_1a2b3c4d5e6f7g8h';
const response = await payment.settings.del(settingId);

Parameters

NameTypeDescription
idstringRequired. The unique identifier or mountLocation of the setting to delete.

Returns

A confirmation message.

Response

json
{
  "message": "Setting set_1a2b3c4d5e6f7g8h deleted"
}