Skip to content

refactor: Billing service#15366

Merged
zomars merged 82 commits intomainfrom
fix/billing-service
Oct 4, 2024
Merged

refactor: Billing service#15366
zomars merged 82 commits intomainfrom
fix/billing-service

Conversation

@zomars
Copy link
Copy Markdown
Contributor

@zomars zomars commented Jun 7, 2024

What does this PR do?

  • Fixes #XXXX (GitHub issue number)
  • Fixes CAL-XXXX (Linear issue number - should be visible at the bottom of the GitHub issue description)

The goal of this PR is to centralize our internal billing in a shared service. This will allow us to have an overview of all the billing related logic in one place.

  • Implements a stripe web hook handler so we can split big API handlers by webhook event, and lazy load them.

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected)
  • I have added a Docs issue here if this PR makes changes that would require a documentation change
  • I have added or modified automated tests that prove my fix is effective or that my feature works (PRs might be rejected if logical changes are not properly tested)

How should this be tested?

  • Are there environment variables that should be set?
  • What are the minimal test data to have?
  • What is expected (happy path) to have (input and output)?
  • Any other important info that could help to test that PR

Checklist

  • I haven't read the contributing guide
  • My code doesn't follow the style guidelines of this project
  • I haven't commented my code, particularly in hard-to-understand areas
  • I haven't checked if my changes generate no new warnings

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jun 7, 2024

Hey there and thank you for opening this pull request! 👋🏼

We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted.

Details:

Unknown release type "WIP" found in pull request title "WIP: Billing service". 

Available types:
 - feat: A new feature
 - fix: A bug fix
 - docs: Documentation only changes
 - style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
 - refactor: A code change that neither fixes a bug nor adds a feature
 - perf: A code change that improves performance
 - test: Adding missing tests or correcting existing tests
 - build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
 - ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
 - chore: Other changes that don't modify src or test files
 - revert: Reverts a previous commit

@vercel
Copy link
Copy Markdown

vercel bot commented Jun 7, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
ai ⬜️ Ignored (Inspect) Visit Preview Oct 3, 2024 9:22pm
cal ⬜️ Ignored (Inspect) Visit Preview Oct 3, 2024 9:22pm
calcom-web-canary ⬜️ Ignored (Inspect) Visit Preview Oct 3, 2024 9:22pm

zomars added 3 commits June 12, 2024 13:39
Signed-off-by: zomars <zomars@me.com>
Signed-off-by: zomars <zomars@me.com>
@socket-security
Copy link
Copy Markdown

socket-security bot commented Jun 14, 2024

👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

View full report↗︎

Comment thread packages/lib/constants.ts Outdated

const handler = async (data: SWHMap["payment_intent.succeeded"]["data"]) => {
const paymentIntent = data.object;
// TODO: Implement payment intent succeeded webhook handler
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think I left it as a placeholder. RN we handle upgrades via redirect callback. I'm not sure if here we can upgrade expired subscriptions or similar.

Comment thread packages/features/ee/billing/teams/index.ts Outdated
Comment thread packages/lib/server/repository/team.ts Outdated
@keithwillcode
Copy link
Copy Markdown
Contributor

@anikdhabal could we please get your help testing this one?

@anikdhabal
Copy link
Copy Markdown
Contributor

anikdhabal commented Sep 30, 2024

@anikdhabal could we please get your help testing this one?

Sure, I will test this 🙏

Copy link
Copy Markdown
Contributor

@keithwillcode keithwillcode left a comment

Choose a reason for hiding this comment

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

Nice changes overall. Just have some suggestions on responsibilities and naming.

teamId: z.coerce.number(),
});

const handler = async (data: SWHMap["customer.subscription.deleted"]["data"]) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Well doesn't this code look clean, simple and to the point. 🙏

parentId: true,
});

export class TeamBilling {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree with @joeauyeung here. This feels more like a repository rather than a team domain object. We should rename imho.

In DDD, for example, a repository would be used to return data for a team. Then, using just a constructor, static methods like we have here or a factory, you take that data and construct a team object with it. Mixing the two responsibilities here is misleading to the caller.

Comment thread packages/features/ee/billing/teams/internal-team-billing.test.ts
});

describe("cancel", () => {
const internalTeamBilling = new InternalTeamBilling(mockTeam);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What does "Internal" mean here? Is it to describe that this class is handling most of the core logic for team billing? Looking at the class, seems like TeamBillingService would be more fitting since it's doing repository calls and logical changes. i.e. It's orchestrating like an Application Service.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

By internal. It means Cal.com internal billing.

Comment thread packages/features/ee/billing/teams/internal-team-billing.ts Outdated
@@ -0,0 +1,27 @@
import logger from "@calcom/lib/logger";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice approach

@socket-security
Copy link
Copy Markdown

socket-security bot commented Oct 1, 2024

Removed dependencies detected. Learn more about Socket for GitHub ↗︎

View full report↗︎

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Oct 2, 2024

E2E results are ready!

});
});

describe("find", () => {
Copy link
Copy Markdown
Contributor Author

@zomars zomars Oct 3, 2024

Choose a reason for hiding this comment

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

Moved here

Copy link
Copy Markdown
Contributor

@keithwillcode keithwillcode left a comment

Choose a reason for hiding this comment

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

Changes since my feedback look better. We can still optimize not having the static repo on there but can be a follow-up.

Have discussed with zomars and we agreed to put onto qa for testing.

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 ❗️ .env changes contains changes to env variables foundation ready-for-e2e 💻 refactor webhooks area: webhooks, callback, webhook payload

Projects

None yet

Development

Successfully merging this pull request may close these issues.