PayPal Checkout Server SDK

1.0.3 · deprecated · verified Mon Apr 13

The `paypal-checkout-serversdk` Python library is **deprecated** as of its last release (1.0.3 on October 24, 2023). PayPal has transitioned this and other older server-side SDKs to private/restricted access on GitHub, meaning they are no longer actively maintained or supported. For new integrations or migrating existing ones, PayPal recommends using the `paypal-server-sdk` Python library or integrating directly with the PayPal REST APIs.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the **recommended replacement** `paypal-server-sdk` client. It retrieves API credentials from environment variables (`PAYPAL_CLIENT_ID` and `PAYPAL_CLIENT_SECRET`) and configures a client for the PayPal Sandbox environment. This setup allows you to begin making API calls to PayPal's REST APIs, such as creating or capturing orders.

import os
import logging
from paypal_serversdk_client import PaypalServersdkClient, ClientCredentialsAuthCredentials, Environment, LoggingConfiguration

# NOTE: This quickstart is for the recommended replacement 'paypal-server-sdk',
# as 'paypal-checkout-serversdk' is deprecated and should not be used.

# Get credentials from environment variables for security
client_id = os.environ.get('PAYPAL_CLIENT_ID', 'YOUR_PAYPAL_CLIENT_ID')
client_secret = os.environ.get('PAYPAL_CLIENT_SECRET', 'YOUR_PAYPAL_CLIENT_SECRET')

if not client_id or not client_secret:
    print("WARNING: PAYPAL_CLIENT_ID and PAYPAL_CLIENT_SECRET not found in environment variables.")
    print("Please set them or replace placeholders for actual API calls.")

# Configure logging for the SDK (optional, but good practice)
logging_config = LoggingConfiguration(log_level=logging.INFO)

# Initialize the API client for the Sandbox environment
# For production, use Environment.LIVE
try:
    client = PaypalServersdkClient(
        client_credentials_auth_credentials=ClientCredentialsAuthCredentials(
            o_auth_client_id=client_id,
            o_auth_client_secret=client_secret
        ),
        environment=Environment.SANDBOX, # Or Environment.LIVE for production
        logging_configuration=logging_config
    )
    print("PayPal Server SDK client initialized successfully (Sandbox environment).")
    print("You can now use 'client' to make API calls, e.g., client.orders_controller.create_order(...)")
except Exception as e:
    print(f"Error initializing PayPal Server SDK client: {e}")

view raw JSON →