Skip to content

Comments

refactor: team and org billing portal service#24497

Merged
Ryukemeister merged 9 commits intomainfrom
refactor-billing-services
Oct 28, 2025
Merged

refactor: team and org billing portal service#24497
Ryukemeister merged 9 commits intomainfrom
refactor-billing-services

Conversation

@Ryukemeister
Copy link
Contributor

What does this PR do?

  • This PR refactors team and org billing portal service to make em both reuse same functions from lib instead of having the same logic twice at two different places

@keithwillcode keithwillcode added core area: core, team members only platform Anything related to our platform plan labels Oct 15, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 15, 2025

Walkthrough

This pull request refactors subscription validation logic by centralizing two validation methods into the base BillingPortalService class. The methods getValidatedTeamSubscriptionId and getValidatedTeamSubscriptionIdForPlatform are removed from OrganizationBillingPortalService and TeamBillingPortalService, then added as protected methods to the base class. Both child services are updated to import and call these centralized helpers instead of maintaining their own implementations. Import statements are adjusted accordingly in all affected files.

Possibly related PRs

  • fix: billing portal for platform #24088: Modifies the same subscription-ID validation and customer-retrieval logic for billing portal services, establishing related validation patterns.
  • fix: platform billing portal #23975: Directly touches the same getValidatedTeamSubscriptionId and getValidatedTeamSubscriptionIdForPlatform validation logic with platform-vs-non-platform handling.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The PR title "refactor: team and org billing portal service" is directly related to the main changes in the changeset. The raw summary shows that methods were removed from both OrganizationBillingPortalService and TeamBillingPortalService, while new protected methods were added to the base BillingPortalService class. This consolidation of shared validation logic into a base class is precisely what the title describes—a refactoring of the team and org billing portal services. The title is concise, clear, and accurately summarizes the primary intent of the changeset.
Description Check ✅ Passed The PR description is related to the changeset and conveys meaningful information about the refactoring. It explicitly states that the team and org billing portal services are being refactored to reuse the same functions from a shared library instead of duplicating logic in two places. This accurately reflects what the raw summary shows: common validation methods were extracted from individual services and moved to the base BillingPortalService class. The description is not vague or off-topic and demonstrates a clear understanding of the refactoring objective.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor-billing-services

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.

@graphite-app graphite-app bot requested a review from a team October 15, 2025 21:56
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: 3

🧹 Nitpick comments (2)
packages/app-store/stripepayment/lib/getValidatedTeamSubscriptionId.ts (1)

1-12: Add JSDoc documentation for the exported helper.

Consider adding JSDoc to describe the function's purpose, parameters, and return value for better maintainability.

/**
 * Validates and extracts the subscription ID from team metadata.
 * 
 * @param metadata - The team metadata as Prisma.JsonValue
 * @returns The subscription ID if valid, null otherwise
 */
export const getValidatedTeamSubscriptionId = (metadata: Prisma.JsonValue) => {
  // ...
};
packages/app-store/stripepayment/lib/getValidatedTeamSubscriptionIdForPlatform.ts (1)

1-7: Consider simplifying or inlining this trivial helper.

This function is a simple null-check that could be expressed as subscriptionId || null or subscriptionId ?? null. Consider whether extracting such a trivial operation into a separate module adds meaningful value or if it would be clearer to inline at call sites.

If you choose to keep the helper, consider adding JSDoc:

/**
 * Validates and returns the platform subscription ID.
 * 
 * @param subscriptionId - The subscription ID to validate
 * @returns The subscription ID if truthy, null otherwise
 */
export const getValidatedTeamSubscriptionIdForPlatform = (subscriptionId?: string | null) => {
  return subscriptionId || null;
};
📜 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 5731321 and add8476.

📒 Files selected for processing (4)
  • packages/app-store/stripepayment/lib/getValidatedTeamSubscriptionId.ts (1 hunks)
  • packages/app-store/stripepayment/lib/getValidatedTeamSubscriptionIdForPlatform.ts (1 hunks)
  • packages/app-store/stripepayment/lib/services/organization/OrganizationBillingPortalService.ts (2 hunks)
  • packages/app-store/stripepayment/lib/services/team/TeamBillingPortalService.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
  • packages/app-store/stripepayment/lib/services/team/TeamBillingPortalService.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
  • packages/app-store/stripepayment/lib/getValidatedTeamSubscriptionIdForPlatform.ts
  • packages/app-store/stripepayment/lib/getValidatedTeamSubscriptionId.ts
  • packages/app-store/stripepayment/lib/services/team/TeamBillingPortalService.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
  • packages/app-store/stripepayment/lib/getValidatedTeamSubscriptionIdForPlatform.ts
  • packages/app-store/stripepayment/lib/getValidatedTeamSubscriptionId.ts
  • packages/app-store/stripepayment/lib/services/team/TeamBillingPortalService.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
  • packages/app-store/stripepayment/lib/getValidatedTeamSubscriptionIdForPlatform.ts
  • packages/app-store/stripepayment/lib/getValidatedTeamSubscriptionId.ts
  • packages/app-store/stripepayment/lib/services/team/TeamBillingPortalService.ts
