SDKs overview
PayPal provides a suite of Software Development Kits (SDKs) to facilitate integration with its various payment and financial services APIs. These SDKs are designed to abstract the underlying REST API calls, handle authentication, and simplify common workflows such as creating payments, managing subscriptions, and processing payouts. The availability of SDKs across multiple programming languages aims to reduce development time and potential errors for developers integrating PayPal functionalities into their applications. PayPal's official SDKs are regularly updated to reflect changes and new features within the PayPal API ecosystem.
While official SDKs cover the most common use cases and are maintained directly by PayPal, the developer community also contributes libraries that extend functionality or provide alternative implementations for specific frameworks or niche requirements. These community-driven projects can offer flexibility and tailored solutions, though their maintenance and support may vary compared to official offerings.
Official SDKs by language
PayPal maintains official SDKs for several popular programming languages, ensuring direct support and compatibility with the latest API versions. These SDKs are typically hosted on respective package managers for easy installation and dependency management. Each SDK provides language-specific interfaces for interacting with PayPal's REST APIs, covering operations from transaction processing to webhook management. For a comprehensive overview of all API endpoints and their capabilities, consult the PayPal REST API reference.
The following table outlines the key official SDKs available, their typical package names, installation commands, and their general maturity status:
| Language | Package Name | Install Command | Maturity |
|---|---|---|---|
| Node.js | @paypal/paypal-rest-sdk |
npm install paypal-rest-sdk |
Stable, actively maintained |
| Python | paypalrestsdk |
pip install paypalrestsdk |
Stable, actively maintained |
| Java | paypal-rest-sdk |
Add as Maven/Gradle dependency | Stable, actively maintained |
| Ruby | paypal-sdk-rest |
gem install paypal-sdk-rest |
Stable, actively maintained |
| .NET | PayPalCoreSDK, PayPalMerchantSDK |
Install-Package PayPal (via NuGet) |
Stable, actively maintained |
| PHP | paypal/rest-api-sdk-php |
composer require paypal/rest-api-sdk-php |
Stable, actively maintained |
Installation
Installing PayPal's official SDKs generally follows the standard practices for each programming language's package manager. Below are detailed instructions for the most commonly used SDKs:
Node.js
The Node.js SDK for PayPal REST API can be installed using npm, the Node.js package manager. This package allows server-side Node.js applications to interact with PayPal's payment processing services.
npm install paypal-rest-sdk
Python
For Python projects, the paypalrestsdk package is available via pip, Python's package installer. This enables Python applications to manage PayPal transactions, payouts, and other API interactions.
pip install paypalrestsdk
Java
Java developers typically integrate the PayPal SDK using Maven or Gradle. The SDK is available on central repositories. Below is an example of a Maven dependency:
<dependency>
<groupId>com.paypal.sdk</groupId>
<artifactId>rest-api-sdk</artifactId&n>
<version>1.14.0</version>
</dependency>
For Gradle, you would add a similar entry to your build.gradle file:
implementation 'com.paypal.sdk:rest-api-sdk:1.14.0'
PHP
The PHP SDK for PayPal's REST API is installed using Composer, the dependency manager for PHP. This allows PHP applications, including those built with frameworks like Laravel or Symfony, to integrate PayPal functionality.
composer require paypal/rest-api-sdk-php
Quickstart example
This quickstart example demonstrates how to set up the PayPal Node.js SDK and create a basic payment. This example assumes you have a PayPal developer account and have obtained your client ID and secret for a REST API app from the PayPal Developer Dashboard. The full API reference for creating payments is available in the PayPal Payments API documentation.
const paypal = require('paypal-rest-sdk');
paypal.configure({
'mode': 'sandbox', // 'sandbox' or 'live'
'client_id': 'YOUR_CLIENT_ID',
'client_secret': 'YOUR_CLIENT_SECRET'
});
const create_payment_json = {
"intent": "sale",
"payer": {
"payment_method": "paypal"
},
"redirect_urls": {
"return_url": "http://localhost:3000/success",
"cancel_url": "http://localhost:3000/cancel"
},
"transactions": [{
"item_list": {
"items": [{
"name": "item",
"sku": "001",
"price": "25.00",
"currency": "USD",
"quantity": 1
}]
},
"amount": {
"currency": "USD",
"total": "25.00"
},
"description": "This is the payment description."
}]
};
paypal.payment.create(create_payment_json, function (error, payment) {
if (error) {
console.error(JSON.stringify(error));
} else {
for(let i = 0; i < payment.links.length; i++) {
if (payment.links[i].rel === 'approval_url') {
console.log('Approval URL: ' + payment.links[i].href);
// Redirect the user to this URL to approve the payment
}
}
}
});
This snippet initializes the PayPal SDK with credentials and mode (sandbox for testing, live for production). It then constructs a JSON object defining a payment intent, payer details, redirect URLs, and transaction specifics. Finally, it uses paypal.payment.create to initiate the payment process and logs the approval URL, to which the user must be redirected to authorize the payment on PayPal's site. After approval, PayPal redirects the user back to the specified return_url or cancel_url, where your application can execute the payment.
Community libraries
Beyond PayPal's officially supported SDKs, the developer community has created and maintains various libraries that can assist with PayPal integrations. These libraries often cater to specific frameworks, offer different architectural patterns, or provide specialized functionalities not directly covered by official SDKs. While community libraries can offer flexibility, developers should evaluate their active maintenance, documentation quality, and community support before incorporating them into production systems. Examples of such libraries might include:
- Framework-specific integrations: Libraries designed to integrate seamlessly with web frameworks like Django, Ruby on Rails, or ASP.NET Core, often providing helper methods or ORM integrations.
- Higher-level abstractions: Some community libraries may provide simpler, more opinionated APIs for common tasks, further abstracting the underlying PayPal REST API calls.
- Specialized payment flows: Libraries that focus on niche payment scenarios or specific PayPal products, potentially offering more tailored solutions than the general-purpose official SDKs.
For example, while PayPal offers official SDKs, a developer might find a Stripe Elements integration guide useful for comparison when evaluating different payment UI components, even if they choose PayPal for backend processing. When using community-contributed code, it's advisable to review the source code and ensure it aligns with security best practices, especially concerning sensitive payment information. Always refer to the official PayPal developer documentation for the most accurate and up-to-date information on API usage and security requirements.