NestJS module for integrating PayPal Payouts using the official PayPal Payouts Node.js SDK. This module provides an injectable client and easy configuration to make PayPal Payouts straightforward in any NestJS application.
Before installing, ensure you have Node.js and Yarn installed. This module requires a NestJS project setup.
yarn add nestjs-paypal-payouts
Configure the module in your NestJS application module (e.g., AppModule
):
import { Module } from '@nestjs/common';
import { NestjsPaypalPayoutsModule } from 'nestjs-paypal-payouts';
@Module({
imports: [
NestjsPaypalPayoutsModule.register({
environment: process.env.PAYPAL_ENVIRONMENT as 'sandbox' | 'live', // Choose 'sandbox' for testing and 'live' for production
clientId: process.env.PAYPAL_CLIENT_ID, // Your PayPal client ID
clientSecret: process.env.PAYPAL_CLIENT_SECRET, // Your PayPal client secret
}),
],
})
export class AppModule {}
For asynchronous configuration, use registerAsync
and provide a factory method:
NestjsPaypalPayoutsModule.registerAsync({
useFactory: async () => ({
environment: await getPayPalEnvironment(),
clientId: await getPayPalClientId(),
clientSecret: await getPayPalClientSecret(),
}),
})
Inject the PayPal client into your services to start making payouts:
import { Injectable } from '@nestjs/common';
import { InjectPaypalClient, InjectPaypal } from 'nestjs-paypal-payouts';
@Injectable()
export class PaymentService {
constructor(
@InjectPaypalClient() private readonly paypalClient,
@InjectPaypal() private readonly paypal,
) {}
async payout() {
const request = this.paypal.payouts.PayoutsPostRequest();
request.requestBody({
/* Payouts request body */
});
const response = await this.paypalClient.execute(request);
console.log(`Payouts Create Response: ${JSON.stringify(response.result)}`);
}
}
A detailed API reference is available to guide you through the available methods in the paypal
and paypalClient
objects, including parameters, return types, and example calls.
Contributions are welcome!
Built with NestJS and @nestjsplus/dyn-schematics. Inspired by nestjs-stripe and the work of John Biundo.