> For the complete documentation index, see [llms.txt](https://docs.codemash.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.codemash.io/sdks-and-cli/payments/triggers/save-payments-trigger.md).

# Save Payments Trigger

A **payments trigger** runs an action automatically on order events — for example sending a receipt email when an order is paid. It fires on `OnOrderCreated`, `OnOrderPaid`, or `OnWebhookCallReceived`; the optional `integrations` and `events` fields narrow which payment integrations and webhook events it reacts to. This method creates the trigger (or updates it when you pass an existing `triggerId`); the response returns its id.

This method is on the **Hub** surface (`norbix.hub.payments`) — call it from admin tooling or IaC.

{% hint style="info" %}
These examples assume the SDK is installed and your credentials are set as environment variables — each client reads them automatically, so the constructors below take no arguments. See [Install a Norbix SDK](/sdks-and-cli/install.md).
{% endhint %}

{% tabs %}
{% tab title="JavaScript / TypeScript" %}

```ts
import { Norbix } from '@norbix.ai/ts';
const norbix = new Norbix();

const result = await norbix.hub.payments.savePaymentsTrigger({
  trigger: {
    type: 'Payments',
    when: 'OnOrderPaid',
    name: 'receipt-on-payment',
    isEnabled: true,
    action: {
      type: 'email',
      templateId: 'tmpl_5XqvoF4k6I2GfarDBg3zqq',
      deliverySettings: { recipientsSourceType: 'AllUsers' },
    },
  },
});
```

{% endtab %}

{% tab title=".NET" %}

```csharp
using Norbix.Sdk;
using Norbix.Sdk.Types.Hub;

using var client = new NorbixClient();

var result = await client.Payments.SavePaymentsTriggerAsync(new SavePaymentsTrigger
{
    Trigger = new PaymentTriggerRequest
    {
        Type = TriggerType.Payments,
        When = PaymentTriggerType.OnOrderPaid,
        Name = "receipt-on-payment",
        IsEnabled = true,
        Action = new TriggerActionEmailDto
        {
            Type = TriggerActionType.Email,
            TemplateId = "tmpl_5XqvoF4k6I2GfarDBg3zqq",
            DeliverySettings = new EmailToAllUsersDeliverySettingsDto
            {
                RecipientsSourceType = EmailCampaignRecipientsSourceTypes.AllUsers,
            },
        },
    },
});
```

{% endtab %}

{% tab title="Python" %}

```python
from norbix_python import NorbixHub

norbix = NorbixHub()

result = norbix.payments.save_payments_trigger(
    trigger={
        "type": "Payments",
        "when": "OnOrderPaid",
        "name": "receipt-on-payment",
        "isEnabled": True,
        "action": {
            "type": "email",
            "templateId": "tmpl_5XqvoF4k6I2GfarDBg3zqq",
            "deliverySettings": {"recipientsSourceType": "AllUsers"},
        },
    },
)
```

{% endtab %}

{% tab title="Go" %}

```go
c, _ := norbix.New(norbix.Options{})
ctx := context.Background()

var result map[string]any
err := c.Hub.Payments.SavePaymentsTrigger(ctx, map[string]any{
	"trigger": map[string]any{
		"type": "Payments",
		"when": "OnOrderPaid",
		"name": "receipt-on-payment",
		"isEnabled": true,
		"action": map[string]any{
			"type": "email",
			"templateId": "tmpl_5XqvoF4k6I2GfarDBg3zqq",
			"deliverySettings": map[string]any{"recipientsSourceType": "AllUsers"},
		},
	},
}, &result)
```

{% endtab %}

{% tab title="Dart / Flutter" %}

```dart
import 'package:norbix/norbix_hub.dart';

final hub = NorbixHub();

final result = await hub.payments.savePaymentsTrigger(body: {
  'trigger': {
    'type': 'Payments',
    'when': 'OnOrderPaid',
    'name': 'receipt-on-payment',
    'isEnabled': true,
    'action': {
      'type': 'email',
      'templateId': 'tmpl_5XqvoF4k6I2GfarDBg3zqq',
      'deliverySettings': {'recipientsSourceType': 'AllUsers'},
    },
  },
});
```

{% endtab %}

{% tab title="Swift" %}

```swift
import NorbixSwift

let client = Norbix()

let result = try await client.hub.payments.savePaymentsTrigger([
    "trigger": [
        "type": "Payments",
        "when": "OnOrderPaid",
        "name": "receipt-on-payment",
        "isEnabled": true,
        "action": [
            "type": "email",
            "templateId": "tmpl_5XqvoF4k6I2GfarDBg3zqq",
            "deliverySettings": ["recipientsSourceType": "AllUsers"],
        ],
    ],
])
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
import dev.norbix.sdk.hub.NorbixHub

val hub = NorbixHub()

val result = hub.payments.savePaymentsTrigger(mapOf(
    "trigger" to mapOf(
        "type" to "Payments",
        "when" to "OnOrderPaid",
        "name" to "receipt-on-payment",
        "isEnabled" to true,
        "action" to mapOf(
            "type" to "email",
            "templateId" to "tmpl_5XqvoF4k6I2GfarDBg3zqq",
            "deliverySettings" to mapOf("recipientsSourceType" to "AllUsers"),
        ),
    ),
))
```

{% endtab %}

{% tab title="CLI" %}

```sh
norbix raw '/{version}/payments/triggers' -X POST --body '{"trigger":{"type":"Payments","when":"OnOrderPaid","name":"receipt-on-payment","isEnabled":true,"action":{"type":"email","templateId":"tmpl_5XqvoF4k6I2GfarDBg3zqq","deliverySettings":{"recipientsSourceType":"AllUsers"}}}}'
```

{% endtab %}
{% endtabs %}

## Scenarios

The examples above send an email to all users. The `action` object is where the behaviour lives — here is one working example for **every** action type (JavaScript; the structure is identical in the other SDKs, only syntax changes as in the tabs above).

### Email specific users

Send a templated email to chosen project users when an order is paid.

```ts
const result = await norbix.hub.payments.savePaymentsTrigger({
  trigger: {
    type: 'Payments',
    when: 'OnOrderPaid',
    name: 'email-team',
    isEnabled: true,
    action: {
      type: 'email',
      templateId: 'tmpl_3bJqQKtPFWfYpVSYnsN3mn',
      deliverySettings: {
        recipientsSourceType: 'SpecifiedUsers',
        userRecipients: ['usr_5hoyo3ThWet5Ik9nc8i8ni', 'usr_3IzD37jxlmrmVhUs9wa7BC'],
      },
    },
  },
});
```

### Email raw addresses

Send the email to fixed addresses (an ops inbox, an external partner) instead of project users.

```ts
const result = await norbix.hub.payments.savePaymentsTrigger({
  trigger: {
    type: 'Payments',
    when: 'OnOrderPaid',
    name: 'email-ops',
    isEnabled: true,
    action: {
      type: 'email',
      templateId: 'tmpl_3bJqQKtPFWfYpVSYnsN3mn',
      deliverySettings: {
        recipientsSourceType: 'Email',
        recipients: ['ops@example.com'],
      },
    },
  },
});
```

### Push notification to all users

Send a mobile push from a push template to every user when an order is paid.

```ts
const result = await norbix.hub.payments.savePaymentsTrigger({
  trigger: {
    type: 'Payments',
    when: 'OnOrderPaid',
    name: 'push-announce',
    isEnabled: true,
    action: {
      type: 'push',
      templateId: 'tmpl_1mq9lRiNGCKMST1hiEQ74M',
      deliverySettings: { recipientsSourceType: 'AllUsers' },
    },
  },
});
```

### SMS to phone numbers

Send a text message to fixed phone numbers.

```ts
const result = await norbix.hub.payments.savePaymentsTrigger({
  trigger: {
    type: 'Payments',
    when: 'OnOrderPaid',
    name: 'sms-oncall',
    isEnabled: true,
    action: {
      type: 'sms',
      templateId: 'tmpl_25aiVcKJGOyZmO58pedIeX',
      deliverySettings: {
        recipientsSourceType: 'PhoneNumbers',
        phoneNumbers: ['+14155550123'],
      },
    },
  },
});
```

### Call a webhook

Publish the event to your configured webhook destinations. Destinations (URLs, secrets) are managed in the Webhooks module; here you only pick which ones receive it.

```ts
const result = await norbix.hub.payments.savePaymentsTrigger({
  trigger: {
    type: 'Payments',
    when: 'OnOrderPaid',
    name: 'webhook-crm',
    isEnabled: true,
    action: {
      type: 'webhookcall',
      deliverySettings: { destinationIds: ['whd_5K6DoEHqml6S0sa7fNuHIQ'] },
    },
  },
});
```

### Run a function

Execute one of your functions from the Code module with the event as input.

```ts
const result = await norbix.hub.payments.savePaymentsTrigger({
  trigger: {
    type: 'Payments',
    when: 'OnOrderPaid',
    name: 'run-function',
    isEnabled: true,
    action: {
      type: 'code',
      functionId: 'cf_3VXuCiv7paJwQHkKTFWrVq',
      deliverySettings: {},
    },
  },
});
```

### Send a realtime (SSE) event

Push a server-sent event to connected clients — for live UI updates.

```ts
const result = await norbix.hub.payments.savePaymentsTrigger({
  trigger: {
    type: 'Payments',
    when: 'OnOrderPaid',
    name: 'realtime-update',
    isEnabled: true,
    action: {
      type: 'ssecall',
      deliverySettings: {
        audience: 'ToCurrentUser',
        eventName: 'entity.changed',
      },
    },
  },
});
```

### Run a marketplace function

Fire an installed marketplace function; `payload` passes extra static values.

```ts
const result = await norbix.hub.payments.savePaymentsTrigger({
  trigger: {
    type: 'Payments',
    when: 'OnOrderPaid',
    name: 'marketplace-sync',
    isEnabled: true,
    action: {
      type: 'marketplace',
      functionId: 'func_4f3VoJJV9ayAellzC9o58T',
      payload: { plan: 'pro' },
    },
  },
});
```

For every field of every shape (CC/BCC, campaign timing, timezone settings, token mappings, collection-based audiences), see the [API reference](/api-reference/payments/triggers/save-payments-trigger.md). More runnable examples live in the SDK repos on [GitHub](https://github.com/norbix-code).

## In the dashboard

Manage this visually in Norbix Cloud — see [Payments → Triggers](/norbix-cloud/payments/triggers.md).

## API reference

Full request and response for this endpoint: [Save Payments Trigger](/api-reference/payments/triggers/save-payments-trigger.md).
