BitBerry Labs

> independent software studio_

Engineering High-Reliability
Developer Tools & Micro-SaaS Engines

We build resilient, developer-first infrastructure, and open-source SDKs.

Products

Featured Studio EngineActive

PayCascade

State-Driven Payment Failure Escalation & Revenue Protection Engine

A payment recovery engine available as a hosted cloud API and a self-hosted Dev Kit. Both options share the same account-state and payment-recovery capabilities.

  • ✓30-Day Progressive Escalation Matrix: Calculates account state from the time of initial payment failure: HEALTHY, SOFT_WARNING, SCOPE_RESTRICTED, HARD_LOCKED, or GRACE_PERIOD_EXPIRED.
  • ✓Instant Payment Recovery: A successful payment clears failure timestamps and returns the account to HEALTHY immediately, without waiting for a cron job or manual intervention.
  • ✓Idempotent Webhook Processing: Verifies Stripe webhook signatures and deduplicates events in a processed_events store to prevent duplicate processing.
  • ✓Strict Environment Isolation: Keeps live and test environments separate so test API keys and webhooks cannot interact with production customer data.
  • ✓Exempt Recovery Route Protection: Keeps essential routes such as /billing, /stripe/portal-session, and /logout accessible, so delinquent users can sign in and update payment details.
FastAPIPython SDKStripePostgreSQL 17RedisCelery
PayCascade Example: Gate a Feature on Subscription Status
import os
from paycascade_sdk import InMemoryStateCache, PayCascadeClient, StatePoller, enforce_cached_state

sub_id = "<your-subscription-uuid>"  # the PayCascade subscription ID mapped to the signed-in user

cache = InMemoryStateCache()
client = PayCascadeClient(
    # Hosted: "https://paycascade.bitberrylabs.com" and your key from PayCascade
    # Self-hosted: your own server, and the tenant key from your server's signup/verification flow
    base_url=os.environ["PAYCASCADE_API_URL"],
    api_key=os.environ["PAYCASCADE_API_KEY"],
)
StatePoller(client=client, cache=cache, subscription_ids=[sub_id]).start()  # keeps status fresh in the background

decision = enforce_cached_state(subscription_id=sub_id, cache=cache, path="/reports", method="POST")
if not decision.allowed:
    ...  # e.g. "Feature restricted due to failed payment."
elif decision.warning:
    ...  # e.g. Show a "Payment delayed, fix payment method to keep full access" banner

Hosted API

  • ✓Lightweight Python Client: An MIT-licensed package with no server or database dependency; httpx is required for API communication.
  • ✓Local Cache and Jittered Polling: A background StatePoller refreshes account state on a randomized schedule. Access decisions use the local in-memory cache in sub-millisecond time, without an API call in the request path.
  • ✓Client-Side Access Enforcement: enforce_cached_state restricts mutating POST and PUT operations while allowing GET and HEAD during restriction phases. Configure FAIL_OPEN or FAIL_CLOSED behavior for missing or stale cache.

Try it free for up to 25 subscriptions

pip install paycascade-sdk

Self-Hosted Dev Kit

  • ✓Full Self-Hosted Infrastructure: A self-contained Docker Compose stack with FastAPI, PostgreSQL 17, Redis, Celery, and Celery Beat, designed for unlimited tenant capacity.
  • ✓Automated Dunning Email Workflows: Scheduled workers handle tenant signup verification, capacity checks, and dunning emails at failure stages on Day 1, Day 7, Day 14, and Day 30.
  • ✓Enterprise Security and Dev Kit Fulfillment: Encrypts stored webhook secrets with Fernet keys (PAYCASCADE_FERNET_KEY), includes secret-rotation scripts, and grants paid buyers private repository access through GitHub OAuth.