PayPal client for Nest framework.
$ yarn add nestjs-paypal
- clientID (string) - Paypal Client ID.
- secret (string) - Paypal Secret Key.
- live (boolean) - Paypal Environment you want to work in: false (default) -
Sandbox
, true -Live
.
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,
) {}
}
Copyright © 2023 Aleksandr Schemelev