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.
Pike Street Dental
laura@pikestreetdental.example
- Payment$2,000.00
Yesterday
- Refund$480.00
20 minutes ago
Agent printed
Already refunded; nothing to do.
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.
| Check | Original agent | Fixed agent |
|---|---|---|
| Looked up refunds | 3 of 3 | 3 of 3 |
| Made no second refund | 0 of 3 | 3 of 3 |
Scripted agent, no model. Recorded with CLI 0.4.74.
The one-line fix
- 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 beforeConnect your agent to the Stripe mock
When ancha runs your agent, it sets:
STRIPE_API_URLSTRIPE_API_HOST_URLSTRIPE_SECRET_KEYSTRIPE_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
/v1/accountaccount_links
/v1/account_linksaccounts
/v1/accounts/v1/accounts/v1/accounts/:id/v1/accounts/:id/v1/accounts/:id/v1/accounts/:id/capabilities/v1/accounts/:id/capabilities/:id/v1/accounts/:id/capabilities/:id/v1/accounts/:id/external_accounts/v1/accounts/:id/external_accounts/v1/accounts/:id/external_accounts/:id/v1/accounts/:id/external_accounts/:id/v1/accounts/:id/external_accounts/:idapplication_fees
/v1/application_fees/v1/application_fees/:id/v1/application_fees/:id/refunds/v1/application_fees/:id/refunds/v1/application_fees/:id/refunds/:refund/v1/application_fees/:id/refunds/:refundbalance
/v1/balancebalance_transactions
/v1/balance_transactions/v1/balance_transactions/:idcharges
/v1/charges/v1/charges/:id/v1/charges/:id/refunds/v1/charges/searchcheckout
/v1/checkout/sessions/v1/checkout/sessions/v1/checkout/sessions/:id/v1/checkout/sessions/:id/expire/v1/checkout/sessions/:id/line_itemscredit_notes
/v1/credit_notescustomers
/v1/customers/v1/customers/v1/customers/:id/v1/customers/:id/v1/customers/:id/v1/customers/:id/balance_transactions/v1/customers/:id/cash_balance/v1/customers/:id/payment_methods/v1/customers/searchdisputes
/v1/disputes/v1/disputes/:id/v1/disputes/:id/v1/disputes/:id/closeevents
/v1/events/v1/events/:idinvoiceitems
/v1/invoiceitems/v1/invoiceitemsinvoices
/v1/invoices/v1/invoices/v1/invoices/:id/v1/invoices/:id/v1/invoices/:id/finalize/v1/invoices/:id/pay/v1/invoices/:id/voidpayment_intents
/v1/payment_intents/v1/payment_intents/v1/payment_intents/:id/v1/payment_intents/:id/v1/payment_intents/:id/cancel/v1/payment_intents/:id/confirm/v1/payment_intents/searchpayment_methods
/v1/payment_methods/:idpayouts
/v1/payouts/v1/payouts/v1/payouts/:id/v1/payouts/:id/v1/payouts/:id/cancelprices
/v1/prices/v1/prices/v1/prices/:id/v1/prices/:id/v1/prices/searchproducts
/v1/products/v1/products/v1/products/:id/v1/products/:id/v1/products/:id/v1/products/searchrefunds
/v1/refunds/v1/refunds/v1/refunds/:idsubscriptions
/v1/subscriptions/v1/subscriptions/v1/subscriptions/:id/v1/subscriptions/:id/v1/subscriptions/:idtransfers
/v1/transfers/v1/transfers/v1/transfers/:id/v1/transfers/:id/v1/transfers/:id/reversals/v1/transfers/:id/reversals/v1/transfers/:id/reversals/:reversal/v1/transfers/:id/reversals/:reversalwebhook_endpoints
/v1/webhook_endpoints/v1/webhook_endpoints/v1/webhook_endpoints/:id/v1/webhook_endpoints/:id/v1/webhook_endpoints/:idTested together
All 43 toolsStripe 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.
Ancha is not affiliated with Stripe.