@crowdlinker/nestjs-stripe
TypeScript icon, indicating that this package has built-in type declarations

0.2.2 • Public • Published

NestJS Stripe

Stripe module for NestJS

Nest Logo

Packages

Installation

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

Usage

Importing the Module

Synchronous

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),
  ],
})

Asynchronous

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],
    }),
  ],
})

Importing in a Class/Service

import { Stripe } from '@crowdlinker/nestjs-stripe';

class StripeService {
  constructor(private readonly stripe: Stripe) {}

  async createCustomer(email) {
    return await this.stripe.customer.create({ email });
  }
}

For Previous v0.1.0 Version

  • StripeOptions was renamed to StripeModuleOptions in v0.2.0. So, for versions lower than v0.2.0, please update your imports accordingly.

Important Points To Note

  • Code is written in Typescript (v5.1.3)

Contributors

Readme

Keywords

Package Sidebar

Install

npm i @crowdlinker/nestjs-stripe

Weekly Downloads

2

Version

0.2.2

License

MIT

Unpacked Size

135 kB

Total Files

53

Last publish

Collaborators

  • ankesh_7
  • prateekkathal_cl