2021-09-28 05:30:01 -04:00
|
|
|
const EmailHandler = require('../Email/EmailHandler')
|
|
|
|
const UserGetter = require('../User/UserGetter')
|
|
|
|
require('./SubscriptionEmailBuilder')
|
2022-04-25 07:05:44 -04:00
|
|
|
const PlansLocator = require('./PlansLocator')
|
2021-09-28 05:30:01 -04:00
|
|
|
|
|
|
|
const SubscriptionEmailHandler = {
|
2022-04-25 07:05:44 -04:00
|
|
|
async sendTrialOnboardingEmail(userId, planCode) {
|
2021-09-28 05:30:01 -04:00
|
|
|
const user = await UserGetter.promises.getUser(userId, {
|
|
|
|
email: 1,
|
|
|
|
})
|
|
|
|
|
2022-04-25 07:05:44 -04:00
|
|
|
const plan = PlansLocator.findLocalPlanInSettings(planCode)
|
|
|
|
if (!plan) {
|
|
|
|
throw new Error('unknown paid plan: ' + planCode)
|
|
|
|
}
|
2021-09-28 05:30:01 -04:00
|
|
|
const emailOptions = {
|
|
|
|
to: user.email,
|
|
|
|
sendingUser_id: userId,
|
2022-04-25 07:05:44 -04:00
|
|
|
planName: plan.name,
|
|
|
|
features: plan.features,
|
2021-09-28 05:30:01 -04:00
|
|
|
}
|
|
|
|
await EmailHandler.promises.sendEmail('trialOnboarding', emailOptions)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = SubscriptionEmailHandler
|