Project

General

Profile

Edit Copy Actions

Bug #11939

open

Subscription production issues

Added by Divya Inapakurthi about 2 hours ago. Updated about 2 hours ago.

Status:
New
Priority:
Normal
Target version:
-
Start date:
11/02/2026
Due date:
% Done:

100%

Estimated time:
Spent time:
Tested Date:
11/02/2026
Raised by Tester:
Page/ Module (POS):
Subscriptions – Subscribers

Add

Subtasks


Add

Related issues

Updated by Divya Inapakurthi about 2 hours ago

1. Duplicate Settlement Invoice Dispatch & Double-Click Prevention
Issue: Repeated settlement invoices and duplicate emails were being sent upon subscription cancellation or when triggered via the UI/cron.
Fix:
Added backend deduplication and a 60-second debounce guard in sendSettlementInvoice to prevent re-sending already dispatched settlement invoices.
Cron (subscriptionAutoCancelCron.js) and cutoff finalization now verify settlementStatus !== 'invoice_sent' before dispatching.
Added button loading/disabled states (isConfirming, settlementActionLoading) on the frontend (CancelSubscriptionButton.tsx, Subscribers.tsx, SubscriptionDetail.tsx) to prevent double-clicks.
Ensured immediate cancellation only auto-sends an invoice when explicitly configured (settlementAction === "send_invoice" or customer self-cancel).
2. Multi-tenant Database Connection Race Condition
Issue: High-concurrency requests or multiple simultaneous webhooks caused overlapping connection creation attempts to the same tenant database. Also, quotation acceptance threw an error due to a static model reference string.
Fix:
Implemented in-flight promise tracking (connectionPromises) in dbUtils.js to eliminate race conditions and pool exhaustion.
Fixed model populate reference in QuotationController.js (getAcceptQuotationWithSubscription) to use dynamic tenant SubscriptionPlan instead of static "Subscription".
3. Stripe Payment Failure Webhook Duplication & False Alerts
Issue: Stripe triggers charge.failed, payment_intent.payment_failed, and invoice.payment_failed for a single failure, causing triplicate SMS/email notifications and duplicate history entries.
Fix:
Routed all payment failure handling authoritatively through invoice.payment_failed in serviceWebhook.controller.js and ignored redundant charge/payment intent events.
Added processedPaymentFailedAttempts and processedStripeInvoiceIds arrays on SubscriptionContract for idempotency.
Strengthened contract lookup logic in invoicePaymentFailed.js to prevent matching incorrect contracts when a customer has multiple subscriptions.
4. False "Past-Due" Status & Job Unhold Recovery
Issue: Any open Stripe invoice was previously treated as past due, leading to contracts being incorrectly flagged as past due and jobs placed on hold unnecessarily.
Fix:
Filtered open invoices to only flag genuinely past-due ones (checks attempt_count > 0, overdue due_date, or active retry state).
Improved restoreOnHoldJobsForSubscription to prevent restoring to a hold status if previousStatus itself was a hold status.
Synchronized Stripe subscription metadata (internalStatus = "active") when an invoice is successfully paid.
5. Custom Visit Schedule Persistence & Email Rendering
Issue: Custom visit schedules configured on quotations were not properly transferring to the subscription contract upon checkout, causing missing or incorrect schedule tables in confirmation emails.
Fix:
Re-enabled effectiveVisitSchedule = customVisitSchedule in createQuotationFromPlan.
Preserved customVisitSchedule through checkout session creation (createSubscriptionCheckout) and completion (checkoutCompleted.js).
Updated email templates (subscriptionPayemtRecievedOnStore.ejs, subscriptionPayemtRecievedOffStore.ejs) and repair utilities to render custom schedules correctly.
6. Subscription Plans Listing, Filters & Variant Summary
Issue: Subscription plan search did not filter by variant or service name, and variant counts were missing in the UI.
Fix:
Added search on variants.name and services.serviceName in backend subscripiton.service.js.
Added aggregation summary (totalPlans, diamondCount, goldCount, silverCount).
Updated frontend SubscriptionsPlans.tsx with dynamic summary metrics, plan type filtering, and expandable variant/service breakdowns.

Actions #2

Updated by Divya Inapakurthi about 2 hours ago

  • % Done changed from 0 to 100
Edit Copy Actions

Also available in: Atom PDF