Skip to main content

Notification Type Definitions

Source: lib/services/email-notification.service.ts, lib/payment/services/payment-email.service.ts, lib/payment/types/payment-types.ts

Notifications in the template are primarily email-based, triggered by system events such as payment completions, subscription changes, and submission reviews.

Interfaces

EmailNotificationData

The core payload for sending admin notification emails.

interface EmailNotificationData {
to: string; // Recipient email address
title: string; // Email subject / notification title
message: string; // Body text content
actionUrl?: string; // Optional CTA link
actionText?: string; // Optional CTA button label
notificationType: string; // Category identifier for template selection
timestamp: string; // ISO 8601 timestamp
}
FieldRequiredDescription
toYesRecipient email address
titleYesSubject line and internal heading
messageYesMain notification body
actionUrlNoLink for the call-to-action button
actionTextNoLabel text for the CTA button
notificationTypeYesUsed to select the email template variant
timestampYesWhen the triggering event occurred

WebhookEventType

Events received from payment provider webhooks that trigger notifications.

enum WebhookEventType {
PAYMENT_SUCCEEDED = 'payment_succeeded',
PAYMENT_FAILED = 'payment_failed',
REFUND_SUCCEEDED = 'refund_succeeded',
SUBSCRIPTION_CREATED = 'subscription_created',
SUBSCRIPTION_UPDATED = 'subscription_updated',
SUBSCRIPTION_CANCELLED = 'subscription_cancelled',
SUBSCRIPTION_TRIAL_ENDING = 'subscription_trial_ending',
SUBSCRIPTION_PAYMENT_SUCCEEDED = 'subscription_payment_succeeded',
SUBSCRIPTION_PAYMENT_FAILED = 'subscription_payment_failed',
INVOICE_PAID = 'invoice_paid',
INVOICE_PAYMENT_FAILED = 'invoice_payment_failed',
// ... additional billing portal events
}

WebhookResult

Standardised result from processing a webhook event.

interface WebhookResult {
received: boolean; // Whether the webhook was accepted
type: string; // Event type identifier
id: string; // Provider event ID
data?: any; // Parsed event payload
}

Notification Categories

The template triggers notifications for these event categories:

CategoryTrigger Events
Paymentpayment_succeeded, payment_failed, refund_succeeded
Subscriptionsubscription_created, subscription_cancelled, subscription_trial_ending
Invoiceinvoice_paid, invoice_payment_failed
SubmissionItem approved, item rejected, new submission received
AccountPassword changed, email verified

Email Service Integration

Notifications are sent via the EmailNotificationService class:

import { EmailNotificationService } from '@/lib/services/email-notification.service';
import type { EmailNotificationData } from '@/lib/services/email-notification.service';

const notification: EmailNotificationData = {
to: 'admin@example.com',
title: 'New Submission Received',
message: 'A new item "Acme Corp" has been submitted for review.',
actionUrl: '/admin/items/pending',
actionText: 'Review Now',
notificationType: 'submission',
timestamp: new Date().toISOString(),
};

const result = await EmailNotificationService.sendAdminNotification(notification);

The service checks email provider availability before sending and returns a skipped result if no provider is configured, preventing runtime errors in environments without email setup.

Email Provider Configuration

Notification delivery depends on the email configuration in lib/config/schemas/email.schema.ts:

ProviderRequired Env VarAuto-enabled
ResendRESEND_API_KEYWhen key is present
NovuNOVU_API_KEYWhen key is present
SMTPSMTP_HOST, SMTP_USER, SMTP_PASSWORDWhen all three are present

Usage Example

// In a webhook handler
import { WebhookEventType } from '@/lib/payment/types/payment-types';

async function handleWebhook(event: WebhookResult) {
if (event.type === WebhookEventType.SUBSCRIPTION_CANCELLED) {
await EmailNotificationService.sendAdminNotification({
to: adminEmail,
title: 'Subscription Cancelled',
message: `Customer ${event.data.customerId} cancelled their subscription.`,
notificationType: 'subscription',
timestamp: new Date().toISOString(),
});
}
}