payouts

Set Up Server-Side SDK

Use the PayPal REST SDKs to get started quickly with the PayPal REST APIs and complete common actions.

The PayPal REST SDKs are available in Java, PHP, Node, Python, Ruby, and .NET.

SDK benefits

Using an SDK over a direct integration allows the SDK to handle authentication for you. The SDK obtains your OAuth 2.0 access token and automatically reflects any Payouts API updates.

Install the SDK

To begin working with the PayPal REST APIs, install the SDK in your preferred language.

//Create a Node.js project in your directory, then run the following command to install the PayPal JavaScript SDK.
npm install @paypal/payouts-sdk
//Create a PHP project in your directory, then run the following command to install the PayPal Payouts PHP SDK.
composer require paypal/paypal-payouts-sdk ~1.0.0
# Create a Python project in your directory, then run the following command to install the PayPal Payouts Python SDK.
pip install paypal-payouts-sdk
# Create a Ruby project in your directory, then run the following command to install the PayPal Payouts Ruby SDK.
gem install paypal-payouts-sdk
//Create a Java Maven or Gradle project in your directory, then add the following dependency to the project from Maven Central.
PAYPAL PAYOUTS JAVA SDK:
 groupId: com.paypal.sdk
 artifactId: payouts-sdk
 version: 1.0.0
//Create a DotNet project in your directory, then run the following command to install the PayPal Payouts DotNet SDK.
dotnet add package PayoutsSdk --version 1.0.0

Set up the environment

After you install the SDK, make it available to your app and configure your environment. Configuration details include either sandbox for testing or live for production, and your client ID and secret for your app.

Note: Learn how to get your REST API credentials for sandbox and live environments in the Developer Dashboard.

In the directory where you installed the SDK, create a file in your preferred language. Include this code to make the SDK available and configure your environment with your application credentials.

'use strict';

/**
 *
 * PayPal Node JS SDK dependency
 */
const payoutsNodeJssdk = require('@paypal/payouts-sdk');

/**
 *
 * Returns PayPal HTTP client instance with environment that has access
 * credentials context. Use this instance to invoke PayPal APIs, provided the
 * credentials have access.
 */
function client() {
    return new payoutsNodeJssdk.core.PayPalHttpClient(environment());
}

/**
 *
 * Set up and return PayPal JavaScript SDK environment with PayPal access credentials.
 * This sample uses SandboxEnvironment. In production, use LiveEnvironment.
 *
 */
function environment() {
    let clientId = process.env.PAYPAL_CLIENT_ID || 'PAYPAL-SANDBOX-CLIENT-ID';
    let clientSecret = process.env.PAYPAL_CLIENT_SECRET || 'PAYPAL-SANDBOX-CLIENT-SECRET';

    if (process.env.NODE_ENV === 'production') {
        return new payoutsNodeJssdk.core.LiveEnvironment('PAYPAL-CLIENT-ID', 'PAYPAL-CLIENT-SECRET');
    }
        return new payoutsNodeJssdk.core.SandboxEnvironment(`PAYPAL-SANDBOX-CLIENT-ID`, 'PAYPAL-SANDBOX-CLIENT-SECRET');

}

module.exports = { client: client};

<?php

namespace Sample;

use PaypalPayoutsSDK\Core\PayPalHttpClient;
use PaypalPayoutsSDK\Core\SandboxEnvironment;
ini_set('error_reporting', E_ALL); // or error_reporting(E_ALL);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
class PayPalClient
{
    /**
     * Returns PayPal HTTP client instance with environment that has access
     * credentials context. Use this instance to invoke PayPal APIs, provided the
     * credentials have access.
     */
    public static function client()
    {
        return new PayPalHttpClient(self::environment());
    }

    /**
     * Set up and return PayPal PHP SDK environment with PayPal access credentials.
     * This sample uses SandboxEnvironment. In production, use LiveEnvironment.
     */
    public static function environment()
    {
        $clientId = getenv("CLIENT_ID") ?: "PAYPAL-CLIENT-ID";
        $clientSecret = getenv("CLIENT_SECRET") ?: "PAYPAL-CLIENT-SECRET";
        return new SandboxEnvironment($clientId, $clientSecret);
    }
}
from paypalpayoutssdk.core import PayPalHttpClient, SandboxEnvironment

