Settings
The Settings API allows you to manage various configurations within PaymentKit, such as donation widgets or notification endpoints. This resource provides methods to create, retrieve, update, and delete settings objects.
The Setting Object#
A setting object contains configuration details for a specific feature or component. The structure of the settings
property varies depending on the type
of the setting.
Attribute | Type | Description |
---|---|---|
|
| Unique identifier for the setting. |
|
| The type of setting, e.g., 'donate', 'notification'. Determines the schema of the |
|
| A unique string identifier for where the setting is used or mounted. |
|
| A human-readable description of the setting. |
|
| Whether the setting is currently active. |
|
|
|
|
| An object containing the configuration specific to the setting's |
|
| Optional. The DID of the component associated with this setting. |
|
| Timestamp of when the setting was created. |
|
| Timestamp of when the setting was last updated. |
Create a Setting#
Creates a new setting object. You must specify the type
, mountLocation
, and description
.
Endpoint: POST /api/settings
Parameters
Name | Type | Description |
---|---|---|
|
| Required. The type of setting to create (e.g., |
|
| Required. A unique identifier for the setting's location. |
|
| Required. A description of what this setting is for. |
|
| Optional. An object with configuration specific to the |
|
| Optional. Whether the setting is active. Defaults to |
|
| Optional. The mode for this setting. Defaults to |
|
| Optional. The DID of the component creating the setting. |
DonateSetting
Object Properties
When type
is 'donate'
, the settings
object can contain the following properties:
Name | Type | Description |
---|---|---|
|
| Configuration for donation amounts. See the |
|
| The text displayed on the donation button. Defaults to |
|
| How to display donation history. Defaults to |
amount
Object Properties (for DonateSetting)
Name | Type | Description |
---|---|---|
|
| An array of predefined donation amounts. Required if |
|
| The default selected preset amount. Defaults to |
|
| Required. Whether to allow custom donation amounts. Defaults to |
|
| The minimum allowed amount for custom donations. Required if |
|
| The maximum allowed amount for custom donations. Required if |
NotificationSetting
Object Properties
When type
is 'notification'
, the settings
object can contain the following properties:
Name | Type | Description |
---|---|---|
|
| Required. If |
|
| Optional. An array of event types to be included in notifications. |
|
| Optional. An array of event types to be excluded from notifications. |
Returns
Returns the newly created TSetting
object.
Example
import payment from '@blocklet/payment-js';
async function createDonateSetting() {
try {
const newSetting = await payment.settings.create({
type: 'donate',
mountLocation: 'site/sidebar',
description: 'Donation button for the main site sidebar',
active: true,
settings: {
amount: {
presets: ['5', '10', '20'],
preset: '10',
custom: true,
minimum: '1',
maximum: '500',
},
btnText: 'Support Us',
},
});
console.log('Setting created:', newSetting);
} catch (error) {
console.error('Error creating setting:', error.message);
}
}
createDonateSetting();
Example Response
{
"id": "set_1J2K3L4M5N6O7P8Q",
"type": "donate",
"mount_location": "site/sidebar",
"description": "Donation button for the main site sidebar",
"active": true,
"livemode": true,
"settings": {
"amount": {
"presets": [
"5",
"10",
"20"
],
"preset": "10",
"minimum": "1",
"maximum": "500",
"custom": true
},
"btnText": "Support Us",
"historyType": "avatar"
},
"component_did": null,
"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.
Endpoint: GET /api/settings/{id}
Parameters
Name | Type | Description |
---|---|---|
|
| Required. The unique identifier ( |
Returns
Returns the TSetting
object if found.
Example
import payment from '@blocklet/payment-js';
async function getSetting(settingIdentifier) {
try {
const setting = await payment.settings.retrieve(settingIdentifier);
console.log('Retrieved setting:', setting);
} catch (error) {
console.error(`Error retrieving setting ${settingIdentifier}:`, error.message);
}
}
// Retrieve by mountLocation
getSetting('site/sidebar');
// Or retrieve by ID
// getSetting('set_1J2K3L4M5N6O7P8Q');
Example Response
{
"id": "set_1J2K3L4M5N6O7P8Q",
"type": "donate",
"mount_location": "site/sidebar",
"description": "Donation button for the main site sidebar",
"active": true,
"livemode": true,
"settings": {
"amount": {
"presets": [
"5",
"10",
"20"
],
"preset": "10",
"minimum": "1",
"maximum": "500",
"custom": true
},
"btnText": "Support Us",
"historyType": "avatar"
},
"component_did": null,
"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.
Endpoint: PUT /api/settings/{id}
Parameters
Name | Type | Description |
---|---|---|
|
| Required. The unique identifier ( |
|
| Required. An object containing the fields to update. |
updateData
Object Properties
Name | Type | Description |
---|---|---|
|
| Optional. A partial settings object. The values will be merged with the existing settings. |
|
| Optional. The new active status for the setting. |
|
| Optional. The new description for the setting. |
Returns
Returns the updated TSetting
object.
Example
import payment from '@blocklet/payment-js';
async function updateSetting(settingIdentifier) {
try {
const updatedSetting = await payment.settings.update(settingIdentifier, {
description: 'New updated description for the sidebar donation button',
active: false,
});
console.log('Setting updated:', updatedSetting);
} catch (error) {
console.error(`Error updating setting ${settingIdentifier}:`, error.message);
}
}
updateSetting('site/sidebar');
Example Response
{
"id": "set_1J2K3L4M5N6O7P8Q",
"type": "donate",
"mount_location": "site/sidebar",
"description": "New updated description for the sidebar donation button",
"active": false,
"livemode": true,
"settings": {
"amount": {
"presets": [
"5",
"10",
"20"
],
"preset": "10",
"minimum": "1",
"maximum": "500",
"custom": true
},
"btnText": "Support Us",
"historyType": "avatar"
},
"component_did": null,
"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.
Endpoint: DELETE /api/settings/{id}
Parameters
Name | Type | Description |
---|---|---|
|
| Required. The unique identifier ( |
Returns
Returns a confirmation message object.
Example
import payment from '@blocklet/payment-js';
async function deleteSetting(settingIdentifier) {
try {
const response = await payment.settings.del(settingIdentifier);
console.log(response.message);
} catch (error) {
console.error(`Error deleting setting ${settingIdentifier}:`, error.message);
}
}
deleteSetting('site/sidebar');
Example Response
{
"message": "Setting site/sidebar deleted"
}
This guide covers the core functionalities of the Settings API, enabling you to manage dynamic configurations within your application.