Metadata-Version: 2.5
Name: django-stripe-marketplace
Version: 0.1.0
Summary: Production-grade Django app for Stripe marketplace integration with multi-tenant support
Project-URL: Homepage, https://github.com/mojnomiya/django-stripe-marketplace
Project-URL: Documentation, https://django-stripe-marketplace.readthedocs.io
Project-URL: Repository, https://github.com/mojnomiya/django-stripe-marketplace
Project-URL: Issues, https://github.com/mojnomiya/django-stripe-marketplace/issues
Author-email: "Md Mojno M." <mojnomiya@gmail.com>
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: Django
Classifier: Framework :: Django :: 4.2
Classifier: Framework :: Django :: 5.0
Classifier: Framework :: Django :: 5.1
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Requires-Dist: django>=4.2
Requires-Dist: stripe>=7.0.0
Provides-Extra: all
Requires-Dist: black>=23.0.0; extra == 'all'
Requires-Dist: celery>=5.3.0; extra == 'all'
Requires-Dist: django-stubs>=4.0.0; extra == 'all'
Requires-Dist: faker>=18.0.0; extra == 'all'
Requires-Dist: flake8>=6.0.0; extra == 'all'
Requires-Dist: isort>=5.12.0; extra == 'all'
Requires-Dist: mypy>=1.0.0; extra == 'all'
Requires-Dist: pytest-cov>=4.0.0; extra == 'all'
Requires-Dist: pytest-django>=4.5.0; extra == 'all'
Requires-Dist: pytest-mock>=3.10.0; extra == 'all'
Requires-Dist: pytest>=7.0.0; extra == 'all'
Requires-Dist: redis>=5.0.0; extra == 'all'
Provides-Extra: celery
Requires-Dist: celery>=5.3.0; extra == 'celery'
Requires-Dist: redis>=5.0.0; extra == 'celery'
Provides-Extra: dev
Requires-Dist: black>=23.0.0; extra == 'dev'
Requires-Dist: django-stubs>=4.0.0; extra == 'dev'
Requires-Dist: faker>=18.0.0; extra == 'dev'
Requires-Dist: flake8>=6.0.0; extra == 'dev'
Requires-Dist: isort>=5.12.0; extra == 'dev'
Requires-Dist: mypy>=1.0.0; extra == 'dev'
Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
Requires-Dist: pytest-django>=4.5.0; extra == 'dev'
Requires-Dist: pytest-mock>=3.10.0; extra == 'dev'
Requires-Dist: pytest>=7.0.0; extra == 'dev'
Description-Content-Type: text/markdown

# django-stripe-marketplace

[![CI](https://github.com/mojnomiya/django-stripe-marketplace/actions/workflows/ci.yml/badge.svg)](https://github.com/mojnomiya/django-stripe-marketplace/actions/workflows/ci.yml)
[![PyPI version](https://badge.fury.io/py/django-stripe-marketplace.svg)](https://pypi.org/project/django-stripe-marketplace/)
[![Python Versions](https://img.shields.io/pypi/pyversions/django-stripe-marketplace.svg)](https://pypi.org/project/django-stripe-marketplace/)
[![Django Versions](https://img.shields.io/pypi/ddversions/django-stripe-marketplace.svg)](https://pypi.org/project/django-stripe-marketplace/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Production-grade Django app for Stripe marketplace integration with multi-tenant support, webhook handling, and comprehensive audit logging.

## Features

- **Multi-tenant Support**: Manage multiple Stripe accounts from a single Django application
- **Webhook Handling**: Secure webhook processing with HMAC-SHA256 signature verification
- **Subscription Management**: Full subscription lifecycle management with trial support
- **Payment Processing**: Payment intent handling with automatic retries
- **Audit Logging**: Comprehensive audit trail for all Stripe operations
- **Idempotency**: Built-in idempotency key generation for safe API calls
- **Async Processing**: Celery tasks for background synchronization
- **Bidirectional Sync**: Keep your database in sync with Stripe

## Installation

```bash
pip install django-stripe-marketplace
```

Add to your Django settings:

```python
INSTALLED_APPS = [
    # ...
    'stripe_marketplace',
]

STRIPE_MARKETPLACE = {
    'SECRET_KEY': 'sk_test_your_stripe_secret_key',
    'PUBLISHABLE_KEY': 'pk_test_your_stripe_publishable_key',
    'WEBHOOK_SECRET': 'whsec_your_webhook_secret',
    'API_VERSION': '2024-04-10',
    'CURRENCY': 'usd',
}
```

Run migrations:

```bash
python manage.py migrate stripe_marketplace
```

## Quick Start

### Setting Up Your Account

```bash
python manage.py setup_stripe --account-id acct_your_account_id --business-name "Your Business"
```

### Creating a Customer

```python
from stripe_marketplace.client import StripeClient
from stripe_marketplace.settings import settings_module

client = StripeClient(api_key=settings_module.SECRET_KEY)
customer = client.create_customer(email="customer@example.com")
```

### Syncing Data

```bash
python manage.py sync_stripe --account-id acct_your_account_id
```

### Handling Webhooks

Add to your URL configuration:

```python
from django.urls import path, include

urlpatterns = [
    path('stripe/', include('stripe_marketplace.urls')),
]
```

## Configuration

### Required Settings

| Setting | Description |
|---------|-------------|
| `SECRET_KEY` | Stripe API secret key |
| `WEBHOOK_SECRET` | Stripe webhook signing secret |

### Optional Settings

| Setting | Default | Description |
|---------|---------|-------------|
| `PUBLISHABLE_KEY` | `""` | Stripe publishable key |
| `API_VERSION` | `"2024-04-10"` | Stripe API version |
| `CURRENCY` | `"usd"` | Default currency |
| `SUBSCRIPTION_TRIAL_DAYS` | `0` | Default trial period |
| `ENABLE_WEBHOOK_LOGGING` | `True` | Enable webhook logging |
| `MAX_WEBHOOK_AGE_HOURS` | `24` | Maximum webhook age |

## Models

- `StripeAccount`: Stripe account configuration
- `StripeCustomer`: Customer linked to Django user
- `StripeProduct`: Stripe product
- `StripePlan`: Subscription plan
- `StripeSubscription`: Subscription
- `StripeInvoice`: Invoice
- `StripePaymentIntent`: Payment intent
- `WebhookEvent`: Received webhook events
- `AuditLog`: Audit trail

## Development

```bash
# Clone the repository
git clone https://github.com/mojnomiya/django-stripe-marketplace.git
cd django-stripe-marketplace

# Create virtual environment
python -m venv venv
source venv/bin/activate

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run linting
flake8 src/
black src/
isort src/
```

## License

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