Skip to main content

Enrollments Module

The enrollments module manages subscriptions and recurring orders.

Configuration Options​

import type { ScheduleData } from '@unchainedshop/core';

export interface EnrollmentsSettingsOptions {
autoSchedulingSchedule?: ScheduleData;
enrollmentNumberHashFn?: (enrollment: Enrollment, index: number) => string;
}

Invoice Generator Schedule​

Interval that the enrollment generator tries to generate new invoices, default behaviour:

import { schedule } from '@unchainedshop/core';
const defaultSchedule = schedule.parse.text('every 59 minutes');

This does not control if a new invoice actually is created, that is based on the enrollment plugin implementation and state of the user's enrollment.

Enrollment Number Creation​

The enrollmentNumberHashFn is used to generate human-readable codes that can be easily spelled out to support staff. The default generates a random alphanumeric uppercase string with length 6 using an unambiguous charset (no O, 0, 1). If the number has already been taken, the function gets iteratively called with an increasing index.

Default Random Hash Generator

Example Custom Configuration​

import { schedule } from '@unchainedshop/core';

await startPlatform({
options: {
enrollments: {
// schedule.parse.text supports "every N seconds/minutes/hours",
// use schedule.parse.cron for daily or more complex schedules
autoSchedulingSchedule: schedule.parse.cron('0 3 * * *'), // every day at 03:00
enrollmentNumberHashFn: (enrollment, index) => `${300000 + index}`,
},
},
});

Events​

EventPayloadDescription
ENROLLMENT_CREATE{ enrollment }Emitted when an enrollment is created
ENROLLMENT_UPDATE{ enrollment, field }Emitted when an enrollment is updated
ENROLLMENT_REMOVE{ enrollmentId }Emitted when an enrollment is removed
ENROLLMENT_ADD_PERIOD{ enrollment }Emitted when a period is added to an enrollment

More Information​

For API usage and detailed documentation, see the core-enrollments package on GitHub.