implementing new payment system + rewrite deploy scripts

This commit is contained in:
Emily
2025-03-28 16:57:57 +01:00
parent 7658dbe85c
commit 7e093251fa
14 changed files with 265 additions and 124 deletions

View File

@@ -1,6 +1,6 @@
export type PREMIUM_TAG = typeof PREMIUM_TAGS[number];
export type PLAN_TAG = typeof PLAN_TAGS[number];
export const PREMIUM_TAGS = [
export const PLAN_TAGS = [
'FREE',
'PLAN_1',
'PLAN_2',
@@ -20,17 +20,17 @@ export const PREMIUM_TAGS = [
] as const;
export type PREMIUM_DATA = {
export type PLAN_DATA = {
COUNT_LIMIT: number,
AI_MESSAGE_LIMIT: number,
PRICE: string,
PRICE_TEST: string,
ID: number,
COST: number,
TAG: PREMIUM_TAG
TAG: PLAN_TAG
}
export const PREMIUM_PLAN: Record<PREMIUM_TAG, PREMIUM_DATA> = {
export const PREMIUM_PLAN: Record<PLAN_TAG, PLAN_DATA> = {
FREE: {
ID: 0,
COUNT_LIMIT: 5_000,
@@ -177,19 +177,19 @@ export const PREMIUM_PLAN: Record<PREMIUM_TAG, PREMIUM_DATA> = {
}
}
export function getPlanFromTag(tag: PREMIUM_TAG) {
export function getPlanFromTag(tag: PLAN_TAG) {
return PREMIUM_PLAN[tag];
}
export function getPlanFromId(id: number) {
for (const tag of PREMIUM_TAGS) {
for (const tag of PLAN_TAGS) {
const plan = getPlanFromTag(tag);
if (plan.ID === id) return plan;
}
}
export function getPlanFromPrice(price: string, testMode: boolean) {
for (const tag of PREMIUM_TAGS) {
for (const tag of PLAN_TAGS) {
const plan = getPlanFromTag(tag);
if (testMode) {
if (plan.PRICE_TEST === price) return plan;

View File

@@ -0,0 +1,22 @@
import { model, Schema, Types } from 'mongoose';
export type TPremium = {
user_id: Schema.Types.ObjectId,
premium_type: number,
customer_id: string,
subscription_id: string,
expire_at: number,
created_at: Date,
}
const PremiumSchema = new Schema<TPremium>({
user_id: { type: Types.ObjectId, unique: true, index: 1 },
customer_id: { type: String },
premium_type: { type: Number },
subscription_id: { type: String },
expire_at: { type: Number },
created_at: { type: Date, default: () => Date.now() }
})
export const PremiumModel = model<TPremium>('premiums', PremiumSchema);

View File

@@ -0,0 +1,26 @@
import { model, Schema, Types } from 'mongoose';
export type TUserLimit = {
_id: Schema.Types.ObjectId,
user_id: Schema.Types.ObjectId,
events: number,
visits: number,
ai_messages: number,
limit: number,
ai_limit: number,
billing_expire_at: Date,
billing_start_at: Date,
}
const UserLimitSchema = new Schema<TUserLimit>({
user_id: { type: Types.ObjectId, index: true, unique: true },
events: { type: Number, required: true, default: 0 },
visits: { type: Number, required: true, default: 0 },
ai_messages: { type: Number, required: true, default: 0 },
limit: { type: Number, required: true },
ai_limit: { type: Number, required: true },
billing_start_at: { type: Date, required: true },
billing_expire_at: { type: Date, required: true },
});
export const UserLimitModel = model<TUserLimit>('user_limits', UserLimitSchema);

View File

@@ -7,14 +7,6 @@ export type TUser = {
locale: string,
picture: string,
created_at: Date,
google_tokens?: {
refresh_token?: string;
expiry_date?: number;
access_token?: string;
token_type?: string;
id_token?: string;
scope?: string;
}
}
const UserSchema = new Schema<TUser>({
@@ -22,15 +14,7 @@ const UserSchema = new Schema<TUser>({
name: String,
given_name: String,
locale: String,
picture: String,
google_tokens: {
refresh_token: String,
expiry_date: Number,
access_token: String,
token_type: String,
id_token: String,
scope: String
},
picture: String,
created_at: { type: Date, default: () => Date.now() }
})

View File

@@ -4,22 +4,12 @@ export type TProject = {
_id: Schema.Types.ObjectId,
owner: Schema.Types.ObjectId,
name: string,
premium: boolean,
premium_type: number,
customer_id: string,
subscription_id: string,
premium_expire_at: Date,
created_at: Date
}
const ProjectSchema = new Schema<TProject>({
owner: { type: Types.ObjectId, index: 1 },
name: { type: String, required: true },
premium: { type: Boolean, default: false },
premium_type: { type: Number, default: 0 },
customer_id: { type: String, required: true },
subscription_id: { type: String, required: true },
premium_expire_at: { type: Date, required: true },
created_at: { type: Date, default: () => Date.now() },
})