0.0.4 • Published 11 months ago

nestjs-paypal v0.0.4

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

Description

PayPal client for Nest framework.

Installation

$ yarn add nestjs-paypal

Available options

  • clientID (string) - Paypal Client ID.
  • secret (string) - Paypal Secret Key.
  • live (boolean) - Paypal Environment you want to work in: false (default) - Sandbox, true - Live.

Usage

Sync mode. Sandbox Environment.

import { PaypalModule } from 'nestjs-paypal';
import { Module } from '@nestjs/common';

@Module({
  imports: [
    PaypalModule.forRoot({
      clientID: 'XXX-XXX',
      secret: 'XXX-XXX',
    }),
  ],
})
export class PaymentModule {}

Async mode (preferred). Live Environment.

import { PaypalModule, PaypalOptions } from 'nestjs-paypal';
import { ConfigService } from '@nestjs/config';
import { Module } from '@nestjs/common';

type PaypalConfigService = ConfigService<
  {
    paypal: PaypalOptions;
  },
  true
>;

@Module({
  imports: [
    PaypalModule.forRootAsync({
      useFactory: (configService: PaypalConfigService) => ({
        clientID: configService.get('paypal.clientID', { infer: true }),
        secret: configService.get('paypal.secret', { infer: true }),
        live: true,
      }),
      inject: [ConfigService],
    }),
  ],
})
export class PaymentModule {}

Client.

import { PayPalHttpClient } from '@paypal/checkout-server-sdk/lib/core/paypal_http_client';
import { InjectPaypal } from 'nestjs-paypal';
import { Injectable } from '@nestjs/common';

@Injectable()
export class PaypalService {
  public constructor(
    @InjectPaypal() private readonly paypalClient: PayPalHttpClient,
  ) {}
}

MIT licensed.

Copyright © 2023 Aleksandr Schemelev

0.0.4

11 months ago

0.0.3

11 months ago

0.0.2

11 months ago

0.0.1

11 months ago