Adds Stripe SDK, config, webhook endpoints, and optional connected accounts to the NestJS project. Interactively asks whether to support connected accounts, account webhooks, connected account webhooks, and payment method (checkout / payment intent / both). Use when the user asks to add Stripe, payments, or billing to the project.
Interactive setup for Stripe payments. Ask the user the following questions before generating any code, then follow the conditional steps based on answers.
Use AskQuestion (or ask conversationally) for each:
npm install stripe
src/config/stripe.config.tsimport { registerAs } from '@nestjs/config';
export interface StripeConfig {
secretKey: string;
webhookSecret: string;
connectedWebhookSecret?: string;
}
export default registerAs(
'stripe',
(): StripeConfig => ({
secretKey: process.env.STRIPE_SECRET_KEY || '',
webhookSecret: process.env.STRIPE_WEBHOOK_SECRET || '',
connectedWebhookSecret:
process.env.STRIPE_CONNECTED_WEBHOOK_SECRET || undefined,
}),
);
src/config/env.validation.tsAdd before the closing });:
/* Stripe configuration */
STRIPE_SECRET_KEY: Joi.string().required(),
STRIPE_WEBHOOK_SECRET: Joi.string().required(),
STRIPE_CONNECTED_WEBHOOK_SECRET: Joi.string().optional(),
If connected account webhooks are not needed, omit the STRIPE_CONNECTED_WEBHOOK_SECRET line.
#Stripe Credentials
STRIPE_SECRET_KEY=
STRIPE_WEBHOOK_SECRET=
If connected account webhooks are needed, also add:
STRIPE_CONNECTED_WEBHOOK_SECRET=
src/main.tsChange the NestFactory.create call to:
const app = await NestFactory.create(AppModule, { rawBody: true });
This makes req.rawBody available in webhook controllers for signature verification.
src/stripe/stripe.module.tsStart with the base module. You will add controllers and providers to it as you go through the conditional steps.
import { Module } from '@nestjs/common';
import { StripeService } from './providers/stripe.service';
@Module({
providers: [StripeService],
exports: [StripeService],
})
export class StripeModule {}
src/stripe/providers/stripe.service.tsimport { StripeConfig } from '@/config/stripe.config';
import { Injectable, OnModuleInit } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import Stripe from 'stripe';
@Injectable()
export class StripeService implements OnModuleInit {
public stripe: Stripe;
constructor(private readonly configService: ConfigService) {}
onModuleInit() {
const config = this.configService.get<StripeConfig>('stripe');
this.stripe = new Stripe(config.secretKey, {
apiVersion: '2026-03-25.dahlia',
});
}
}
src/app.module.tsimport stripeConfig from './config/stripe.config';
import { StripeModule } from './stripe/stripe.module';
stripeConfig to the load array: