Skip to content

Comments

fix: billing portal for platform#24088

Merged
Ryukemeister merged 2 commits intomainfrom
update-org-billing-portal-to-handle-platform-sub
Sep 26, 2025
Merged

fix: billing portal for platform#24088
Ryukemeister merged 2 commits intomainfrom
update-org-billing-portal-to-handle-platform-sub

Conversation

@Ryukemeister
Copy link
Contributor

@Ryukemeister Ryukemeister commented Sep 25, 2025

What does this PR do?

  • fix: platform billing portal #23975 updated TeamBillingPortalService.ts to handle platform team billing, but the billing portal in the platform dashboard actually uses OrganizationBillingPortalService.ts hence org billing service needs to be updated as well.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 25, 2025

Walkthrough

This change adds two async helper methods to OrganizationBillingPortalService: getValidatedTeamSubscriptionId(metadata) and getValidatedTeamSubscriptionIdForPlatform(subscriptionId?). getCustomerId is refactored to use these helpers. For platform teams, it reads subscriptionId from team.platformBilling?.subscriptionId; for non-platform teams, it validates and extracts the subscriptionId from team metadata. If no valid subscriptionId is found, it returns null. When a subscriptionId exists, it fetches the subscription, checks for a customer ID, and logs a warning if missing. Error handling logic remains as before.

Possibly related PRs

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Title Check ✅ Passed The title concisely indicates that this pull request fixes the billing portal specifically for platform teams, matching the core change of updating subscription ID handling for platform versus non-platform flows.
Description Check ✅ Passed The pull request description directly addresses the update needed in OrganizationBillingPortalService to handle platform team billing and references the prior related change (#23975), demonstrating that it pertains to the actual changes in this PR.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch update-org-billing-portal-to-handle-platform-sub

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@keithwillcode keithwillcode added core area: core, team members only platform Anything related to our platform plan labels Sep 25, 2025
@Ryukemeister Ryukemeister changed the title fix: update billing portal for platform fix: billing portal for platform Sep 25, 2025
@graphite-app graphite-app bot requested a review from a team September 25, 2025 18:44
@dosubot dosubot bot added billing area: billing, stripe, payments, paypal, get paid 🐛 bug Something isn't working labels Sep 25, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/app-store/stripepayment/lib/services/organization/OrganizationBillingPortalService.ts (2)

27-35: Consider making this helper synchronous and private.

There’s no asynchronous work here, so async only adds promise churn. Making it private also keeps the service surface area tight.

-  async getValidatedTeamSubscriptionId(metadata: Prisma.JsonValue) {
+  private getValidatedTeamSubscriptionId(metadata: Prisma.JsonValue) {

Outside this hunk, the call site can drop the await:

const subscriptionId = this.getValidatedTeamSubscriptionId(team.metadata);

37-43: Same here—no need for async, and private clarifies intent.

This helper is purely synchronous and only used internally, so we can trim the promise wrapper and hide it from the public API.

-  async getValidatedTeamSubscriptionIdForPlatform(subscriptionId?: string | null) {
+  private getValidatedTeamSubscriptionIdForPlatform(subscriptionId?: string | null) {

Then update the call site accordingly:

const subscriptionId = this.getValidatedTeamSubscriptionIdForPlatform(
  team.platformBilling?.subscriptionId
);
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 0ac460f and defbb3a.

📒 Files selected for processing (1)
  • packages/app-store/stripepayment/lib/services/organization/OrganizationBillingPortalService.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*Service.ts

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

Service files must include Service suffix, use PascalCase matching exported class, and avoid generic names (e.g., MembershipService.ts)

Files:

  • packages/app-store/stripepayment/lib/services/organization/OrganizationBillingPortalService.ts
**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

**/*.ts: For Prisma queries, only select data you need; never use include, always use select
Ensure the credential.key field is never returned from tRPC endpoints or APIs

Files:

  • packages/app-store/stripepayment/lib/services/organization/OrganizationBillingPortalService.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js .utc() in hot paths like loops

Files:

  • packages/app-store/stripepayment/lib/services/organization/OrganizationBillingPortalService.ts
**/*.{ts,tsx,js,jsx}

⚙️ CodeRabbit configuration file

Flag default exports and encourage named exports. Named exports provide better tree-shaking, easier refactoring, and clearer imports. Exempt main components like pages, layouts, and components that serve as the primary export of a module.

Files:

  • packages/app-store/stripepayment/lib/services/organization/OrganizationBillingPortalService.ts
🧠 Learnings (1)
📚 Learning: 2025-09-09T03:29:43.025Z
Learnt from: emrysal
PR: calcom/cal.com#23692
File: packages/lib/server/service/InsightsBookingBaseService.ts:16-16
Timestamp: 2025-09-09T03:29:43.025Z
Learning: In the Cal.com codebase, readonlyPrisma is still an instance of PrismaClient, making type changes from `typeof readonlyPrisma` to `PrismaClient` less critical since they are fundamentally compatible types.

Applied to files:

  • packages/app-store/stripepayment/lib/services/organization/OrganizationBillingPortalService.ts
🧬 Code graph analysis (1)
packages/app-store/stripepayment/lib/services/organization/OrganizationBillingPortalService.ts (1)
packages/app-store/stripepayment/lib/subscriptions.ts (1)
  • getSubscriptionFromId (31-33)
🔇 Additional comments (3)
packages/app-store/stripepayment/lib/services/organization/OrganizationBillingPortalService.ts (3)

2-2: Import keeps metadata validation strongly typed.

Pulling in Prisma.JsonValue here makes the helper signatures explicit and keeps validation aligned with Prisma’s JSON typing. Nice touch.


48-65: Clear branching for platform vs. classic teams.

Splitting the subscription lookup paths like this makes the platform handling much easier to follow and keeps the early returns tight.


68-74: Nice reuse of the validated ID in logging.

Threading the vetted subscriptionId through to the warning keeps the log actionable without re-reading metadata.

@Ryukemeister Ryukemeister enabled auto-merge (squash) September 25, 2025 18:58
@vercel
Copy link

vercel bot commented Sep 25, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
cal Ignored Ignored Sep 25, 2025 6:59pm
cal-eu Ignored Ignored Sep 25, 2025 6:59pm

@github-actions
Copy link
Contributor

github-actions bot commented Sep 25, 2025

E2E results are ready!

@Ryukemeister Ryukemeister merged commit dcef99b into main Sep 26, 2025
60 of 63 checks passed
@Ryukemeister Ryukemeister deleted the update-org-billing-portal-to-handle-platform-sub branch September 26, 2025 05:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

billing area: billing, stripe, payments, paypal, get paid 🐛 bug Something isn't working core area: core, team members only platform Anything related to our platform plan ready-for-e2e size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants