Feature #8487
openwe have to notify admin after customer subscribe to any of either product or service subscription. We implemented manage notifications by user actions like manage notifications High priority
100%
Subtasks
Related issues
Updated by Divya Inapakurthi 8 days ago
- Status changed from In Progress to Resolved
Implementation Summary: Subscription Notification System & Cancellation Service
Executed a full overhaul of the automated notification system for Product and Service subscriptions and stabilized the manual cancellation service.
🚀 Key Implementation Points
1. Unified Admin Alert System
Standardized Templates: Integrated
adminSubscriptionAlert.ejs
and
subscription-cancellation-admin.ejs
to handle all internal notification events across all subscription types.
Multi-Channel Dispatch: Leveraging the
notifyUsers
utility to ensure admins receive alerts via Email and SMS based on configured settings.
2. Customer Billing & Cancellation Flow
Billing Recovery: Developed a dedicated
customerPaymentFailed.ejs
template to notify customers of billing issues, maintaining brand standards.
Manual Cancellation Fix: Refactored the
cancelSubscriptionForAllPlans
service to handle Stripe API calls, local DB status updates, and inventory recalculations in a single atomic flow.
Dynamic Price Display: Updated cancellation emails to prioritize the actual historical price from the first transaction in the paymentTransactions array.
3. Webhook Handler Integration
Integrated the
notifyUsers
utility into 8 core backend handlers across Product and Service modules:
checkoutCompleted
invoicePaid
invoicePaymentFailed
subscriptionUpdated
subscriptionDeleted
4. Notification Coverage
Standardized internal subjects (e.g., "Service Subscription Renewed").
Ensured admin coverage across all critical lifecycle events: New Activations, Renewals, Failures, and Cancellations.
🛠️ Issues Resolved
Fixed Reference Errors: Resolved a critical ReferenceError: toTitleCase is not defined that was crashing the email rendering process.
Template Resolution: Relocated administrative templates to src/views/emails/ to ensure the mailer utility can resolve them consistently (fixing ENOENT errors).
Duplicate Prevention: Removed redundant sendEmail calls in the cancellation logic to prevent duplicate notifications during manual vs. webhook cancellations.
Contextual Data Patched: Ensured all necessary helper functions (toTitleCase, formatWebsiteDisplay) and company brand data are passed to the rendering engine.
Service Renewal Gaps: Patched the Service invoicePaid.js handler to include admin alerts for both Off-Store and standard renewal flows.
📝 Technical Notes
Templates Located At:
src/views/emails/subscription-cancellation-admin.ejs
src/views/emails/subscription-cancellation-customer.ejs
src/views/customerPaymentFailed.ejs
Frontend Impact: No UI changes required; the system is dynamic and will automatically display new notification enums in the "Manage Notifications" modal.
Logging: Included real-time console logging for targeted Emails/Phones within the notifyUsers utility for easier delivery monitoring.
Updated by Divya Inapakurthi 7 days ago
- Due date set to 04/02/2026
Daily Progress Report - April 1, 2026
🚀 New Implementations & Configurations
Duplicate Notification Prevention: Implemented cycle-based logic to distinguish between "Initial Activation" and "Subsequent Renewals" for both Service and Product subscriptions, preventing redundant alerts.
Enhanced Subscription Completion Logic: Added robust detection for subscription completion based on both date thresholds (customPlanEndDate) and cycle caps (totalCycles reached).
Notification Event Expansion: Added Product_Subscription_Completed and Service_Subscription_Completed to the notification enums, allowing these events to be configured in settings.
Automated SMS Compliance: Implemented auto-formatting for phone numbers to ensure strict E.164 compliance, resolving Twilio rejection errors caused by spaces and brackets.
Standardized Notification Metadata: Added dynamic Plan Names and Company Branding to all Service and Product subscription SMS and Email alerts.
🛠️ Webhook Logic & Event Classification
Stripe "cancel_at" Fix: Resolved 400 errors by ensuring subscription end dates are scheduled with a buffer to meet Stripe's API requirements.
Cycle-Based Completion Logic: Patched the product subscription webhook to automatically classify events as "Completed" based on cycle cap (cycleNumber >= totalCycles), providing a fallback when date thresholds are missing.
Completion Traceability: Added completion-reason logging to the product webhook to make the classification of "Completed vs Cancelled" traceable in system logs.
Race Condition Mitigation: Fixed a race condition where the invoice.paid webhook arrived before the local subscription record was created by adding a 1000ms mitigation delay.
🛡️ Stability and Error Handling
Installment Payment Crash Guard: Fixed a critical error where one-time (installment) payments crashed the webhook handler by attempting to retrieve a non-existent Stripe Subscription ID.
Negative Count Guard: Added a guard during product variant subscriber decrements to ensure activeSubscribers only decrements when the count is greater than zero.
Notification Reference Fixes: Resolved multiple "LoadModels" and "Date is not defined" reference errors within the product subscription background processes.
EJS Template Fixes: Resolved rendering errors by adding missing message and date properties to administrative and customer email payloads.
Email Context Failures: Fixed "Company not found" failures in tenure completion email services by passing company data directly from the webhook context.
📊 Notification Audit & Verification
System Audit: Conducted an end-to-end audit of the notifyUsers utility, documenting key drop-off points (missing event configs, disabled user preferences, and phone format issues).
Delivery Verification: Confirmed that current cancellation and completion notifications (both Email + SMS) are dispatching successfully for verified events.
SMS Deliverability Check: Identified an India DLT warning status (+91 numbers without DLT_SENDER_ID) which has been documented for future sender ID optimization.
🎨 Standardization & Branding
SMS Formatting: Standardized all automated SMS alerts to follow the format: "Plan: [Plan Name]" and removed generic "Check dashboard" text for a professional brand presentation.
Admin Filtering: Refined role-based user resolution to ensure administrative alerts are sent only to the appropriate, enabled users.
Updated by Divya Inapakurthi about 14 hours ago
- Due date changed from 04/02/2026 to 04/06/2026
- Start date changed from 03/31/2026 to 04/02/2026