nestjs-paystack
implements a paystackModule
, which when imported into
your nest modules project provides a Paystack client to any class that injects it.
npm install --save nestjs-paystack
The simplest way to use nestjs-paystack
is to import the forRoot
function from PaystackModule
into the module in which you want to inject the service.
import { Module } from '@nestjs-common';
import { PaystackModule } from 'nestjs-paystack';
@Module({
imports: [
PaystackModule.forRoot({
apiKey: 'sk_xxxxxxxxx',
}),
],
})
export class AppModule {}
You can then inject the Paystack client into your injectable classes by using a
custom InjectPaystack
decorator
import { Injectable } from '@nestjs/common';
import { InjectPaystack } from 'nestjs-paystack';
@Injectable()
export class AppService {
public constructor(
@InjectPaystack() private readonly paystackClient) {}
}
You can also set it up Asynchronously.
import { Module } from '@nestjs-common';
import { PaystackModule } from 'nestjs-paystack';
import { PaystackConfigService } from './PaystackConfigService';
import { PaystackConfigModule } from './PaystackConfigModule';
@Module({
imports: [
PaystackConfigModule,
PaystackModule.forRootAsync({
inject: [PaystackConfigService],
useFactory: (configService: PaystackConfigService) =>
PaystackConfigService.getPaystackConfig(),
}),
}),
],
})
export class AppModule {}
// PaystackConfigService.ts
import { Injectable } from '@nestjs/common';
import { PaystackOptions } from 'nestjs-paystack';
@Injectable()
export class ConfigService {
public getPaystackConfig(): PaystackOptions {
return {
apiKey: 'sk_xxxxxxxxxxxxxx',
};
}
}
// PaystackConfigModule.ts
import { Global, Module } from '@nestjs/common';
import { PaystackConfigService } from './PaystackConfigService';
@Global()
@Module({
exports: [PaystackConfigService],
providers: [PaystackConfigService],
})
export class PaystackConfigModule {}
This module uses paystack and all methods defined in the documentation are available to the paystackClient
.
Docs
Distributed under the MIT License. See LICENSE
for more information.
- nestjs
- paystack
- Inspired by the nest-stripe module by Dylan Aspden
Copyright © 2020 Seyi Adeleke