feat: stripe integration

This commit is contained in:
Vasily Zubarev
2025-04-24 15:27:44 +02:00
parent 38a5c0f814
commit abd5ad8403
31 changed files with 559 additions and 112 deletions

View File

@@ -5,6 +5,7 @@ import { cache } from "react"
export const SELF_HOSTED_USER = {
email: "taxhacker@localhost",
name: "Self-Hosted Mode",
membershipPlan: "unlimited",
}
export const getSelfHostedUser = cache(async () => {
@@ -13,7 +14,7 @@ export const getSelfHostedUser = cache(async () => {
})
})
export const createSelfHostedUser = cache(async () => {
export const getOrCreateSelfHostedUser = cache(async () => {
return await prisma.user.upsert({
where: { email: SELF_HOSTED_USER.email },
update: SELF_HOSTED_USER,
@@ -21,6 +22,14 @@ export const createSelfHostedUser = cache(async () => {
})
})
export function getOrCreateCloudUser(email: string, data: Prisma.UserCreateInput) {
return prisma.user.upsert({
where: { email },
update: data,
create: data,
})
}
export const getUserById = cache(async (id: string) => {
return await prisma.user.findUnique({
where: { id },
@@ -33,6 +42,12 @@ export const getUserByEmail = cache(async (email: string) => {
})
})
export const getUserByStripeCustomerId = cache(async (customerId: string) => {
return await prisma.user.findFirst({
where: { stripeCustomerId: customerId },
})
})
export function updateUser(userId: string, data: Prisma.UserUpdateInput) {
return prisma.user.update({
where: { id: userId },