Basic Stripe integration. new pages for stripe handshake and new Account page. use query instead of useQuery for trpc fetches from store

This commit is contained in:
Michael Dausmann
2023-03-18 20:37:51 +11:00
parent 2ef98d0d98
commit 7311c13db2
21 changed files with 503 additions and 34 deletions

View File

@@ -40,6 +40,34 @@ export default class UserAccountService {
});
}
async getAccountById(account_id: number): Promise<Account> {
return this.prisma.account.findFirstOrThrow({
where: { id: account_id },
});
}
async updateAccountStipeCustomerId (account_id: number, stripe_customer_id: string){
return await this.prisma.account.update({
where: { id: account_id },
data: {
stripe_customer_id,
}
})
}
async updateStripeSubscriptionDetailsForAccount (stripe_customer_id: string, stripe_subscription_id: string, current_period_ends: Date){
const account = await this.prisma.account.findFirstOrThrow({
where: {stripe_customer_id}
});
return await this.prisma.account.update({
where: { id: account.id },
data: {
stripe_subscription_id,
current_period_ends
}
})
}
async createUser( supabase_uid: string, display_name: string ): Promise<FullDBUser | null> {
const trialPlan = await this.prisma.plan.findFirstOrThrow({ where: { name: TRIAL_PLAN_NAME}});
return this.prisma.user.create({

View File

@@ -7,4 +7,9 @@ export class UtilService {
}
return date;
}
public static getErrorMessage(error: unknown) {
if (error instanceof Error) return error.message
return String(error)
}
}