class PayPalClient:
    def __init__(self):
        self.client_id =  os.environ["PAYPAL-CLIENT-ID"] if 'PAYPAL-CLIENT-ID' in os.environ else "PAYPAL-CLIENT-ID"
        self.client_secret = os.environ["PAYPAL-CLIENT-SECRET"] if 'PAYPAL_CLIENT_SECRET' in os.environ else "PAYPAL-CLIENT-SECRET"

        """Set up and return PayPal Python SDK environment with PayPal Access credentials.
           This sample uses SandboxEnvironment. In production, use
           LiveEnvironment."""
        self.environment = SandboxEnvironment(client_id=self.client_id, client_secret=self.client_secret)

        """ Returns PayPal HTTP client instance in an environment with access credentials. Use this instance to invoke PayPal APIs, provided the
            credentials have access. """
        self.client = PayPalHttpClient(self.environment)
require 'paypal-payouts-sdk'

module PayPalClient
  class << self

    # Set up and return PayPal Ruby SDK environment with PayPal access credentials.
    # This sample uses SandboxEnvironment. In production, use LiveEnvironment.
    def environment
      client_id = ENV['PAYPAL_CLIENT_ID'] || 'PAYPAL-CLIENT-ID'
      client_secret = ENV['PAYPAL_CLIENT_SECRET'] || 'PAYPAL-CLIENT-SECRET'

      PayPal::SandboxEnvironment.new(client_id, client_secret)
    end

    # Returns PayPal HTTP client instance in an environment with access
    # credentials. Use this instance to invoke PayPal APIs, provided the
    # credentials have access.
    def client
      PayPal::PayPalHttpClient.new(self.environment)
    end
  end
end
package com.sample;

import com.paypal.core.PayPalEnvironment;
import com.paypal.core.PayPalHttpClient;

public class PayPalClient {

  /**
   * Set up PayPal SDK environment with PayPal access credentials. This sample uses SandboxEnvironment. In production, use LiveEnvironment.
   */
  private PayPalEnvironment environment = new PayPalEnvironment.Sandbox(System.getProperty("PAYPAL-CLIENT-ID") != null ? System.getProperty("PAYPAL-CLIENT-ID") : "PAYPAL-CLIENT-ID", System.getProperty("PAYPAL-CLIENT-SECRET") != null ? System.getProperty("PAYPAL_CLIENT_SECRET") : "PAYPAL-CLIENT-SECRET");
  /**
   * Returns PayPal HTTP client instance in an environment with access
   * credentials. Use this instance to invoke PayPal APIs, provided the
   * credentials have access.
   */
  PayPalHttpClient client = new PayPalHttpClient(environment);
  /**
   * Method to get client object
   *
   * @return PayPalHttpClient client
   */
  public PayPalHttpClient client() {
    return this.client;
  }
}
using System;
using PayoutsSdk.Core;
using PayPalHttp;
namespace Samples {
  public class PayPalClient {
    /**
        Set up PayPal environment with sandbox credentials.
        In production, use LiveEnvironment.
     */
    public static PayPalEnvironment environment() {
      return new SandboxEnvironment(System.Environment.GetEnvironmentVariable("PAYPAL_CLIENT_ID") != null ? System.Environment.GetEnvironmentVariable("PAYPAL_CLIENT_ID") : "PAYPAL-CLIENT-ID", System.Environment.GetEnvironmentVariable("PAYPAL_CLIENT_SECRET") != null ? System.Environment.GetEnvironmentVariable("PAYPAL_CLIENT_SECRET") : "PAYPAL-CLIENT-SECRET");
    }
    /**
        Returns PayPalHttpClient instance to invoke PayPal APIs.
     */
    public static HttpClient client() {
      return new PayPalHttpClient(environment());
    }
    public static HttpClient client(string refreshToken) {
      return new PayPalHttpClient(environment(), refreshToken);
    }
  }
}
        

Additional information