pnpm add stripe
pnpm add https://github.com/alexrequelme/nestjs-stripe.git
Once the installation process is complete, we can import the StripeModule
into the root AppModule
.
import { Module } from '@nestjs-common';
import { StripeModule } from 'nestjs-stripe';
@Module({
imports: [
StripeModule.forRootAsync({
imports: [ConfigModule],
inject: [stripeConfig.KEY],
useFactory: (config: ConfigType<typeof stripeConfig>) => ({
apiKey: config.secretKey,
options: { apiVersion: '2023-08-16' },
}),
})
],
providers: [...],
})
export class AppModule {}
Once this is done, the StripeService
will be available to inject across the entire project (without needing to import any modules), for example:
import { Injectable } from '@nestjs/common';
import { StripeService } from 'nestjs-stripe';
@Injectable()
export class PaymentService {
constructor(private stripe: StripeService) {}
}
Alexander Requelme
Licensed under the MIT License - see the LICENSE file for details.