npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@parkerproject/paypal-payouts-sdk

v1.0.3

Published

NodeJS SDK for PayPal Payouts APIs that accepts accessToken

Downloads

15

Readme

Unofficial PayPal Payouts API SDK for NodeJS

Forked from the official SDK.

Please refer to the PayPal Payouts Integration Guide for more information. Also refer to Setup your SDK for additional information about setting up the SDK's.

Examples

Creating a Payouts

This will create a Payout and print the batch_id for the Payout.

Code to Execute:

const paypal = require('@parkerproject/paypal-payouts-sdk');
  
// Creating an environment using client id and secret
let clientId = "<<PAYPAL-CLIENT-ID>>";
let clientSecret = "<<PAYPAL-CLIENT-SECRET>>";
let environment = new paypal.core.SandboxEnvironment(clientId, clientSecret);
let client = new paypal.core.PayPalHttpClient(environment);


// Creating an environment using access token
let accessToken = "<<PAYPAL-ACCESS-TOKEN>>"
let environment = new paypal.core.SandboxEnvironmentWithAccessToken(accessToken);
let client = new paypal.core.PayPalHttpClient(environment);

let requestBody = {
    "sender_batch_header": {
      "recipient_type": "EMAIL",
      "email_message": "SDK payouts test txn",
      "note": "Enjoy your Payout!!",
      "sender_batch_id": "Test_sdk_1",
      "email_subject": "This is a test transaction from SDK"
    },
    "items": [{
      "note": "Your 1$ Payout!",
      "amount": {
        "currency": "USD",
        "value": "1.00"
      },
      "receiver": "[email protected]",
      "sender_item_id": "Test_txn_1"
    }, {
      "note": "Your 1$ Payout!",
      "amount": {
        "currency": "USD",
        "value": "1.00"
      },
      "receiver": "[email protected]",
      "sender_item_id": "Test_txn_2"
    }, {
      "note": "Your 1$ Payout!",
      "amount": {
        "currency": "USD",
        "value": "1.00"
      },
      "receiver": "[email protected]",
      "sender_item_id": "Test_txn_3"
    }, {
      "note": "Your 1$ Payout!",
      "amount": {
        "currency": "USD",
        "value": "1.00"
      },
      "receiver": "[email protected]",
      "sender_item_id": "Test_txn_4"
    }, {
      "note": "Your 1$ Payout!",
      "amount": {
        "currency": "USD",
        "value": "1.00"
      },
      "receiver": "[email protected]",
      "sender_item_id": "Test_txn_5"
    }]
  }

// Construct a request object and set desired parameters
// Here, PayoutsPostRequest() creates a POST request to /v1/payments/payouts
let request = new paypal.payouts.PayoutsPostRequest();
request.requestBody(requestBody);

// Call API with your client and get a response for your call
let createPayouts  = async function(){
        let response = await client.execute(request);
        console.log(`Response: ${JSON.stringify(response)}`);
        // If call returns body in response, you can get the deserialized version from the result attribute of the response.
        console.log(`Payouts Create Response: ${JSON.stringify(response.result)}`);
}
createPayouts();

Handle API Failure

This will create a Payout with validation failure to showcase how to parse the failed response entity. Refer samples for more scenarios

Code to Execute:

const paypal = require('@parkerproject/paypal-payouts-sdk');
  
// Creating an environment using client id and secret
let clientId = "<<PAYPAL-CLIENT-ID>>";
let clientSecret = "<<PAYPAL-CLIENT-SECRET>>";
let environment = new paypal.core.SandboxEnvironment(clientId, clientSecret);
let client = new paypal.core.PayPalHttpClient(environment);

// Creating an environment using access token
let accessToken = "<<PAYPAL-ACCESS-TOKEN>>"
let environment = new paypal.core.SandboxEnvironmentWithAccessToken(accessToken);
let client = new paypal.core.PayPalHttpClient(environment);

let requestBody = {
    "sender_batch_header": {
      "recipient_type": "EMAIL",
      "email_message": "SDK payouts test txn",
      "note": "Enjoy your Payout!!",
      "sender_batch_id": "Test_sdk_fail",
      "email_subject": "This is a test transaction from SDK"
    },
    "items": [{
      "note": "Your 1$ Payout!",
      "amount": {
        "currency": "USD",
        "value": "1.00"
      },
      "receiver": "[email protected]",
      "sender_item_id": "Test_txn_1"
    }]
  }

// Construct a request object and set desired parameters
// Here, PayoutsPostRequest() creates a POST request to /v1/payments/payouts
let request = new paypal.payouts.PayoutsPostRequest();
request.requestBody(requestBody);

// Call API with your client and get a response for your call
let createPayouts  = async function(){
    try {
        let response = await client.execute(request);
        console.log(`Response: ${JSON.stringify(response)}`);
        // If call returns body in response, you can get the deserialized version from the result attribute of the response.
        console.log(`Payouts Create Response: ${JSON.stringify(response.result)}`);
    catch (e) {
      if (e.statusCode) {
        //Handle server side/API failure response
        console.log("Status code: ", e.statusCode);
        // Parse failure response to get the reason for failure
        const error = JSON.parse(e.message)
        console.log("Failure response: ", error)
        console.log("Headers: ", e.headers)
      } else {
        //Hanlde client side failure
        console.log(e)
      }
    }
}
createPayouts();

Retrieve a Payout Batch

Pass the batchId from the previous sample to retrieve Payouts batch details

Code to Execute:

let getPayouts =  async function(batchId) {
    request = new paypal.payouts.PayoutsGetRequest(batchId);
    request.page(1);
    request.pageSize(10);
    request.totalRequired(true);
    // Call API with your client and get a response for your call
    let response = await client.execute(request);
    console.log(`Response: ${JSON.stringify(response)}`);
    // If call returns body in response, you can get the deserialized version from the result attribute of the response.
    console.log(`Payouts Batch: ${JSON.stringify(response.result)}`);
}

getPayouts('REPLACE-WITH-BATCH-ID'); 

Running tests

To run integration tests using your client id and secret, clone this repository and run the following command:

$ npm install
$ PAYPAL_CLIENT_ID=YOUR_SANDBOX_CLIENT_ID PAYPAL_CLIENT_SECRET=YOUR_SANDBOX_CLIENT_SECRET npm test

Samples

You can start off by trying out Payouts Samples

To run samples run the following command:

$ npm install
$ PAYPAL_CLIENT_ID=YOUR_SANDBOX_CLIENT_ID PAYPAL_CLIENT_SECRET=YOUR_SANDBOX_CLIENT_SECRET npm test

To try out different samples head to this link

Note: Update the payPalClient.js with your sandbox credentials or pass your client credentials as environment variable while executing the samples.

Note

PayPalHttpClient used as part of this project returns Promises

You can read more about Promises here: https://www.promisejs.org/

License

Code released under SDK LICENSE