mirror of
https://github.com/documenso/documenso.git
synced 2026-07-24 08:54:20 +10:00
138d663c25
Merge origin/main into feat/external-2fa-codes. Resolve formatting conflicts caused by biome rollout; preserve both feature streams: PR's external 2FA token + signing-session 2FA proof additions plus main's RateLimit/RecipientExpired/signingReminders/date-auto-insert. In complete-document-with-token.ts, drop the duplicate early field-fetching block introduced when main moved that logic later with date auto-insert support; keep the EXTERNAL_TWO_FACTOR_AUTH check using derivedRecipientActionAuth.
57 lines
1.4 KiB
TypeScript
57 lines
1.4 KiB
TypeScript
import { createCustomer } from '@documenso/ee/server-only/stripe/create-customer';
|
|
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
|
import { prisma } from '@documenso/prisma';
|
|
|
|
import { adminProcedure } from '../trpc';
|
|
import {
|
|
ZCreateStripeCustomerRequestSchema,
|
|
ZCreateStripeCustomerResponseSchema,
|
|
} from './create-stripe-customer.types';
|
|
|
|
export const createStripeCustomerRoute = adminProcedure
|
|
.input(ZCreateStripeCustomerRequestSchema)
|
|
.output(ZCreateStripeCustomerResponseSchema)
|
|
.mutation(async ({ input, ctx }) => {
|
|
const { organisationId } = input;
|
|
|
|
ctx.logger.info({
|
|
input: {
|
|
organisationId,
|
|
},
|
|
});
|
|
|
|
const organisation = await prisma.organisation.findUnique({
|
|
where: {
|
|
id: organisationId,
|
|
},
|
|
include: {
|
|
owner: {
|
|
select: {
|
|
email: true,
|
|
name: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
if (!organisation) {
|
|
throw new AppError(AppErrorCode.NOT_FOUND);
|
|
}
|
|
|
|
// Create Stripe customer outside a transaction to avoid holding a
|
|
// connection open during the external API call.
|
|
const stripeCustomer = await createCustomer({
|
|
name: organisation.name,
|
|
email: organisation.owner.email,
|
|
});
|
|
|
|
await prisma.organisation.update({
|
|
where: {
|
|
id: organisationId,
|
|
},
|
|
data: {
|
|
customerId: stripeCustomer.id,
|
|
},
|
|
});
|
|
});
|