feat: Billing Service (#14756)

* chore: Billing Service

* chore: others

* chore: don't type

* chore: typo

* chore: use proper wh secret

* chore: updates

* chore: lockfile

* chore: docs and comment out

* chore: updates and include plan

* chore: config

* chore: bring back alias

* chore: update lockfile

* chore: refactor

* chore: default none plan in db

* chore: read from env vars

* chore: feedback

* chore: remove json config

* chore: proper type
This commit is contained in:
Erik authored and GitHub committed 2024-04-30 20:02:04 +00:00
1 parent a51024e915
commit 1cfd2f7053
38 files changed
+664 -133

No files matched your search

+1
View File
@@ -9,6 +9,7 @@ export const V2_ENDPOINTS = {
export const SUCCESS_STATUS = "success";
export const ERROR_STATUS = "error";
export const REDIRECT_STATUS = "redirect";
// Client Errors (4xx)
export const BAD_REQUEST = "BAD_REQUEST";
export const UNAUTHORIZED = "UNAUTHORIZED";
+9 -1
View File
@@ -2,7 +2,12 @@ import { Transform } from "class-transformer";
import { IsNumber, Min, Max, IsOptional } from "class-validator";
import type { Response as BaseResponse } from "express";
import type { ERROR_STATUS, SUCCESS_STATUS, API_ERROR_CODES } from "@calcom/platform-constants";
import type {
ERROR_STATUS,
SUCCESS_STATUS,
API_ERROR_CODES,
REDIRECT_STATUS,
} from "@calcom/platform-constants";
export type ApiSuccessResponse<T> = { status: typeof SUCCESS_STATUS; data: T };
export type ApiSuccessResponseWithoutData = { status: typeof SUCCESS_STATUS };
@@ -23,6 +28,7 @@ export type ApiErrorResponse = {
};
export type ApiRedirectResponseType = {
status: typeof REDIRECT_STATUS;
url: string;
};
@@ -32,6 +38,8 @@ export type ApiResponse<T = undefined> = T extends undefined
? ApiSuccessResponseWithoutData | ApiErrorResponse
: ApiSuccessResponse<T> | ApiErrorResponse;
export type ApiResponseMaybeRedirect<T = undefined> = ApiResponse<T> | ApiRedirectResponseType;
export class Pagination {
@Transform(({ value }: { value: string }) => value && parseInt(value))
@IsNumber()
@@ -0,0 +1,21 @@
-- CreateTable
CREATE TABLE "PlatformBilling" (
"id" INTEGER NOT NULL,
"customerId" TEXT NOT NULL,
"plan" TEXT NOT NULL DEFAULT 'none',
"subscriptionId" TEXT,
"billingCycleStart" INTEGER,
"billingCycleEnd" INTEGER,
"overdue" BOOLEAN DEFAULT false,
CONSTRAINT "PlatformBilling_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "PlatformBilling_id_key" ON "PlatformBilling"("id");
-- CreateIndex
CREATE UNIQUE INDEX "PlatformBilling_customerId_key" ON "PlatformBilling"("customerId");
-- AddForeignKey
ALTER TABLE "PlatformBilling" ADD CONSTRAINT "PlatformBilling_id_fkey" FOREIGN KEY ("id") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE;
+15
View File
@@ -400,6 +400,7 @@ model Team {
isPlatform Boolean @default(false)
platformOAuthClient PlatformOAuthClient[]
smsLockState SMSLockState @default(UNLOCKED)
platformBilling PlatformBilling?
@@unique([slug, parentId])
@@index([parentId])
@@ -1357,3 +1358,17 @@ enum SMSLockState {
UNLOCKED
REVIEW_NEEDED
}
model PlatformBilling {
id Int @id @unique // team id
customerId String @unique
subscriptionId String?
plan String
billingCycleStart Int?
billingCycleEnd Int?
overdue Boolean? @default(false)
team Team @relation(fields: [id], references: [id], onDelete: Cascade)
}