(subscription: any)
| 635 | * Send welcome email for Pro and Team plan subscriptions |
| 636 | */ |
| 637 | export async function sendPlanWelcomeEmail(subscription: any): Promise<void> { |
| 638 | try { |
| 639 | const subPlan = subscription.plan |
| 640 | if (isPlanPro(subPlan) || isPlanTeam(subPlan)) { |
| 641 | const userId = subscription.referenceId |
| 642 | const users = await db |
| 643 | .select({ email: user.email, name: user.name }) |
| 644 | .from(user) |
| 645 | .where(eq(user.id, userId)) |
| 646 | .limit(1) |
| 647 | |
| 648 | if (users.length > 0 && users[0].email) { |
| 649 | const { getEmailSubject, renderPlanWelcomeEmail } = await import('@/components/emails') |
| 650 | const { sendEmail } = await import('@/lib/messaging/email/mailer') |
| 651 | |
| 652 | const baseUrl = getBaseUrl() |
| 653 | const { getDisplayPlanName } = await import('@/lib/billing/plan-helpers') |
| 654 | const html = await renderPlanWelcomeEmail({ |
| 655 | planName: getDisplayPlanName(subPlan), |
| 656 | userName: users[0].name || undefined, |
| 657 | loginLink: `${baseUrl}/login`, |
| 658 | }) |
| 659 | |
| 660 | const displayName = getDisplayPlanName(subPlan) |
| 661 | await sendEmail({ |
| 662 | to: users[0].email, |
| 663 | subject: `Your ${displayName} plan is now active on ${(await import('@/ee/whitelabeling')).getBrandConfig().name}`, |
| 664 | html, |
| 665 | emailType: 'updates', |
| 666 | }) |
| 667 | |
| 668 | logger.info('Plan welcome email sent successfully', { |
| 669 | userId, |
| 670 | email: users[0].email, |
| 671 | plan: subPlan, |
| 672 | }) |
| 673 | } |
| 674 | } |
| 675 | } catch (error) { |
| 676 | logger.error('Failed to send plan welcome email', { |
| 677 | error, |
| 678 | subscriptionId: subscription.id, |
| 679 | plan: subscription.plan, |
| 680 | }) |
| 681 | throw error |
| 682 | } |
| 683 | } |
no test coverage detected