- Notifications
You must be signed in to change notification settings - Fork0
Provides an injectable Stripe client to nestjs modules
License
sergeyleschev/nestjs-stripe
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Injectable Stripe client for your nestjs projects
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.
npm install --save nestjs-stripe
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 theapiKey
field.
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
I would greatly appreciate any contributions to make this project better. Pleasemake sure to follow the below guidelines before getting your hands dirty.
- Fork the repository
- Create your branch (
git checkout -b my-branch
) - Commit any changes to your branch
- Push your changes to your remote branch
- Open a pull request
Distributed under the MIT License. SeeLICENSE
for more information.
Copyright © 2019 Dylan Aspden
About
Provides an injectable Stripe client to nestjs modules
Resources
License
Stars
Watchers
Forks
Packages0
Languages
- TypeScript100.0%