streamlit-paypal


Namestreamlit-paypal JSON
Version 1.0.1 PyPI version JSON
download
home_pagehttps://github.com/TEENLU/streamlit-paypal
SummaryPayPal payment integration for Streamlit apps
upload_time2025-10-07 03:04:54
maintainerNone
docs_urlNone
authorTEENLU
requires_python>=3.9
licenseMIT
keywords streamlit paypal payment integration component
VCS
bugtrack_url
requirements streamlit requests python-dotenv
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 💳 Streamlit PayPal

[![Python](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
[![Streamlit](https://img.shields.io/badge/streamlit-1.28+-red.svg)](https://streamlit.io)
[![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)

**Secure and elegant PayPal payment integration for Streamlit apps**

Easily integrate PayPal payments into your Streamlit applications with a secure, popup-based payment flow.

> This project is forked from [streamlit-oauth](https://github.com/dnplus/streamlit-oauth), focusing on PayPal payment integration.

## 🚀 Quick Start

### Installation

```bash
pip install streamlit-paypal
```

### Basic Usage

Create a `.env` file with your PayPal credentials:

```bash
PAYPAL_CLIENT_ID=your_client_id
PAYPAL_CLIENT_SECRET=your_client_secret
```

Then use the component in your Streamlit app:

```python
import streamlit as st
from streamlit_paypal import PayPalComponent
import os

# Initialize PayPal component
paypal = PayPalComponent(
    client_id=os.getenv('PAYPAL_CLIENT_ID'),
    client_secret=os.getenv('PAYPAL_CLIENT_SECRET'),
    mode='sandbox'  # Use 'live' for production
)

# Create payment button
if 'payment' not in st.session_state:
    result = paypal.payment_button(
        name="Pay $10 USD",
        amount=10.00,
        currency='USD',
        description='Product Purchase',
        return_url='https://yourapp.streamlit.app'  # Required!
    )

    if result:
        st.session_state.payment = result
        st.rerun()
else:
    st.success(f"Payment successful! Order ID: {st.session_state.payment['order_id']}")
```

> **⚠️ Production Notice**: This component uses Streamlit session state for immediate interaction. For reliable order processing in production (handling network interruptions, browser closures, etc.), configure **PayPal Webhooks** to receive payment notifications server-side and persist order states.

## 📚 API Reference

### PayPalComponent

```python
paypal = PayPalComponent(
    client_id: str,           # PayPal Client ID
    client_secret: str,       # PayPal Client Secret
    mode: str = 'sandbox'     # 'sandbox' or 'live'
)

result = paypal.payment_button(
    name: str,                # Button text
    amount: float,            # Payment amount
    currency: str,            # Currency code (USD, EUR, TWD, etc.)
    description: str,         # Order description
    return_url: str           # Post-payment return URL (required)
)
```

### Return Value

On successful payment, returns a dictionary:

```python
{
    'order_id': 'xxx',        # PayPal Order ID
    'status': 'COMPLETED',    # Order status
    'payer_email': 'xxx',     # Payer's email
    'amount': '10.00',        # Payment amount
    'currency': 'USD'         # Currency code
}
```

## 🔒 Security Features

| Feature | Description |
|---------|-------------|
| Client Secret Protection | ✅ Secret stays server-side, zero frontend exposure |
| CSRF Protection | ✅ Order ID verification mechanism |
| Timeout Control | ✅ 5-minute auto-cancellation |
| Order Verification | ✅ Can only capture self-created orders |
| Replay Attack Protection | ✅ Order state tracking |

## 🛠️ Development

### Setup

```bash
# Clone repository
git clone https://github.com/TEENLU/streamlit-paypal.git
cd streamlit-paypal

# Install in development mode
pip install -e .

# Run example
streamlit run examples/paypal_basic.py
```

### Frontend Development

```bash
cd streamlit_paypal/frontend
npm install
npm run dev
```

### Testing

```bash
python test_paypal_component.py
```

## 📊 Architecture Design

### Why Popup Mode?

1. **Simpler URL Handling**: Returns Python dict directly, no callback URL parsing needed
2. **Better UX**: Dedicated window feels more professional, doesn't interrupt main app flow
3. **State Management**: Auto-integrates with Streamlit session state
4. **Enhanced Security**: Reduces URL parameter exposure risks

### Production Architecture

This package provides the **frontend interaction layer** for immediate payment experiences.

**Recommended production setup**:

```
Streamlit App (this package)  →  Real-time UI, payment buttons, user experience
         ↓
PayPal Orders API             →  Create orders, popup payment flow
         ↓
Your Backend + Webhooks       →  Receive PAYMENT.CAPTURE.COMPLETED
                                  Persist orders, fulfillment, authorization
```

**Why use Webhooks?**
- ✅ Reliability: Process payments even if user closes browser
- ✅ Security: Server-to-Server verification
- ✅ Completeness: Receive all payment events (success, failure, refund, etc.)

Reference: [PayPal Webhooks Documentation](https://developer.paypal.com/docs/api-basics/notifications/webhooks/)

## 🙏 Acknowledgments

This project is forked from [dnplus/streamlit-oauth](https://github.com/dnplus/streamlit-oauth). Special thanks to the original author for the excellent popup mechanism architecture.

## 📝 License

MIT License - see [LICENSE](LICENSE) file for details

---

**Version:** 1.0.0
**Status:** 🟢 Active Development

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/TEENLU/streamlit-paypal",
    "name": "streamlit-paypal",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "streamlit, paypal, payment, integration, component",
    "author": "TEENLU",
    "author_email": "TEENLU <ivanru372@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/dc/b3/c549badcaa3d4b0148f5c3531473db705a50dd3b508b326bb282007b2fb0/streamlit_paypal-1.0.1.tar.gz",
    "platform": null,
    "description": "# \ud83d\udcb3 Streamlit PayPal\n\n[![Python](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)\n[![Streamlit](https://img.shields.io/badge/streamlit-1.28+-red.svg)](https://streamlit.io)\n[![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)\n\n**Secure and elegant PayPal payment integration for Streamlit apps**\n\nEasily integrate PayPal payments into your Streamlit applications with a secure, popup-based payment flow.\n\n> This project is forked from [streamlit-oauth](https://github.com/dnplus/streamlit-oauth), focusing on PayPal payment integration.\n\n## \ud83d\ude80 Quick Start\n\n### Installation\n\n```bash\npip install streamlit-paypal\n```\n\n### Basic Usage\n\nCreate a `.env` file with your PayPal credentials:\n\n```bash\nPAYPAL_CLIENT_ID=your_client_id\nPAYPAL_CLIENT_SECRET=your_client_secret\n```\n\nThen use the component in your Streamlit app:\n\n```python\nimport streamlit as st\nfrom streamlit_paypal import PayPalComponent\nimport os\n\n# Initialize PayPal component\npaypal = PayPalComponent(\n    client_id=os.getenv('PAYPAL_CLIENT_ID'),\n    client_secret=os.getenv('PAYPAL_CLIENT_SECRET'),\n    mode='sandbox'  # Use 'live' for production\n)\n\n# Create payment button\nif 'payment' not in st.session_state:\n    result = paypal.payment_button(\n        name=\"Pay $10 USD\",\n        amount=10.00,\n        currency='USD',\n        description='Product Purchase',\n        return_url='https://yourapp.streamlit.app'  # Required!\n    )\n\n    if result:\n        st.session_state.payment = result\n        st.rerun()\nelse:\n    st.success(f\"Payment successful! Order ID: {st.session_state.payment['order_id']}\")\n```\n\n> **\u26a0\ufe0f Production Notice**: This component uses Streamlit session state for immediate interaction. For reliable order processing in production (handling network interruptions, browser closures, etc.), configure **PayPal Webhooks** to receive payment notifications server-side and persist order states.\n\n## \ud83d\udcda API Reference\n\n### PayPalComponent\n\n```python\npaypal = PayPalComponent(\n    client_id: str,           # PayPal Client ID\n    client_secret: str,       # PayPal Client Secret\n    mode: str = 'sandbox'     # 'sandbox' or 'live'\n)\n\nresult = paypal.payment_button(\n    name: str,                # Button text\n    amount: float,            # Payment amount\n    currency: str,            # Currency code (USD, EUR, TWD, etc.)\n    description: str,         # Order description\n    return_url: str           # Post-payment return URL (required)\n)\n```\n\n### Return Value\n\nOn successful payment, returns a dictionary:\n\n```python\n{\n    'order_id': 'xxx',        # PayPal Order ID\n    'status': 'COMPLETED',    # Order status\n    'payer_email': 'xxx',     # Payer's email\n    'amount': '10.00',        # Payment amount\n    'currency': 'USD'         # Currency code\n}\n```\n\n## \ud83d\udd12 Security Features\n\n| Feature | Description |\n|---------|-------------|\n| Client Secret Protection | \u2705 Secret stays server-side, zero frontend exposure |\n| CSRF Protection | \u2705 Order ID verification mechanism |\n| Timeout Control | \u2705 5-minute auto-cancellation |\n| Order Verification | \u2705 Can only capture self-created orders |\n| Replay Attack Protection | \u2705 Order state tracking |\n\n## \ud83d\udee0\ufe0f Development\n\n### Setup\n\n```bash\n# Clone repository\ngit clone https://github.com/TEENLU/streamlit-paypal.git\ncd streamlit-paypal\n\n# Install in development mode\npip install -e .\n\n# Run example\nstreamlit run examples/paypal_basic.py\n```\n\n### Frontend Development\n\n```bash\ncd streamlit_paypal/frontend\nnpm install\nnpm run dev\n```\n\n### Testing\n\n```bash\npython test_paypal_component.py\n```\n\n## \ud83d\udcca Architecture Design\n\n### Why Popup Mode?\n\n1. **Simpler URL Handling**: Returns Python dict directly, no callback URL parsing needed\n2. **Better UX**: Dedicated window feels more professional, doesn't interrupt main app flow\n3. **State Management**: Auto-integrates with Streamlit session state\n4. **Enhanced Security**: Reduces URL parameter exposure risks\n\n### Production Architecture\n\nThis package provides the **frontend interaction layer** for immediate payment experiences.\n\n**Recommended production setup**:\n\n```\nStreamlit App (this package)  \u2192  Real-time UI, payment buttons, user experience\n         \u2193\nPayPal Orders API             \u2192  Create orders, popup payment flow\n         \u2193\nYour Backend + Webhooks       \u2192  Receive PAYMENT.CAPTURE.COMPLETED\n                                  Persist orders, fulfillment, authorization\n```\n\n**Why use Webhooks?**\n- \u2705 Reliability: Process payments even if user closes browser\n- \u2705 Security: Server-to-Server verification\n- \u2705 Completeness: Receive all payment events (success, failure, refund, etc.)\n\nReference: [PayPal Webhooks Documentation](https://developer.paypal.com/docs/api-basics/notifications/webhooks/)\n\n## \ud83d\ude4f Acknowledgments\n\nThis project is forked from [dnplus/streamlit-oauth](https://github.com/dnplus/streamlit-oauth). Special thanks to the original author for the excellent popup mechanism architecture.\n\n## \ud83d\udcdd License\n\nMIT License - see [LICENSE](LICENSE) file for details\n\n---\n\n**Version:** 1.0.0\n**Status:** \ud83d\udfe2 Active Development\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "PayPal payment integration for Streamlit apps",
    "version": "1.0.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/TEENLU/streamlit-paypal/issues",
        "Homepage": "https://github.com/TEENLU/streamlit-paypal",
        "Repository": "https://github.com/TEENLU/streamlit-paypal"
    },
    "split_keywords": [
        "streamlit",
        " paypal",
        " payment",
        " integration",
        " component"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "f6d8ac0884922d872ea6b42fe8c71d9f7c0d8a85bb8c0b821a130ca723c2423c",
                "md5": "2df4b82c14da7a5aa20b1640080854c7",
                "sha256": "99e58279f8120df4c0425bc71dc1183065c841b8cca70d213eb2d3cd36bb1aa8"
            },
            "downloads": -1,
            "filename": "streamlit_paypal-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2df4b82c14da7a5aa20b1640080854c7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 66642,
            "upload_time": "2025-10-07T03:04:53",
            "upload_time_iso_8601": "2025-10-07T03:04:53.532325Z",
            "url": "https://files.pythonhosted.org/packages/f6/d8/ac0884922d872ea6b42fe8c71d9f7c0d8a85bb8c0b821a130ca723c2423c/streamlit_paypal-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "dcb3c549badcaa3d4b0148f5c3531473db705a50dd3b508b326bb282007b2fb0",
                "md5": "41e11188c6fa8070345feb402bb2a0bf",
                "sha256": "1696c82c4f3dab6e4101849c482f1dec61aa7ec0a441b0e35a25f4762cb1edc8"
            },
            "downloads": -1,
            "filename": "streamlit_paypal-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "41e11188c6fa8070345feb402bb2a0bf",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 68352,
            "upload_time": "2025-10-07T03:04:54",
            "upload_time_iso_8601": "2025-10-07T03:04:54.617371Z",
            "url": "https://files.pythonhosted.org/packages/dc/b3/c549badcaa3d4b0148f5c3531473db705a50dd3b508b326bb282007b2fb0/streamlit_paypal-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-07 03:04:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "TEENLU",
    "github_project": "streamlit-paypal",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "streamlit",
            "specs": [
                [
                    "==",
                    "1.48"
                ]
            ]
        },
        {
            "name": "requests",
            "specs": [
                [
                    ">=",
                    "2.31.0"
                ]
            ]
        },
        {
            "name": "python-dotenv",
            "specs": [
                [
                    "==",
                    "1.0.1"
                ]
            ]
        }
    ],
    "lcname": "streamlit-paypal"
}
        
Elapsed time: 1.22093s