Credit Billing Ledger for Stripe + Store Billing

    1

    This ledger encodes the rules that keep a credit balance explainable, with the webhook handlers and the admin surface around it.

    $35

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned

    Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIDeepSeekDeepSeekMuseMuse+22 more

    Credit Billing Ledger for Stripe + Store Billing

    Example session with this skill installed

    Set up credit billing for our app: $9.99 packs of 100 credits on the web through Stripe and the same pack in the Android app through Play billing. Stripe keeps redelivering webhooks and we double-credited someone last week. Also handle refunds without going negative.

    • Read your context and instructions
    • Compiled the credit billing ledger

    Summary

    Wired one ledger behind both rails. Redelivered webhooks now credit once, refunds open a billing-review hold instead of a negative balance, and support has an admin API and a runbook.

    What was done

    • Catalog: p10 = 100 credits, 999 cents USD, store product credits_100. Amounts come from here; checkout metadata only names the product and the account.
    • node --test scripts/billing.test.mjs: 12 passed (idempotent grants, renewal keyed on subscription + billing period, ignored subscription payment intents, refund/dispute holds, won-dispute-only-clears-own-hold, sandbox ignored in production, transfer review, signature check, loopback server 200/400/401/423/403/500).
    • node scripts/server.mjs --db billing.db --stripe-secret-file ... --store-token-file ... --admin-token-file ... on 127.0.0.1:8787.

    Test-mode run against Stripe

    StepResult
    Checkout with the test cardpayment_intent.succeeded -> 100 credits, creditedNow: true
    stripe events resend of the same event200, creditedNow: false, balance still 100
    stripe refunds createcharge.refunded -> balance 100, billingReview.reason = refunded, /purchase/start -> 423
    Dispute test card, then close as lostpayment dispute_lost, hold stays
    Separate dispute closed wonthat hold clears; the other does not
    Support resolves via POST /admin/reviews/:id/resolvehold cleared with resolvedBy in the event trail

    Play rail

    Sent NON_RENEWING_PURCHASE twice with the same event id: one grant. A SANDBOX event in production: recorded as ignored_sandbox_event, zero credits.

    Handed to support

    reference/support-runbook.md with the published policy quoted; GET /admin/account/:id for every "where did my credits go" ticket.

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

    About this skill

    Selling credits looks simple until the webhooks arrive twice, a subscription's payment intent fails the one-time handler on every renewal, a refund drives a balance negative, and support "fixes" it by editing numbers. This ledger encodes the rules that keep a credit balance explainable, with the webhook handlers and the admin surface around it.

    Ledger (ledger.mjs, node:sqlite): a grant is applied once per grant id inside one transaction; the id comes from what was paid for (payment intent, subscription + billing period, store event id), never the webhook event id, so a retry with a new event id still credits once and creditedNow records which delivery granted. Usage and admin adjustments go through the same ledger with reason and actor; nothing takes a balance below zero.

    Stripe (stripe-events.mjs): one-time intents validated against the catalog's amount and currency; a subscription invoice's payment intent is ignored instead of thrown on (the bug that failed every renewal with a 500 until found); invoice eligibility by billing_reason and amount; plan matched by price id; refund, dispute created, dispute lost keep the credits and open billing review; a won dispute clears only its own hold; dependency-free signature verification with tolerance and timing-safe compare.

    Store (store-events.mjs): RevenueCat-shaped events for Play and App Store: application user id only, sandbox never credited in production, catalog credits not the client's claim, cancellation keeps access and credits, refund opens review, transfer reviews every account involved, stale events never overwrite.

    Server (server.mjs): loopback webhook routes (400 bad signature, 401 bad bearer, 500 so the provider retries), a purchase route that returns 423 under review, admin snapshot, review list, resolve and adjust; secrets from files.

    12 offline tests including a live loopback server. reference/design.md names the failure behind each rule; reference/support-runbook.md is the template for whoever answers billing mail. Node 22.5+, no packages.

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for APIs & Backend.

    One currency per catalog entry. No built-in tax or invoicing. Requires RevenueCat-shaped event payloads for store billing. Trials require manual admin adjustments.

    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 buying a skill.

    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 19 days ago

    Accounts
    Stripe account
    Software
    Node.js 22.5+Store-billing relay

    Use Stripe test mode for acceptance. The in-app rail needs a store-billing relay that posts webhooks, such as RevenueCat.

    Permissions

    Read Files
    Network Access
    Terminal / Shell
    Write Files

    Shell to run the node scripts, tests and the loopback server; read files for the secret files (webhook signing secret, store bearer token, admin token); write files for the SQLite ledger database. Network access only through the retrieveSubscription function you supply (a call to your payment provider with a restricted key); the server itself listens on 127.0.0.1. No environment variables.

    Listed19 days ago

    What's inside

    Frequently Asked Questions

    The skill uses a transaction-safe SQLite ledger that keys every credit grant to specific transaction IDs from Stripe or mobile stores, effectively ignoring duplicate webhook deliveries that often cause double-crediting in simpler systems.

    It is designed for Node.js 22.5+ environments and uses native modules like node:sqlite, making it highly compatible with most modern AI agents and backend frameworks without requiring external npm dependencies.

    When a dispute or refund is detected via webhook, the system flags the account with a "Billing Review" status (HTTP 423), allowing you to halt services immediately rather than dealing with the complexity of negative balances.

    You receive a production-ready Node.js server implementation, a pre-configured SQLite schema for the ledger, a suite of twelve automated test scenarios for billing edge cases, and a loopback API for admin overrides.

    While optimized for Stripe and RevenueCat event schemas, the logic is modular; you can manually map any mobile store webhook or custom payment provider to the ledger's internal event handlers.

    This skill focuses strictly on the credit ledger and transaction validation; it does not handle external tax calculations (like VAT/GST) or the generation of PDF invoices for customers.

    New in APIs & Backend