mirror of
https://github.com/documenso/documenso.git
synced 2025-11-14 08:42:12 +10:00
fix: update customer handling for checkouts
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
'use server';
|
'use server';
|
||||||
|
|
||||||
|
import { createCustomer } from '@documenso/ee/server-only/stripe/create-customer';
|
||||||
import { getCheckoutSession } from '@documenso/ee/server-only/stripe/get-checkout-session';
|
import { getCheckoutSession } from '@documenso/ee/server-only/stripe/get-checkout-session';
|
||||||
import {
|
import {
|
||||||
getStripeCustomerByEmail,
|
getStripeCustomerByEmail,
|
||||||
@ -7,7 +8,7 @@ import {
|
|||||||
} from '@documenso/ee/server-only/stripe/get-customer';
|
} from '@documenso/ee/server-only/stripe/get-customer';
|
||||||
import { getPortalSession } from '@documenso/ee/server-only/stripe/get-portal-session';
|
import { getPortalSession } from '@documenso/ee/server-only/stripe/get-portal-session';
|
||||||
import { getRequiredServerComponentSession } from '@documenso/lib/next-auth/get-server-session';
|
import { getRequiredServerComponentSession } from '@documenso/lib/next-auth/get-server-session';
|
||||||
import { Stripe, stripe } from '@documenso/lib/server-only/stripe';
|
import { Stripe } from '@documenso/lib/server-only/stripe';
|
||||||
import { getSubscriptionByUserId } from '@documenso/lib/server-only/subscription/get-subscription-by-user-id';
|
import { getSubscriptionByUserId } from '@documenso/lib/server-only/subscription/get-subscription-by-user-id';
|
||||||
|
|
||||||
export type CreateCheckoutOptions = {
|
export type CreateCheckoutOptions = {
|
||||||
@ -42,13 +43,11 @@ export const createCheckout = async ({ priceId }: CreateCheckoutOptions) => {
|
|||||||
|
|
||||||
// Create a Stripe customer if it does not exist for the current user.
|
// Create a Stripe customer if it does not exist for the current user.
|
||||||
if (!stripeCustomer) {
|
if (!stripeCustomer) {
|
||||||
stripeCustomer = await stripe.customers.create({
|
await createCustomer({
|
||||||
name: user.name ?? undefined,
|
user,
|
||||||
email: user.email,
|
|
||||||
metadata: {
|
|
||||||
userId: user.id,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
stripeCustomer = await getStripeCustomerByEmail(user.email);
|
||||||
}
|
}
|
||||||
|
|
||||||
return getCheckoutSession({
|
return getCheckoutSession({
|
||||||
|
|||||||
Reference in New Issue
Block a user