PayPal Agent Toolkit

repository·main·Indexed 41 days ago

https://github.com/paypal/agent-toolkit

A toolkit for agent interactions with PayPal API version 1.11.0. It enables agent frameworks including OpenAI Agent SDK, LangChain, Vercel AI SDK, CrewAI, Amazon Bedrock, and MCP to interact with PayPal APIs through function calling. The toolkit provides pre-built tools for managing invoices, payments, disputes, subscriptions, shipment tracking, catalog management, and reporting.

Tokens
20.5K
Snippets
69
Records
89
Agent score
46%

What's inside PayPal Agent Toolkit

  1. Set up the OpenAI Example environment

    main

    To run the OpenAI example, you must configure your environment with both OpenAI and PayPal credentials. You can populate these variables in your local shell environment or in a .env file at the root of the project.

    OPENAI_API_KEY=YOUR_OPENAI_API_KEY
    PAYPAL_CLIENT_ID=PayPal_Client_ID
    PAYPAL_CLIENT_SECRET=PayPal_Client_Secret
  2. Configure logging for troubleshooting

    main

    The toolkit uses Python's standard logging module. It is recommended to log to a file. To inspect detailed request payloads and headers for debugging, set the logging level to DEBUG.

    import logging
    
    # Basic configuration: logs to a file with INFO level
    logging.basicConfig(
        filename='paypal_agent_toolkit.log', 
        level=logging.INFO,
        format='%(asctime)s %(levelname)s %(name)s %(message)s'
    )
    
    # To enable debug-level logs (for seeing payloads and headers)
    # logging.getLogger().setLevel(logging.DEBUG)
  3. Install PayPal Agent Toolkit Python examples

    main

    To set up the Python example workspace, create a virtual environment, activate it, and install the necessary dependencies using pip.

    Setup Steps

    1. Create a virtual environment: python -m venv venv
    2. Activate the environment:
      • macOS/Linux: source venv/bin/activate
      • Windows: venv\Scripts\activate
    3. Install dependencies: pip install -r requirements.txt
    # Step 1: Create a virtual environment
    python -m venv venv
    
    # Step 2: Activate the virtual environment
    source venv/bin/activate  # On macOS/Linux
    # For Windows:
    # venv\Scripts\activate
    
    # Step 3: Install required dependencies
    pip install -r requirements.txt
  4. Set up the LangChain example environment

    main

    To run the LangChain example, you must configure the following environment variables in your local environment or in a .env file. You will need an OpenAI API key and your PayPal credentials (Client ID and Client Secret) to authenticate with PayPal services.

    OPENAI_API_KEY=YOUR_OPENAI_API_KEY
    PAYPAL_CLIENT_ID=PayPal_Client_ID
    PAYPAL_CLIENT_SECRET=PayPal_Client_Secret
  5. Generate a PayPal Access Token via cURL

    main

    To integrate with PayPal APIs, you need an access token. You can generate one using cURL by providing your Client ID and Client Secret.

    For Sandbox: Use https://api-m.sandbox.paypal.com/v1/oauth2/token. For Production: Use https://api-m.paypal.com/v1/oauth2/token.

    curl -v https://api-m.sandbox.paypal.com/v1/oauth2/token \
      -H "Accept: application/json" \
      -H "Accept-Language: en_US" \
      -u "CLIENT_ID:CLIENT_SECRET" \
      -d "grant_type=client_credentials"
  6. Set up the Bedrock Example environment

    main

    To run the Bedrock example, you must configure your local environment or a .env file with the following credentials for AWS and PayPal:

    • AWS_ACCESS_KEY_ID: Your AWS access key.
    • AWS_SECRET_ACCESS_KEY: Your AWS secret access key.
    • PAYPAL_CLIENT_ID: Your PayPal Client ID.
    • PAYPAL_CLIENT_SECRET: Your PayPal Client Secret.
    AWS_ACCESS_KEY_ID=AWS_ACCESS_KEY_ID
    AWS_SECRET_ACCESS_KEY=AWS_SECRET_ACCESS_KEY
    PAYPAL_CLIENT_ID=PayPal_Client_ID
    PAYPAL_CLIENT_SECRET=PayPal_Client_Secret
  7. Set up the AI SDK Example environment

    main

    To run the AI SDK example, you must configure your environment with the necessary API keys and PayPal credentials. You can either export these as local environment variables or include them in a .env file in your project root.

    OPENAI_API_KEY=YOUR_OPENAI_API_KEY
    PAYPAL_CLIENT_ID=PayPal_Client_ID
    PAYPAL_CLIENT_SECRET=PayPal_Client_Secret
  8. Configure environment variables for PayPal Agent Toolkit examples

    main

    The examples require an .env file in the example directory containing credentials for OpenAI, Amazon Bedrock, and PayPal. Replace the placeholders with your actual service credentials.

    Required keys:

    • OPENAI_API_KEY: Your OpenAI API key.
    • AWS_ACCESS_KEY_ID: Your AWS access key ID for Bedrock.
    • AWS_SECRET_ACCESS_KEY: Your AWS secret access key for Bedrock.
    • PAYPAL_CLIENT_ID: Your PayPal developer client ID.
    • PAYPAL_SECRET: Your PayPal developer secret.
    # OpenAI Configuration
    OPENAI_API_KEY=<your_openai_api_key>
    
    # Amazon Bedrock Configuration
    AWS_ACCESS_KEY_ID=AWS_ACCESS_KEY_ID
    AWS_SECRET_ACCESS_KEY=AWS_SECRET_ACCESS_KEY
    
    # PayPal Configuration
    PAYPAL_CLIENT_ID=<your_paypal_client_id>
    PAYPAL_SECRET=<your_paypal_secret>
  9. Manage Invoices

    main

    The toolkit provides a suite of functions to manage the lifecycle of PayPal invoices. You can create new invoices, retrieve existing ones, list multiple invoices, and send them to recipients. It also supports advanced features like setting up automatic reminders, generating QR codes for payments, and recording payments or refunds against specific invoices.

    Key capabilities include:

    • Creation & Retrieval: createInvoice, getInvoice, listInvoices.
    • Communication: sendInvoice, sendInvoiceReminder, setupInvoiceAutoReminder, cancelInvoiceAutoReminder.
    • Lifecycle Management: cancelSentInvoice, deleteInvoice, generateInvoiceNumber.
    • Financial Tracking: recordPaymentForInvoice, recordRefundForInvoice, createConditionalRulesForInvoice.
    • Utilities: generateInvoiceQrCode.