/nestjs-mangopay

Injectable Mangopay client for Nestjs

Primary LanguageTypeScriptMIT LicenseMIT

npm NPM Release Publish

Nest Mangopay Module

Mangopay module for Nest framework (node.js). Using the Nodejs dependency mangopay2-nodejs-sdk.

Implementing the MangopayModule from this package you gain access to Mangopay service through dependency injection with minimal setup.

Getting Started

Prerequisites

This lib requires Node.js >=14.17.0, NestJS ^9.0.0, mangopay2-nodejs-sdk ^1.33.0.

Instalation

$ npm install --save nestjs-mangopay
$ yarn add nestjs-mangopay

To use Mangopay service we need to register module for example in app.module.ts

import { MangopayModule } from 'nestjs-mangopay';

@Module({
  imports: [
    MangopayModule.register({
      clientId: process.env.MANGOPAY_CLIENT_ID,
      clientApiKey: process.env.MANGOPAY_API_KEY,
      baseUrl: process.env.MANGOPAY_API_URL,
    }),
  ],
})
export class AppModule {}
import { MangopayModule } from 'nestjs-mangopay';

@Module({
  imports: [
    MangopayModule.registerAsync({
      userFactory: () => ({
        clientId: process.env.MANGOPAY_CLIENT_ID,
        clientApiKey: process.env.MANGOPAY_API_KEY,
        baseUrl: process.env.MANGOPAY_API_URL,
      })
    }),
  ],
})
export class AppModule {}

Example usage in service.

import { MangopayService } from 'nestjs-mangopay';

@Injectable()
export class AppService {
  public constructor(private readonly mangopayService: MangopayService) {}

  async createUser() {
    return this.mangopayService.Users.create({
      FirstName: 'Victor',
      LastName: 'Hugo',
      Address: '1 rue des Misérables, Paris',
      Birthday: 1300186358,
      Nationality: 'FR',
      CountryOfResidence: 'FR',
      Occupation: 'Writer',
      ProofOfIdentity: null,
      ProofOfAddress: null,
      PersonType: 'NATURAL',
      Email: 'victor@hugo.com',
      Tag: 'custom tag',
    });
  }
}

Services

import { MangopayService } from 'nestjs-mangopay';

@Injectable()
export class AppService {
  public constructor(private readonly mangopayService: MangopayService) {}

  async getUsers() {
    return this.mangopayService.Users.getAll();
  }
}

For full Service API see Mangopay Node SDK reference here

Testing

Example of testing can be found here.