fix: add items from stash

This commit is contained in:
Mythie
2023-08-30 16:36:22 +10:00
parent c3f11afaf9
commit d7bd8fcd37
11 changed files with 129 additions and 10 deletions

View File

@ -1 +0,0 @@
<!-- This is a stub -->

View File

@ -1,32 +0,0 @@
import { prisma } from '@documenso/prisma';
import { User } from '@documenso/prisma/client';
import { stripe } from '../../server-only/stripe';
import { getSubscriptionByUserId } from '../../server-only/subscription/get-subscription-by-user-id';
export type CreateCustomerOptions = {
user: User;
};
export const createCustomer = async ({ user }: CreateCustomerOptions) => {
const existingSubscription = await getSubscriptionByUserId({ userId: user.id });
if (existingSubscription) {
throw new Error('User already has a subscription');
}
const customer = await stripe.customers.create({
name: user.name ?? undefined,
email: user.email,
metadata: {
userId: user.id,
},
});
return await prisma.subscription.create({
data: {
userId: user.id,
customerId: customer.id,
},
});
};

View File

@ -1,19 +0,0 @@
'use server';
import { stripe } from '../../server-only/stripe';
export type GetPortalSessionOptions = {
customerId: string;
returnUrl: string;
};
export const getPortalSession = async ({ customerId, returnUrl }: GetPortalSessionOptions) => {
'use server';
const session = await stripe.billingPortal.sessions.create({
customer: customerId,
return_url: returnUrl,
});
return session.url;
};

View File

@ -3,7 +3,7 @@
"version": "1.0.0",
"main": "./index.ts",
"types": "./index.ts",
"license": "SEE LICENSE IN LICENSE.md",
"license": "SEE LICENSE IN LICENSE",
"files": [
"client-only/",
"server-only/",