Files
sign/packages/ee/server-only/stripe/get-checkout-session.ts

36 lines
777 B
TypeScript
Raw Normal View History

import type Stripe from 'stripe';
2023-10-13 23:33:40 +11:00
import { stripe } from '@documenso/lib/server-only/stripe';
export type GetCheckoutSessionOptions = {
customerId: string;
priceId: string;
returnUrl: string;
subscriptionMetadata?: Stripe.Metadata;
2023-10-13 23:33:40 +11:00
};
export const getCheckoutSession = async ({
customerId,
priceId,
returnUrl,
subscriptionMetadata,
2023-10-13 23:33:40 +11:00
}: GetCheckoutSessionOptions) => {
const session = await stripe.checkout.sessions.create({
customer: customerId,
2023-10-19 12:27:01 +11:00
mode: 'subscription',
2023-10-13 23:33:40 +11:00
line_items: [
{
price: priceId,
quantity: 1,
},
],
success_url: `${returnUrl}?success=true`,
cancel_url: `${returnUrl}?canceled=true`,
subscription_data: {
metadata: subscriptionMetadata,
},
2023-10-13 23:33:40 +11:00
});
return session.url;
};