A stateful Stripe API mock for testing agents.

A local Stripe API for your agent’s tests. Payments, refunds and Connect transfers stay on the account, so a test can check what it charged, refunded or paid to a seller.

See the example
Acme RecordsSucceeded

Pike Street Dental

laura@pikestreetdental.example

  • Payment$2,000.00

    Yesterday

  • Refund$480.00

    20 minutes ago

Agent printed

Already refunded; nothing to do.

The payment after the fixed agent runs: still one refund. Starting data and checks from scene.yaml.

An agent refunded a customer twice

Laura at Pike Street Dental asked again for her $480 credit on yesterday’s $2,000 payment. It had been refunded twenty minutes earlier. The agent looked only at the newest refund on the account, which belonged to another customer, and refunded Laura a second time.

The test checks the agent’s calls: it must look up refunds and must not create one.

Refund check3 trials / version
CheckOriginal agentFixed agent
Looked up refunds3 of 33 of 3
Made no second refund0 of 33 of 3

Scripted agent, no model. Recorded with CLI 0.4.74.

The one-line fix

agent.mjs
- const { data: refunds } = await stripe('GET', 'refunds?limit=1');+ const { data: refunds } = await stripe('GET', `refunds?payment_intent=${payment.id}`);

Run it yourself

Save agent.mjs and scene.yaml in an empty directory. You need Node.js 24.

npm install -g @ancha-labs/cli
ancha init --agent "node agent.mjs"
ancha run scene.yaml --local -n 3
ancha baseline save before
# change 'refunds?limit=1' to `refunds?payment_intent=${payment.id}` in agent.mjs
ancha run scene.yaml --local -n 3 --compare before

Connect your agent to the Stripe mock

When ancha runs your agent, it sets:

  • STRIPE_API_URL
  • STRIPE_API_HOST_URL
  • STRIPE_SECRET_KEY
  • STRIPE_WEBHOOK_SECRET

Point the client you already use at them.

import Stripe from 'stripe';

const stripe = new Stripe(process.env.STRIPE_SECRET_KEY, {
  maxNetworkRetries: 0,
  httpClient: Stripe.createFetchHttpClient((input, init) => {
    const url = new URL(String(input));
    return fetch(process.env.STRIPE_API_URL + url.pathname + url.search, init);
  }),
});

Locally, ancha runs your agent as an ordinary process, so keep real Stripe credentials out of its environment.

See all 103 endpoints

account

GET/v1/account

account_links

POST/v1/account_links

accounts

GET/v1/accounts
POST/v1/accounts
GET/v1/accounts/:id
POST/v1/accounts/:id
DELETE/v1/accounts/:id
GET/v1/accounts/:id/capabilities
GET/v1/accounts/:id/capabilities/:id
POST/v1/accounts/:id/capabilities/:id
GET/v1/accounts/:id/external_accounts
POST/v1/accounts/:id/external_accounts
GET/v1/accounts/:id/external_accounts/:id
POST/v1/accounts/:id/external_accounts/:id
DELETE/v1/accounts/:id/external_accounts/:id

application_fees

GET/v1/application_fees
GET/v1/application_fees/:id
GET/v1/application_fees/:id/refunds
POST/v1/application_fees/:id/refunds
GET/v1/application_fees/:id/refunds/:refund
POST/v1/application_fees/:id/refunds/:refund

balance

GET/v1/balance

balance_transactions

GET/v1/balance_transactions
GET/v1/balance_transactions/:id

charges

GET/v1/charges
GET/v1/charges/:id
GET/v1/charges/:id/refunds
GET/v1/charges/search

checkout

GET/v1/checkout/sessions
POST/v1/checkout/sessions
GET/v1/checkout/sessions/:id
POST/v1/checkout/sessions/:id/expire
GET/v1/checkout/sessions/:id/line_items

credit_notes

GET/v1/credit_notes

customers

