Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Provides an injectable Stripe client to nestjs modules

License

NotificationsYou must be signed in to change notification settings

sergeyleschev/nestjs-stripe

 
 

Repository files navigation

Injectable Stripe client for your nestjs projects

Table Of Contents

About

nestjs-stripe implements a module,StripeModule, which when imported intoyour nestjs project provides a Stripe client to any class that injects it. Thislets Stripe be worked into your dependency injection workflow without having todo any extra work outside of the initial setup.

Installation

npm install --save nestjs-stripe

Getting Started

The simplest way to usenestjs-stripe is to useStripeModule.forRoot

import{Module}from'@nestjs-common';import{StripeModule}from'nestjs-stripe';@Module({imports:[StripeModule.forRoot({apiKey:'my_secret_key',apiVersion:'2020-03-02',}),],})exportclassAppModule{}

You can then inject the Stripe client into any of your injectables by using acustom decorator

import{Injectable}from'@nestjs/common';import{InjectStripe}from'nestjs-stripe';importStripefrom'stripe';@Injectable()exportclassAppService{publicconstructor(@InjectStripe()privatereadonlystripeClient:Stripe){}}

Asynchronous setup is also supported

import{Module}from'@nestjs-common';import{StripeModule}from'nestjs-stripe';@Module({imports:[StripeModule.forRootAsync({inject:[ConfigService],useFactory:(configService:ConfigService)=>({apiKey:configService.get('stripe_key'),apiVersion:'2020-03-02',}),}),],})exportclassAppModule{}

Read up on thestripe-node caveatshere. Due to thewaystripe-node works you can only use the latest version of the Stripe APIthat was published at the time the module version was published. If you wish touse an older version of the Stripe API, follow the steps in the above link.Because of this, theapiVersion field is now required along with theapiKeyfield.

Example

In order to run the example run the following commands in your terminal. Theexpected output of the example is to show that the Stripe client wassuccessfully injected into theAppService.

cd exampleyarn installyarn start

Contributing

I would greatly appreciate any contributions to make this project better. Pleasemake sure to follow the below guidelines before getting your hands dirty.

  1. Fork the repository
  2. Create your branch (git checkout -b my-branch)
  3. Commit any changes to your branch
  4. Push your changes to your remote branch
  5. Open a pull request

License

Distributed under the MIT License. SeeLICENSE for more information.

Acknowledgements

Copyright © 2019 Dylan Aspden

About

Provides an injectable Stripe client to nestjs modules

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript100.0%

[8]ページ先頭

©2009-2025 Movatter.jp