0.0.2 • Published 8 months ago

monopay-nest v0.0.2

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

NestJS Monopay wrapper

A monopay wrapper for NestJS.

Installation

npm install monopay-nest monopay
yarn add monopay-nest monopay

Usage

Register the module:

import { Zarinpal } from 'monopay';
import { MonopayModule } from 'monopay-nest';

@Module({
  imports: [
    MonopayModule.forRoot<Zarinpal>({
      isGlobal: true,
      config: { merchantId: 'zarinpal-merchant' },
      driver: 'zarinpal',
    }),
    // ...
  ],
})
export class AppModule {}

If you're using Javascript, omit the typing after forRoot

Now inject the service:

import { Zarinpal } from 'monopay';
import { MonopayService } from 'monopay-nest';

@Controller()
export class SomeController {
  constructor(private readonly monopayService: MonopayService<Zarinpal>) {}

  @Get('/')
  someEndpoint() {
    this.monopayService.requestPayment({
      amount: 50000,
      callbackUrl: 'https://my-site.com/callback',
      description: 'Description about the transaction',
    });
  }
}