GET/v1/customers
POST/v1/customers
GET/v1/customers/:id
POST/v1/customers/:id
DELETE/v1/customers/:id
GET/v1/customers/:id/balance_transactions
GET/v1/customers/:id/cash_balance
GET/v1/customers/:id/payment_methods
GET/v1/customers/search

disputes

GET/v1/disputes
GET/v1/disputes/:id
POST/v1/disputes/:id
POST/v1/disputes/:id/close

events

GET/v1/events
GET/v1/events/:id

invoiceitems

GET/v1/invoiceitems
POST/v1/invoiceitems

invoices

GET/v1/invoices
POST/v1/invoices
GET/v1/invoices/:id
POST/v1/invoices/:id
POST/v1/invoices/:id/finalize
POST/v1/invoices/:id/pay
POST/v1/invoices/:id/void

payment_intents

GET/v1/payment_intents
POST/v1/payment_intents
GET/v1/payment_intents/:id
POST/v1/payment_intents/:id
POST/v1/payment_intents/:id/cancel
POST/v1/payment_intents/:id/confirm
GET/v1/payment_intents/search

payment_methods

GET/v1/payment_methods/:id

payouts

GET/v1/payouts
POST/v1/payouts
GET/v1/payouts/:id
POST/v1/payouts/:id
POST/v1/payouts/:id/cancel

prices

GET/v1/prices
POST/v1/prices
GET/v1/prices/:id
POST/v1/prices/:id
GET/v1/prices/search

products

GET/v1/products
POST/v1/products
GET/v1/products/:id
POST/v1/products/:id
DELETE/v1/products/:id
GET/v1/products/search

refunds

GET/v1/refunds
POST/v1/refunds
GET/v1/refunds/:id

subscriptions

GET/v1/subscriptions
POST/v1/subscriptions
GET/v1/subscriptions/:id
POST/v1/subscriptions/:id
DELETE/v1/subscriptions/:id

transfers

GET/v1/transfers
POST/v1/transfers
GET/v1/transfers/:id
POST/v1/transfers/:id
GET/v1/transfers/:id/reversals
POST/v1/transfers/:id/reversals
GET/v1/transfers/:id/reversals/:reversal
POST/v1/transfers/:id/reversals/:reversal

webhook_endpoints

GET/v1/webhook_endpoints
POST/v1/webhook_endpoints
GET/v1/webhook_endpoints/:id
POST/v1/webhook_endpoints/:id
DELETE/v1/webhook_endpoints/:id

Tested together

All 43 tools

Stripe API mock FAQ

What is a stateful Stripe API mock?

It keeps data between calls. A refund your agent creates shows up when it lists refunds again, and a payment refunded earlier stays refunded. Ancha’s mock covers customers, payments, subscriptions, invoices and refunds, plus Connect accounts, onboarding, transfers, application fees and payouts.

How is this different from stripe-mock?

Stripe’s stripe-mock is stateless: it validates the data you send and then ignores it, so a refund you create is not there when you list refunds. Stripe recommends it for basic sanity checks. Ancha’s Stripe mock keeps state for the whole run, which is what a check for a second refund needs.

Is this the same as Stripe test mode?

No. Test mode is Stripe’s own sandbox in your account. Ancha is an independent simulation that starts from data you write, so every trial begins with the same customers and payments and nothing needs cleaning up.

Can I simulate a declined card?

Yes. Use test tokens such as pm_card_chargeDeclined, or give a seeded customer’s card a decline reason: generic_decline, insufficient_funds or expired_card.

Can I use the stripe Node.js library?

Yes. It is tested with stripe 23.1.0. The library takes no base path, so point its host at STRIPE_API_HOST_URL or pass a fetch client that rewrites the URL, as in the code above.

Will this create real charges?

No, as long as the agent uses the STRIPE_API_URL and STRIPE_SECRET_KEY that ancha sets: every payment and refund stays in the simulated Stripe.

Run the example on your machine.

Book a demo

Ancha is not affiliated with Stripe.