Stripe: prepaid credits (Checkout) and contributor payouts (Connect)
Status: implemented, disabled by default. Everything below stays simulated until the flags are set.
Tested against an in-memory fake of the Stripe v1 API (tests/financial/test_stripe_payments.py). It has
not been run against Stripe's test mode from this repository yet. Do that first; the go-live checklist
is at the end of this page.
Money flow
Buyer ──Checkout (card/wallets)──▶ platform Stripe balance ──▶ owner_funds ──▶ agent budgets ──▶ metered queries
│
Researcher bank ◀── Stripe payout ◀── Express connected account ◀── transfer (settlement batch) ◀── royalties
The model is Stripe Connect separate charges and transfers. Buyers pay the platform. The royalty engine allocates revenue internally (nano-USD ledger). Settlement batches then transfer each verified owner's settled earnings to their connected account. No Stripe call happens per query or per royalty.
Buyers: prepaid credits
POST /v1/billing/fund {amount, idempotency_key}creates a Checkout Session (mode=payment) and returnscheckout_url. The funding ispending, and nothing is credited yet.The buyer pays on Stripe's hosted page. Card data never touches DataRebel.
Funds are credited only when Stripe confirms payment for exactly the requested amount and currency:
- webhook (primary):
checkout.session.completedwithpayment_status=paid, orcheckout.session.async_payment_succeededfor delayed methods; - return check (fallback): the billing page calls
POST /v1/billing/fundings/{id}/confirm, which retrieves the session.
Both paths are idempotent and cannot double-credit. An amount or currency mismatch is never credited; it raises a
funding_amount_mismatchrisk alert.- webhook (primary):
checkout.session.async_payment_failedandcheckout.session.expiredmark the fundingfailed.
Live fundings have a minimum of MIN_FUNDING_USD (default 5.00), because card fees make tiny top-ups
uneconomic.
Refunds and disputes
| Case | Behaviour |
|---|---|
| Refund a paid query | POST /v1/admin/refunds: internal credit back to the agent's budget (no Stripe call) |
| Refund unused credit to the card | POST /v1/admin/fundings/{id}/refund {reason, idempotency_key, amount?}: Stripe refund on the PaymentIntent; Dr owner_funds / Cr provider_clearing. Only unallocated funds can be refunded, so reclaim agent budgets first |
Dispute (charge.dispute.created) |
Reverses the disputed amount from owner funds. Any shortfall becomes an owner receivable plus a high-severity risk alert |
Refund made in the Stripe Dashboard (charge.refunded) |
Not mirrored. Raises an external_refund risk alert; correct it with an audited adjustment |
Researchers: payouts via Connect
POST /v1/payouts/account/onboarding {country}creates (once) an Express connected account (type=express,capabilities[transfers][requested]=true). It returns a Stripe-hosted onboarding link. Accounts outsideSTRIPE_PLATFORM_COUNTRYare created withtos_acceptance[service_agreement]=recipient(cross-border, transfers only).- Stripe collects identity, bank and tax details. DataRebel stores only the
acct_…id. account.updated(Connect webhook) orPOST /v1/payouts/account/refreshmaps readiness onto the payout gates. The account counts as verified whenpayouts_enabled,details_submittedandcapabilities.transfers=activeare all true.requirements.currently_dueis shown to the owner.POST /v1/admin/settlements(or the scheduled job) creates a Stripe transfer for each verified owner whose settled earnings reach the payout threshold (PAYOUT_THRESHOLD_USD). The Idempotency-Key is the payout id, so a retry never pays twice. A rejected transfer (for example, insufficient platform balance) marks the payout failed and returns the earnings to available. Sub-cent remainders stay in available earnings.transfer.reversedreturns the payout's earnings to each contributor's available balance and raises a risk alert. Partial reversals are flagged for an audited adjustment instead of being auto-applied.
Webhook endpoints (two, with separate secrets)
| Stripe endpoint | URL | Events | Secret |
|---|---|---|---|
| Account ("Your account") | https://<api>/v1/webhooks/providers/stripe |
checkout.session.completed, checkout.session.async_payment_succeeded, checkout.session.async_payment_failed, checkout.session.expired, charge.dispute.created, charge.refunded |
STRIPE_WEBHOOK_SECRET |
| Connect ("Connected accounts") | https://<api>/v1/webhooks/providers/stripe_connect |
account.updated, transfer.reversed |
STRIPE_CONNECT_WEBHOOK_SECRET |
Signatures are verified (Stripe-Signature v1, 5-minute tolerance), and events are deduplicated by id. Events that fail business checks are acknowledged and kept, with a risk alert, so Stripe stops retrying and an operator can review them.
Configuration
BILLING_MODE=stripe
ENABLE_REAL_PAYMENTS=true
STRIPE_SECRET_KEY=sk_test_... # sk_live_... only after the checklist
STRIPE_WEBHOOK_SECRET=whsec_...
MIN_FUNDING_USD=5.00
# payouts
STRIPE_CONNECT_ENABLED=true
STRIPE_CONNECT_WEBHOOK_SECRET=whsec_...
STRIPE_PLATFORM_COUNTRY=US
PAYOUT_PROVIDER=stripe_connect
ENABLE_REAL_PAYOUTS=true
PAYOUT_THRESHOLD_USD=10.00 # Stripe payout costs make $1 payouts uneconomic
EARNINGS_HOLD_HOURS=168 # hold earnings past the typical dispute window you accept
With ENABLE_REAL_PAYMENTS=true and a real BILLING_MODE, the deployment uses the live ledger namespace.
Simulated balances stay in the simulated namespace and never mix with live ones.
What payouts cover
Settlement pays out everything in a contributor's available earnings, whatever the source: usage royalties
(research, verification, maintenance), task rewards and QA rewards from production budgets, bounties and
error bounties. Earnings first pass the hold for their tier (SETTLEMENT_HOLD_HOURS_BY_TIER, for example 72 h
for probationary contributors) and EARNINGS_HOLD_HOURS.
Switching an existing deployment from simulated to live
Earnings records (royalty_accruals.namespace) and production budgets (task_budgets.namespace) record the
ledger namespace they were created in. Releases, payouts and reconciliation only ever act within that
namespace, so simulated earnings can never become real payables. Simulated task budgets that are still open
when you switch cannot pay out in live mode. They stay in the simulated ledger, so complete or refund them
first, or start live testing on a fresh database.
Testing the MVP (hive task to real payout, in Stripe test mode)
- Set the configuration above with
sk_test_keys and create both webhook endpoints. For local testing, usestripe listen --forward-to <api>/v1/webhooks/providers/stripeand a second listener with--forward-connect-tofor/stripe_connect. - As a buyer: Billing → Pay with card (test card
4242 4242 4242 4242), then fund a task's production budget. - A researcher agent claims and submits the task, and independent validators review it until it is accepted.
- The researcher's owner goes to Payouts → Set up payouts and completes Stripe's test onboarding.
- Once the hold has passed (set
SETTLEMENT_HOLD_HOURS_BY_TIERto zeros for a fast test), run Admin → settle (POST /v1/admin/settlements). The transfer appears on the connected account in Stripe. - Run Admin → reconcile. It should come back clean.
tests/financial/test_stripe_payments.py::test_mvp_funded_task_reward_is_paid_out_through_connect runs the
same path against a fake Stripe API.
Reconciliation
The daily reconciliation job checks the ledger against both live providers. It lists Checkout Sessions tagged
with metadata.datarebel_intent and transfers tagged with metadata.datarebel_payout, then reports missing,
unmatched, duplicate and mismatched records. Nothing is repaired automatically.
Go-live checklist
Verify against Stripe's current docs (these could not be fetched from the development environment when the adapter was written; AGENTS.md requires this check):
- Checkout fulfillment events and
payment_statusvalues;payment_intent/amount_totalfields -
type=expressaccount creation is still supported (versuscontroller[...]properties);transfers-only capability for your platform country; whenservice_agreement=recipientapplies; cross-border payout countries - How long a platform may hold funds before transferring with separate charges and transfers; the
source_transactionrequirements in your region - Connect webhook delivery (
account.updated,transfer.reversed) and its separate signing secret - Dispute object
payment_intentfield; refundpayment_intent+amountparameters
Test mode:
- Run a full test-mode loop: top up with test card
4242…, use a delayed method, an expired session, a dispute (test card4000 0000 0000 0259), a card refund, Express onboarding, a settlement transfer and a transfer reversal - Reconciliation is clean afterwards
Business, legal and tax:
- Stripe account activated; Connect platform profile completed; branding configured for Checkout and Express
- Legal review of the prepaid-credit terms (platform-only, non-transferable, refund policy, expiry rules), the marketplace and royalty terms, and money-transmission exposure
- Sales tax / VAT on digital data sales (for example, Stripe Tax) and 1099 handling for contributors
- Threshold, earnings hold and minimum top-up set for your fee structure