Stripe billing integration: customers, subscriptions, checkout sessions, webhooks
Project description
ulfblk-billing
Stripe billing integration: customers, subscriptions, checkout sessions, and webhooks.
Features
- Protocol-first: BillingProvider protocol allows swapping Stripe for Paddle, LemonSqueezy, etc.
- httpx client: No Stripe SDK dependency - direct REST API calls with form-encoded bodies
- Webhook verification: HMAC-SHA256 signature validation using stdlib (no external deps)
- Tenant-aware: Optional multitenant isolation via metadata injection
- Lifecycle managed: async context manager with start/stop for httpx client
Install
uv add ulfblk-billing
Quick Start
from bloque_billing import (
BillingService, BillingSettings, CustomerCreate,
CheckoutCreate, CheckoutMode, StripeProvider,
)
settings = BillingSettings(
api_key="sk_test_...",
webhook_secret="whsec_...",
)
provider = StripeProvider(settings)
service = BillingService(provider, settings=settings)
async with service:
# Create a customer
customer = await service.create_customer(
CustomerCreate(email="user@example.com", name="Jane Doe")
)
# Create a checkout session
checkout = await service.create_checkout_session(
CheckoutCreate(
customer_id=customer.id,
price_id="price_xxx",
success_url="https://example.com/success",
cancel_url="https://example.com/cancel",
mode=CheckoutMode.SUBSCRIPTION,
)
)
print(checkout.url) # redirect user here
Webhook Processing
from bloque_billing import WebhookProcessor, WebhookEventType
processor = WebhookProcessor(webhook_secret="whsec_...")
@processor.on(WebhookEventType.SUBSCRIPTION_CREATED)
async def handle_sub(event):
print(f"New subscription: {event.data}")
# In your webhook endpoint:
event = await processor.process(payload=body, signature_header=sig)
Custom Provider
Implement the BillingProvider protocol for any payment platform:
from bloque_billing.protocol import BillingProvider
class PaddleProvider:
async def create_customer(self, data):
... # Paddle API calls
async def health_check(self) -> bool:
return True
# ... implement all protocol methods
Dependencies
Only ulfblk-core and httpx. Webhook verification uses stdlib hmac.
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
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 ulfblk_billing-0.1.0.tar.gz.
File metadata
- Download URL: ulfblk_billing-0.1.0.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","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":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f8848c4f0cc3a385c34e8233bc2901e2112dbe5ad9de74fd82e398fdb2f0238e
|
|
| MD5 |
d88276999fb6beb857d26f71d117585b
|
|
| BLAKE2b-256 |
b8d5358127791497063d180c1d015f9b9f591fec05437b892491c51f04c81c3c
|
File details
Details for the file ulfblk_billing-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ulfblk_billing-0.1.0-py3-none-any.whl
- Upload date:
- Size: 16.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","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":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
096d29e0d55da3b9bedd3a814ed65be9d351a948b8a2e41ab3821424a43492cc
|
|
| MD5 |
2d5f02fecbc6c085bb6e92b5c87786a3
|
|
| BLAKE2b-256 |
3a66fd9e1058da8cd6f6705c9a6e30110a5854b010a4d22a3113176b05ed402a
|