UNPKG

@unchainedshop/plugins

Version:

Because of a Typescript issue with upstream "postfinancecheckout", the Postfinance plugin has been disabled from transpilation, import the source ts files from src and enable node_module tsc or copy over the src/payment/postfinance-checkout to your projec

40 lines 1.49 kB
import { EnrollmentDirector, EnrollmentAdapter } from '@unchainedshop/core'; export const rangeMatcher = (date = new Date()) => { const timestamp = date.getTime(); return ({ start, end }) => { const startTimestamp = new Date(start).getTime(); const endTimestamp = new Date(end).getTime(); return startTimestamp <= timestamp && endTimestamp >= timestamp; }; }; const LicensedEnrollments = { ...EnrollmentAdapter, key: 'shop.unchained.enrollments.licensed', version: '1.0.0', label: 'Simple Licensed Enrollments', isActivatedFor: (productPlan) => { return productPlan?.usageCalculationType === 'LICENSED'; }, actions: (params) => { return { ...EnrollmentAdapter.actions(params), isValidForActivation: async () => { const periods = params.enrollment?.periods || []; return periods.findIndex(rangeMatcher()) !== -1; }, isOverdue: async () => { return false; }, configurationForOrder: async (context) => { const { period } = context; const beginningOfPeriod = period.start.getTime() <= new Date().getTime(); if (beginningOfPeriod) { return context; } return null; }, }; }, }; EnrollmentDirector.registerAdapter(LicensedEnrollments); //# sourceMappingURL=licensed.js.map