0.2.2 • Published 2 months ago

@crowdlinker/nestjs-stripe v0.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

NestJS Stripe

Stripe module for NestJS

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

0.2.2

2 months ago

0.2.1

2 months ago

0.2.0

2 months ago

0.1.0

3 years ago