Skip to content

Billing - Fix#18135

Merged
charlesBochet merged 2 commits intomainfrom
ej/fix-billing
Feb 23, 2026
Merged

Billing - Fix#18135
charlesBochet merged 2 commits intomainfrom
ej/fix-billing

Conversation

@etiennejouan
Copy link
Copy Markdown
Contributor

@etiennejouan etiennejouan commented Feb 20, 2026

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Feb 20, 2026

Greptile Summary

This PR fixes billing subscription cleanup during workspace deletion by ensuring subscriptions are properly canceled before deletion and using explicit type-safe checks.

Key Changes:

  • Replaced truthy check with explicit isDefined() check in billing-subscription.service.ts:154 for better type safety and consistency with codebase patterns
  • Added billingSubscriptionService.deleteSubscriptions() call in batchCleanOnboardingWorkspaces (cleaner.workspace-service.ts:309) to properly clean up subscriptions before deleting onboarding workspaces
  • Injected BillingSubscriptionService dependency into CleanerWorkspaceService constructor (cleaner.workspace-service.ts:63)

Confidence Score: 4/5

  • This PR is safe to merge with one potential concern around billing enablement checks
  • The changes are focused and correct, but there's an inconsistency: batchCleanOnboardingWorkspaces unconditionally calls deleteSubscriptions without checking if billing is enabled, while workspace.service.ts checks isBillingEnabled() before calling the same method. This inconsistency should be addressed.
  • Pay attention to cleaner.workspace-service.ts line 309 - verify billing enablement check is needed

Important Files Changed

Filename Overview
packages/twenty-server/src/engine/core-modules/billing/services/billing-subscription.service.ts Changed truthy check to explicit isDefined() check in deleteSubscriptions method for better type safety
packages/twenty-server/src/engine/workspace-manager/workspace-cleaner/services/cleaner.workspace-service.ts Added billing subscription cleanup call before workspace deletion in batchCleanOnboardingWorkspaces method

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[batchCleanOnboardingWorkspaces] --> B{Find workspaces in<br/>PENDING_CREATION or<br/>ONGOING_CREATION status}
    B --> C{Workspaces found?}
    C -->|No| D[End]
    C -->|Yes| E{Dry run?}
    E -->|Yes| F[Log operation only]
    E -->|No| G[For each workspace]
    G --> H[Find user workspaces]
    H --> I[For each user workspace]
    I --> J[handleRemoveWorkspaceMember]
    J --> K{More users?}
    K -->|Yes| I
    K -->|No| L[deleteSubscriptions - NEW]
    L --> M{subscriptionToCancel<br/>isDefined?}
    M -->|Yes| N[cancelSubscription<br/>in Stripe]
    M -->|No| O[Skip Stripe cancel]
    N --> P[Delete from DB]
    O --> P
    P --> Q[Delete workspace from DB]
    Q --> R{More workspaces?}
    R -->|Yes| G
    R -->|No| S[Log completion]
    F --> D
    S --> D
Loading

Last reviewed commit: 5edbe9b

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 20, 2026

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:50929

This environment will automatically shut down when the PR is closed or after 5 hours.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

…cleaner/services/cleaner.workspace-service.ts

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

@etiennejouan etiennejouan added this pull request to the merge queue Feb 23, 2026
@charlesBochet charlesBochet removed this pull request from the merge queue due to a manual request Feb 23, 2026
@charlesBochet charlesBochet merged commit 7cbbd08 into main Feb 23, 2026
65 of 68 checks passed
@charlesBochet charlesBochet deleted the ej/fix-billing branch February 23, 2026 11:13
@twenty-eng-sync
Copy link
Copy Markdown

Hey @etiennejouan! After you've done the QA of your Pull Request, you can mark it as done here. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Billing issue - Investigate Sub <> Workspace de-sync

3 participants