Subscription and recurring billing module for the Unchained Engine
npm install @unchainedshop/core-enrollments

Enrollment (subscription) management module for the Unchained Engine. Handles recurring subscriptions, subscription periods, and automatic order generation.
``bash`
npm install @unchainedshop/core-enrollments
`typescript
import { configureEnrollmentsModule, EnrollmentStatus } from '@unchainedshop/core-enrollments';
const enrollmentsModule = await configureEnrollmentsModule({ db });
// Create an enrollment
const enrollmentId = await enrollmentsModule.create({
userId: 'user-123',
productId: 'plan-product-456',
quantity: 1,
});
// Activate enrollment
await enrollmentsModule.activate(enrollmentId);
// Find active enrollments
const enrollments = await enrollmentsModule.findEnrollments({
status: EnrollmentStatus.ACTIVE,
});
`
| Export | Description |
|--------|-------------|
| configureEnrollmentsModule | Configure and return the enrollments module |
| Method | Description |
|--------|-------------|
| findEnrollment | Find enrollment by ID |findEnrollments
| | Find enrollments with filtering and pagination |count
| | Count enrollments matching query |enrollmentExists
| | Check if enrollment exists |
| Method | Description |
|--------|-------------|
| create | Create a new enrollment |update
| | Update enrollment data |delete
| | Delete an enrollment |activate
| | Activate an enrollment |terminate
| | Terminate an enrollment |
| Method | Description |
|--------|-------------|
| addPeriod | Add a billing period |findPeriod
| | Find a specific period |isExpired
| | Check if enrollment is expired |
| Export | Description |
|--------|-------------|
| addToDate | Add time interval to date |
| Export | Description |
|--------|-------------|
| EnrollmentStatus | Status values (INITIAL, ACTIVE, PAUSED, TERMINATED) |
| Export | Description |
|--------|-------------|
| enrollmentsSettings | Access enrollment module settings |
| Export | Description |
|--------|-------------|
| Enrollment | Enrollment document type |EnrollmentPeriod
| | Period document type |EnrollmentsModule
| | Module interface type |
| Event | Description |
|-------|-------------|
| ENROLLMENT_CREATE | Enrollment created |ENROLLMENT_UPDATE
| | Enrollment updated |ENROLLMENT_REMOVE
| | Enrollment deleted |ENROLLMENT_ACTIVATE
| | Enrollment activated |ENROLLMENT_TERMINATE` | Enrollment terminated |
|
EUPL-1.2