🧬 Code graph analysis (2)
packages/app-store/stripepayment/lib/services/organization/OrganizationBillingPortalService.ts (2)
packages/app-store/stripepayment/lib/getValidatedTeamSubscriptionIdForPlatform.ts (1)
  • getValidatedTeamSubscriptionIdForPlatform (1-7)
packages/app-store/stripepayment/lib/getValidatedTeamSubscriptionId.ts (1)
  • getValidatedTeamSubscriptionId (4-12)
packages/app-store/stripepayment/lib/services/team/TeamBillingPortalService.ts (2)
packages/app-store/stripepayment/lib/getValidatedTeamSubscriptionIdForPlatform.ts (1)
  • getValidatedTeamSubscriptionIdForPlatform (1-7)
packages/app-store/stripepayment/lib/getValidatedTeamSubscriptionId.ts (1)
  • getValidatedTeamSubscriptionId (4-12)
🔇 Additional comments (4)
packages/app-store/stripepayment/lib/services/team/TeamBillingPortalService.ts (2)

4-5: LGTM! Clean extraction of validation logic.

The import of shared helper functions successfully consolidates the validation logic and removes code duplication.


38-38: Consider removing await if helper becomes synchronous.

If the suggestion to remove async from getValidatedTeamSubscriptionId is accepted, this await can also be removed for consistency.

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

4-5: LGTM! Consistent refactoring across services.

The shared helper functions are now being used consistently in both organization and team billing services, successfully eliminating code duplication.


43-43: Consider removing await if helper becomes synchronous.

If the suggestion to remove async from getValidatedTeamSubscriptionId is accepted, this await can also be removed for consistency.

@dosubot dosubot bot added billing area: billing, stripe, payments, paypal, get paid 💻 refactor labels Oct 15, 2025
@vercel
Copy link

vercel bot commented Oct 15, 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 Oct 28, 2025 11:10am
cal-eu Ignored Ignored Oct 28, 2025 11:10am

Copy link
Member

@sean-brydon sean-brydon left a comment

Choose a reason for hiding this comment

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

Lets put these functions on the base service instead of creating a new util for them

@github-actions github-actions bot marked this pull request as draft October 16, 2025 09:00
@Ryukemeister Ryukemeister dismissed sean-brydon’s stale review October 16, 2025 21:10

implemented feedback!

@Ryukemeister Ryukemeister marked this pull request as ready for review October 16, 2025 21:10
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 (1)
packages/app-store/stripepayment/lib/services/base/BillingPortalService.ts (1)

77-82: Consider simplifying the null check.

The method can be reduced to a single line using the nullish coalescing operator.

Apply this diff to simplify:

 protected getValidatedTeamSubscriptionIdForPlatform(subscriptionId?: string | null) {
-  if (!subscriptionId) {
-    return null;
-  }
-  return subscriptionId;
+  return subscriptionId ?? null;
 }
📜 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 ef66452 and 1d5aa54.

📒 Files selected for processing (3)
  • packages/app-store/stripepayment/lib/services/base/BillingPortalService.ts (2 hunks)
  • packages/app-store/stripepayment/lib/services/organization/OrganizationBillingPortalService.ts (1 hunks)
  • packages/app-store/stripepayment/lib/services/team/TeamBillingPortalService.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/app-store/stripepayment/lib/services/team/TeamBillingPortalService.ts
🧰 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/base/BillingPortalService.ts
  • 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/base/BillingPortalService.ts
  • 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/base/BillingPortalService.ts
  • 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/base/BillingPortalService.ts
  • packages/app-store/stripepayment/lib/services/organization/OrganizationBillingPortalService.ts
⏰ Context from checks skipped due to timeout of 180000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Linters / lint
  • GitHub Check: Type check / check-types
  • GitHub Check: Tests / Unit
🔇 Additional comments (4)
packages/app-store/stripepayment/lib/services/base/BillingPortalService.ts (2)

9-10: LGTM! Imports support the new validation methods.

The new imports are necessary for the validation methods added below.


67-75: LGTM! Solid validation logic.

The method correctly parses team metadata using Zod schema validation and safely extracts the subscription ID. The early return pattern makes the logic clear.

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

34-36: LGTM! Correctly calling synchronous validation.

The method is called synchronously without await, which is correct since getValidatedTeamSubscriptionIdForPlatform doesn't return a Promise. Good fix from the previous review.


41-41: LGTM! Proper use of base class validation.

The refactor successfully delegates validation to the base class method, eliminating code duplication.

@github-actions
Copy link
Contributor

This PR has been marked as stale due to inactivity. If you're still working on it or need any help, please let us know or update the PR to keep it active.

@github-actions github-actions bot added the Stale label Oct 27, 2025
@Ryukemeister Ryukemeister enabled auto-merge (squash) October 28, 2025 09:17
@github-actions
Copy link
Contributor

github-actions bot commented Oct 28, 2025

E2E results are ready!

@Ryukemeister Ryukemeister merged commit 1dade81 into main Oct 28, 2025
35 of 36 checks passed
@Ryukemeister Ryukemeister deleted the refactor-billing-services branch October 28, 2025 11:42
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 core area: core, team members only platform Anything related to our platform plan ready-for-e2e 💻 refactor size/M Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants