New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Billing Service #14756
Merged
+663
−132
Merged
feat: Billing Service #14756
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
bd742e2
chore: Billing Service
exception ea44e0b
chore: others
exception ad487c7
chore: don't type
exception cbdb86a
chore: typo
exception b63aea8
chore: use proper wh secret
exception 78769b9
chore: updates
exception 48db4f2
Merge remote-tracking branch 'origin/main' into chore/platform-billing
exception 48d4cf8
chore: lockfile
exception e68ff2f
chore: docs and comment out
exception e3822be
chore: updates and include plan
exception 96c7b14
chore: config
exception 6908369
chore: bring back alias
exception 663dea8
chore: update lockfile
exception e58a316
Merge branch 'main' into chore/platform-billing
exception 5ba3255
chore: refactor
exception 1f8f215
chore: default none plan in db
exception 984db6f
chore: read from env vars
exception 4f4f0b3
chore: feedback
exception c004642
chore: remove json config
exception 7d9dbca
Merge branch 'main' into chore/platform-billing
exception 330d82e
chore: proper type
exception edfe409
Merge branch 'chore/platform-billing' of github.com:calcom/cal.com in…
exception File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Injectable, NestMiddleware } from "@nestjs/common"; | ||
import * as bodyParser from "body-parser"; | ||
import type { Request, Response } from "express"; | ||
|
||
@Injectable() | ||
export class JsonBodyMiddleware implements NestMiddleware { | ||
use(req: Request, res: Response, next: () => any) { | ||
bodyParser.json()(req, res, next); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Injectable, NestMiddleware } from "@nestjs/common"; | ||
import * as bodyParser from "body-parser"; | ||
import type { Request, Response } from "express"; | ||
|
||
@Injectable() | ||
export class RawBodyMiddleware implements NestMiddleware { | ||
use(req: Request, res: Response, next: () => any) { | ||
bodyParser.raw({ type: "*/*" })(req, res, next); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { BillingRepository } from "@/modules/billing/billing.repository"; | ||
import { BillingController } from "@/modules/billing/controllers/billing.controller"; | ||
import { BillingConfigService } from "@/modules/billing/services/billing.config.service"; | ||
import { BillingService } from "@/modules/billing/services/billing.service"; | ||
import { MembershipsModule } from "@/modules/memberships/memberships.module"; | ||
import { OrganizationsModule } from "@/modules/organizations/organizations.module"; | ||
import { PrismaModule } from "@/modules/prisma/prisma.module"; | ||
import { StripeModule } from "@/modules/stripe/stripe.module"; | ||
import { Module } from "@nestjs/common"; | ||
|
||
@Module({ | ||
imports: [PrismaModule, StripeModule, MembershipsModule, OrganizationsModule], | ||
providers: [BillingConfigService, BillingService, BillingRepository], | ||
exports: [BillingService, BillingRepository], | ||
controllers: [BillingController], | ||
}) | ||
export class BillingModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { PlatformPlan } from "@/modules/billing/types"; | ||
import { PrismaReadService } from "@/modules/prisma/prisma-read.service"; | ||
import { PrismaWriteService } from "@/modules/prisma/prisma-write.service"; | ||
import { Injectable } from "@nestjs/common"; | ||
|
||
@Injectable() | ||
export class BillingRepository { | ||
constructor(private readonly dbRead: PrismaReadService, private readonly dbWrite: PrismaWriteService) {} | ||
|
||
getBillingForTeam = (teamId: number) => | ||
this.dbRead.prisma.platformBilling.findUnique({ | ||
where: { | ||
id: teamId, | ||
}, | ||
}); | ||
|
||
async updateTeamBilling( | ||
teamId: number, | ||
billingStart: number, | ||
billingEnd: number, | ||
plan: PlatformPlan, | ||
subscription?: string | ||
) { | ||
return this.dbWrite.prisma.platformBilling.update({ | ||
where: { | ||
id: teamId, | ||
}, | ||
data: { | ||
billingCycleStart: billingStart, | ||
billingCycleEnd: billingEnd, | ||
subscriptionId: subscription, | ||
plan: plan.toString(), | ||
}, | ||
}); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stripe requires a Buffer/String for the Webhooks to be built. Since NestJS by default parses everything as JSON, this was not letting the event through. That's why this change was required.