Skip to main content

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

# For development (editable install)
pip install -e packages/fluxos-stripe

# Or add to requirements.txt
-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


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.1.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fluxos_stripe-1.0.1-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file fluxos_stripe-1.0.1.tar.gz.

File metadata

  • Download URL: fluxos_stripe-1.0.1.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

Hashes for fluxos_stripe-1.0.1.tar.gz
Algorithm Hash digest
SHA256 39af835ed0edd50cbefd5dc3cfb3d05750f8bf55a6c5d6db5581099b3fe6ef77
MD5 4b4f340eb90d4c40359b555d3ba23b38
BLAKE2b-256 4fbbbedab36825f033851af618949cc0149d9b5b842a8f602ad4d7f26c26730a

See more details on using hashes here.

File details

Details for the file fluxos_stripe-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: fluxos_stripe-1.0.1-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

Hashes for fluxos_stripe-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 437cd95f521a7fbcd0322560ab32f819a5f5b72cdd0b7cec18277e8d02bf03bd
MD5 6858f5dfa320770b9ecf5b2a1e5ef5c6
BLAKE2b-256 2810314b2d04b3fe4ced8d65bfff63bcbc9a22b06b3d6b52352a9f1a033ef3d5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page