Stripe module for NestJS
- Stripe - stripe (v14.21.0)
npm install --save @crowdlinker/nestjs-stripe stripe
npm install --save-dev @types/stripe
// or
// yarn add @crowdlinker/nestjs-stripe stripe
// yarn add -D @types/stripe
import { StripeModule, StripeModuleOptions } from '@crowdlinker/nestjs-stripe';
@Module({
imports: [
StripeModule.forRoot({
apiKey: 'STRIPE_API_KEY',
config: {
apiVersion: '2019-08-08',
maxNetworkRetries: 1,
httpAgent: null,
timeout: 1000,
host: 'api.example.com',
port: 123,
telemetry: true,
}
} as StripeModuleOptions),
],
})
import { StripeModule, StripeModuleOptions } from '@crowdlinker/nestjs-stripe';
@Module({
imports: [
StripeModule.forRootAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) =>
({
apiKey: configService.apiKey,
config: {
apiVersion: configService.apiVersion,
maxNetworkRetries: configService.maxNetworkRetries,
httpAgent: configService.httpAgent,
timeout: configService.timeout,
host: configService.host,
port: configService.port,
telemetry: configService.telemetry,
}
} as StripeModuleOptions),
inject: [ConfigService],
}),
],
})
import { Stripe } from '@crowdlinker/nestjs-stripe';
class StripeService {
constructor(private readonly stripe: Stripe) {}
async createCustomer(email) {
return await this.stripe.customer.create({ email });
}
}
StripeOptions
was renamed toStripeModuleOptions
inv0.2
. So, for versions lower thanv0.2
, please update your imports accordingly.
- Code is written in Typescript (v5.1.3)