Settings
The Settings API allows you to manage application-wide configurations, such as rules for notifications or parameters for donation widgets. These settings are versatile and can be tailored for different types of components or features within your application.
Each setting is identified by a mountLocation and has a specific type which determines the structure of its settings object.
The Setting Object#
A setting object represents a specific configuration in your application. It contains the following properties:
Property | Type | Description |
|---|---|---|
|
| Unique identifier for the setting. |
|
|
|
|
| The type of setting (e.g., |
|
| An identifier for the component or location where this setting is applied. |
|
|
|
|
| (Optional) The DID of the component associated with this setting. |
|
| A description of the setting's purpose. |
|
| An object containing the detailed configuration. Its structure depends on the |
|
| The timestamp when the setting was created. |
|
| The timestamp when the setting was last updated. |
Create a Setting#
Creates a new setting for a specified mount location and type.
Parameters#
Name | Type | Description |
|---|---|---|
|
| Required. A unique identifier for where the setting is used. |
|
| Required. A human-readable description of the setting. |
|
| Required. The type of setting to create, such as |
|
| Required. A configuration object whose structure depends on the |
|
| For |
|
| For |
| `'table' | 'avatar'` |
|
| For |
|
| For |
|
| For |
|
| (Optional) Whether the setting is active. Defaults to |
|
| (Optional) Whether this setting applies to live mode. |
|
| (Optional) The DID of the component. |
Returns#
Returns the newly created setting object.
Example#
async function createNotificationSetting() {
try {
const setting = await payment.settings.create({
type: 'notification',
mountLocation: 'user_dashboard_notifications',
description: 'Controls notifications for the main user dashboard.',
active: true,
settings: {
self_handle: false,
include_events: ['customer.subscription.renewed', 'invoice.paid'],
},
});
console.log('Setting created:', setting);
} catch (error) {
console.error('Error creating setting:', error.message);
}
}
createNotificationSetting();Example Response#
{
"id": "set_1J2K3L4M5N6O7P8Q",
"livemode": false,
"type": "notification",
"mount_location": "user_dashboard_notifications",
"active": true,
"component_did": null,
"description": "Controls notifications for the main user dashboard.",
"settings": {
"self_handle": false,
"include_events": [
"customer.subscription.renewed",
"invoice.paid"
]
},
"created_at": "2023-10-27T10:00:00.000Z",
"updated_at": "2023-10-27T10:00:00.000Z"
}Retrieve a Setting#
Retrieves the details of a specific setting by its ID or mount location.
Parameters#
Name | Type | Description |
|---|---|---|
|
| Required. The unique identifier or mount location of the setting to retrieve. |
Returns#
Returns the retrieved setting object.
Example#
async function getSettingDetails(id) {
try {
const setting = await payment.settings.retrieve(id);
console.log('Setting details:', setting);
} catch (error) {
console.error(`Error retrieving setting ${id}:`, error.message);
}
}
getSettingDetails('set_1J2K3L4M5N6O7P8Q');Example Response#
{
"id": "set_1J2K3L4M5N6O7P8Q",
"livemode": false,
"type": "notification",
"mount_location": "user_dashboard_notifications",
"active": true,
"component_did": null,
"description": "Controls notifications for the main user dashboard.",
"settings": {
"self_handle": false,
"include_events": [
"customer.subscription.renewed",
"invoice.paid"
]
},
"created_at": "2023-10-27T10:00:00.000Z",
"updated_at": "2023-10-27T10:05:00.000Z"
}Update a Setting#
Updates an existing setting's properties. You can modify its status, description, or the nested settings object.
Parameters#
Name | Type | Description |
|---|---|---|
|
| Required. The identifier or mount location of the setting to update. |
|
| Required. An object containing the fields to update. |
|
| (Optional) New active status for the setting. |
|
| (Optional) New description for the setting. |
|
| (Optional) A partial object to merge with the existing settings. |
Returns#
Returns the updated setting object.
Example#
async function updateSetting(id) {
try {
const updatedSetting = await payment.settings.update(id, {
description: 'Updated dashboard notification settings.',
settings: {
exclude_events: ['invoice.created'],
},
});
console.log('Setting updated:', updatedSetting);
} catch (error) {
console.error(`Error updating setting ${id}:`, error.message);
}
}
updateSetting('set_1J2K3L4M5N6O7P8Q');Example Response#
{
"id": "set_1J2K3L4M5N6O7P8Q",
"livemode": false,
"type": "notification",
"mount_location": "user_dashboard_notifications",
"active": true,
"component_did": null,
"description": "Updated dashboard notification settings.",
"settings": {
"self_handle": false,
"include_events": [
"customer.subscription.renewed",
"invoice.paid"
],
"exclude_events": [
"invoice.created"
]
},
"created_at": "2023-10-27T10:00:00.000Z",
"updated_at": "2023-10-27T10:10:00.000Z"
}Delete a Setting#
Permanently deletes a setting.
Parameters#
Name | Type | Description |
|---|---|---|
|
| Required. The identifier or mount location of the setting to delete. |
Returns#
Returns an object with a confirmation message.
Example#
async function deleteSetting(id) {
try {
const response = await payment.settings.del(id);
console.log(response.message);
} catch (error) {
console.error(`Error deleting setting ${id}:`, error.message);
}
}
deleteSetting('set_1J2K3L4M5N6O7P8Q');Example Response#
{
"message": "Setting deleted successfully"
}This guide has covered how to manage application settings. For tracking usage-based billing, you can proceed to the Meters section.