More screenshots

    Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseDotsDots+21 more

    Ledgerlock

    1

    Credits and 30-day passes on Postgres and Stripe that never double-charge, double-credit or trap a user in a renewal.

    $19

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned
    Ledgerlock

    Ledgerlock

    Example session with this skill installed

    Set up a credit system with a 30-day pass for my Supabase and Next.js app. I need it to handle Stripe webhooks without double-crediting if they retry.

    • Read your context and instructions
    • Compiled the ledgerlock

    Built credits plus a 30-day pass for your Supabase and Next.js app, with Stripe fulfilment that survives retries.

    PieceWhat it does
    credit_accountsone row per user, check (balance >= 0), locked with for update on every spend
    credit_ledgerappend-only, a unique idempotency_key on every spend, grant and refund
    passesexpires_at = greatest(now(), expires_at) + 30 days; an active pass makes covered actions cost 0
    stripe_eventsevent ids already handled, so a retried webhook is skipped
    -- inside spend_credits (security definer, search_path = '')
    select balance into bal from public.credit_accounts where user_id = p_user for update;
    if exists (select 1 from public.credit_ledger where idempotency_key = p_key) then return bal; end if;
    if bal is null or bal < p_amount then return null; end if;
    update public.credit_accounts set balance = balance - p_amount where user_id = p_user;
    insert into public.credit_ledger(user_id, delta, reason, idempotency_key) values (p_user, -p_amount, p_reason, p_key);
    
    revoke execute on function public.spend_credits from public, anon, authenticated;
    grant execute on function public.spend_credits to service_role;
    

    The webhook verifies the raw body, skips event ids it has seen, and calls the same fulfill(sessionId) as the success page with the key checkout:<session.id>, so a retry grants once. Prices are mapped to Stripe price ids on the server, never taken from the client.

    Tests (Vitest against local Supabase): 20 parallel 1-credit spends on a balance of 5 give exactly 5 successes and a balance of 0; the same key twice writes one ledger row; a replayed webhook grants once.

    Next steps

    1. Add STRIPE_WEBHOOK_SECRET and run stripe listen --forward-to localhost:3000/api/stripe/webhook.
    2. Fill the pricing table with your price ids per region.
    3. Run stripe trigger checkout.session.completed to test end to end.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    A user taps twice and pays twice. A Stripe webhook retries and the credits land twice. Two requests race and spend the same credit. Ask your agent to "add credits and a 30-day pass to the app" and Ledgerlock builds billing that counts every credit exactly once: a locked balance row, an append-only ledger, an idempotency key on every spend, grant and refund, and Stripe fulfilment that survives retries.

    Why it's different

    • Proven, not assumed: a concurrency test fires 20 parallel spends at a balance of 5 and expects exactly 5 successes, and a replayed webhook must grant once.
    • Locked down by default: money functions set search_path, lock the account row and revoke execute from client roles, so no browser can grant itself credits.
    • Honest billing: price and renewal shown before pay, reminders before any renewal, one-tap cancel, no weekly auto-charge trials.
    • Built from real projects: 9 failures that actually happened, each with its guard.

    What it does

    • Ledger schema: account row with check (balance >= 0), append-only ledger with unique idempotency keys, passes and a Stripe event table, plus a nightly balance = sum(delta) check.
    • Spend and refund flow: deduct before the work, refund on failure with a key derived from the spend, and never refund a pass user who spent nothing.
    • Stripe Checkout and webhooks: server-side price mapping, one fulfilment function for the webhook and the success page, raw-body signature check, event dedupe.
    • Regional pricing: real per-region prices with currency_options or separate price ids, not just FX conversion.
    • Refunds and disputes: claw back unspent credits, end the pass, freeze spending on a dispute.

    How it works

    1. Pricing table first: packs, passes and plans per region, with the rule that an active pass makes covered actions free.
    2. Migration: tables, locked RPCs and grants in one migration.
    3. Routes: checkout, fulfilment and webhook handlers with idempotent grants.
    4. Billing UX: price, renewal and cancel shown honestly.
    5. Prove it: Vitest against local Supabase plus stripe trigger and stripe listen end to end.

    Frameworks & tools

    Defaults to Postgres on Supabase, Stripe and Next.js route handlers, and follows your stack if it differs. Tests with Vitest, the Supabase CLI and the Stripe CLI.

    Use cases

    • AI apps that charge per action with credit packs.
    • A 30-day pass that wins over credits while it is active.
    • Fixing balances that drift or webhooks that credit twice.
    • Pricing the same product fairly in different countries.

    Known limitations

    Not for in-game currencies traded between users or marketplace payouts (Stripe Connect is a different design). Needs a Stripe account and a Postgres database you control.

    No support for user-to-user currency transfers or Stripe Connect. Requires Postgres for row-locking and Stripe for payment fulfillment.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before any payment.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Trust & safety

    Security scan

    Security scan passed 29 days ago

    Permissions

    Network Access
    Listed1 month ago
    Updated29 days ago

    What's inside

    Frequently Asked Questions

    Yes. The SQL is plain Postgres; Supabase is the default because of its RPC and role setup.

    Yes, as a variant: a plan extends access only on a paid invoice for an active subscription and ends on cancellation.

    Execute on the money functions is revoked from client roles and the user id comes from server auth, never from the request.

    Each event id is recorded and every grant has a unique key, so it is granted once.

    New in APIs & Backend