mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 00:03:33 +10:00
21 lines
718 B
TypeScript
21 lines
718 B
TypeScript
'use server';
|
|
|
|
import { env } from 'next-runtime-env';
|
|
|
|
import { getStripeCustomerByUser } from '@documenso/ee/server-only/stripe/get-customer';
|
|
import { getPortalSession } from '@documenso/ee/server-only/stripe/get-portal-session';
|
|
import { getRequiredServerComponentSession } from '@documenso/lib/next-auth/get-server-component-session';
|
|
|
|
export const createBillingPortal = async () => {
|
|
const NEXT_PUBLIC_WEBAPP_URL = env('NEXT_PUBLIC_WEBAPP_URL');
|
|
|
|
const { user } = await getRequiredServerComponentSession();
|
|
|
|
const { stripeCustomer } = await getStripeCustomerByUser(user);
|
|
|
|
return getPortalSession({
|
|
customerId: stripeCustomer.id,
|
|
returnUrl: `${NEXT_PUBLIC_WEBAPP_URL}/settings/billing`,
|
|
});
|
|
};
|