Shared Stripe integration package used by services in this repo
Project description
fluxos-stripe
Shared Stripe integration package used by services in this repo.
Installation
Install from PyPI (recommended):
uv add fluxos-stripe
# or: pip install fluxos-stripe
Local editable install (repo development):
pip install -e packages/fluxos-stripe
Quick Start
from fluxos_stripe import StripeClient, StripeConfig
# Create config
config = StripeConfig(
api_key="sk_test_...",
webhook_secret="whsec_...", # Optional
)
# Create client
client = StripeClient(config)
# Create a customer
customer = await client.create_customer(
email="user@example.com",
name="John Doe",
metadata={"organization_id": "org_123"},
)
# Create checkout session
session = await client.create_checkout_session(
price_id="price_...",
customer_email="user@example.com",
success_url="https://example.com/success",
cancel_url="https://example.com/cancel",
)
print(f"Checkout URL: {session.url}")
# Verify webhook
event = client.verify_webhook_signature(payload, signature)
print(f"Event type: {event.type}")
Testing
Unit Tests (no Stripe API key needed)
cd packages/fluxos-stripe
pip install -e ".[dev]"
pytest tests/unit -v
E2E Tests (requires Stripe test mode API key)
export STRIPE_TEST_API_KEY=sk_test_...
export STRIPE_TEST_WEBHOOK_SECRET=whsec_... # From stripe-cli
export STRIPE_TEST_PRICE_ID=price_... # A test price ID
pytest tests/e2e -v -m e2e
Using Mock Client for Tests
from fluxos_stripe.mock import MockStripeClient, customer_factory
# Create mock client
mock_client = MockStripeClient()
# Pre-populate with test data
mock_client.add_customer(customer_factory(email="existing@test.com"))
# Use in tests
customer = await mock_client.create_customer(email="new@test.com")
assert customer.id.startswith("cus_")
# Simulate failures
mock_client.set_should_fail(True, "Simulated network error")
API Reference
StripeConfig
StripeConfig(
api_key: str, # Required - Stripe secret key
webhook_secret: str | None, # Optional - for webhook verification
timeout: float = 30.0, # API request timeout
max_retries: int = 3, # Max retry attempts
)
StripeClient Methods
| Method | Description |
|---|---|
create_customer(email, name?, metadata?) |
Create a Stripe customer |
get_customer(customer_id) |
Get customer by ID |
get_customer_by_email(email) |
Search customer by email |
create_checkout_session(...) |
Create checkout session |
get_checkout_session(session_id) |
Get checkout session |
get_subscription(subscription_id) |
Get subscription |
list_customer_subscriptions(customer_id) |
List customer subscriptions |
cancel_subscription(subscription_id, at_period_end?) |
Cancel subscription |
verify_webhook_signature(payload, signature) |
Verify webhook |
get_price(price_id) |
Get price by ID |
list_prices(product_id?) |
List active prices |
create_billing_portal_session(customer_id, return_url) |
Create billing portal |
health_check() |
Check Stripe API connectivity |
Exceptions
from fluxos_stripe import (
StripeError, # Base exception
StripeConfigError, # Invalid configuration
StripeCustomerError, # Customer operations
StripePaymentError, # Payment/checkout operations
StripeSubscriptionError, # Subscription operations
StripeWebhookError, # Webhook verification
StripeConnectionError, # API connectivity
)
License
MIT. See the repository root LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fluxos_stripe-1.0.2.tar.gz
(11.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fluxos_stripe-1.0.2.tar.gz.
File metadata
- Download URL: fluxos_stripe-1.0.2.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb15ac3c16f2a3250a5a8f559ceb1594171d0cbb1940de1dc277666c8ffad1e0
|
|
| MD5 |
7329ad2115a8e5af93aa56efc3655f1f
|
|
| BLAKE2b-256 |
9aa73d18c8d08476690400c7bc89658122bdccb8bd6986bd903e2ca9b4600e93
|
File details
Details for the file fluxos_stripe-1.0.2-py3-none-any.whl.
File metadata
- Download URL: fluxos_stripe-1.0.2-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
faa131573b315e71bc09412ff0e71e42e285e819ef91a5d7a75ed81e90dbdc30
|
|
| MD5 |
99451bebbffba0cdd96619dc1b352c37
|
|
| BLAKE2b-256 |
c5b2955e957bbd3c8ea30aead6da120e80f7812e61c243caefe447cf43369866
|