PayPal REST SDK for Python

1.13.3 · deprecated · verified Sun Apr 12

The `paypalrestsdk` library provides Python APIs to integrate with PayPal's REST APIs for creating, processing, and managing payments. This library is officially deprecated and is no longer actively maintained. The last public version is 1.13.3, released in November 2023, and no new features or support are provided.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to configure the `paypalrestsdk` and create a basic PayPal payment. It assumes `PAYPAL_MODE`, `PAYPAL_CLIENT_ID`, and `PAYPAL_CLIENT_SECRET` are set as environment variables. Note that this SDK is deprecated.

import os
import paypalrestsdk

paypalrestsdk.configure({
    "mode": os.environ.get("PAYPAL_MODE", "sandbox"), # "sandbox" or "live"
    "client_id": os.environ.get("PAYPAL_CLIENT_ID", ""),
    "client_secret": os.environ.get("PAYPAL_CLIENT_SECRET", "")
})

# Example: Create a simple payment (requires valid client_id and client_secret in sandbox/live)
payment = paypalrestsdk.Payment({
    "intent": "sale",
    "payer": {
        "payment_method": "paypal"
    },
    "redirect_urls": {
        "return_url": "http://localhost:8000/payment/execute",
        "cancel_url": "http://localhost:8000/payment/cancel"
    },
    "transactions": [{
        "item_list": {
            "items": [{
                "name": "item",
                "sku": "item",
                "price": "1.00",
                "currency": "USD",
                "quantity": 1
            }]
        },
        "amount": {
            "total": "1.00",
            "currency": "USD"
        },
        "description": "This is the payment transaction description."
    }]
})

if payment.create():
    print(f"Payment created successfully: {payment.id}")
    for link in payment.links:
        if link.rel == "approval_url":
            print(f"Approval URL: {link.href}")
else:
    print(f"Error creating payment: {payment.error}")

view raw JSON →