Recipe · Third-party APIs

Mock a third-party API like Stripe (and replay webhooks)

Hitting the real Stripe sandbox on every reload is slow, rate-limited and hard to script around failure. Mock the slice you call, freeze the responses you need, and inject the errors you must handle — all from a stable URL.

Updated June 7, 20266 min

Why mock an API you don't own

  • Speed — no round-trip to a sandbox, no shared rate limit slowing your test suite.
  • Determinism — the same customer and charge every run, so assertions don't flake.
  • Failure on demand — exercise your retry, timeout and error paths without waiting for the real API to misbehave.

Model the resources you call

You don't reproduce all of Stripe — only the endpoints your code touches. An enum field pins the realistic set of statuses:

spec
{  "resources": [{    "name": "charges",    "count": 30,    "fields": [      { "name": "id", "type": "uuid" },      { "name": "amount", "type": "integer" },      { "name": "currency", "type": "enum", "values": ["eur", "usd"] },      { "name": "status",        "type": "enum",        "values": ["succeeded", "pending", "failed"] },      { "name": "customerId", "type": "ref", "ref": "customers.id" }    ]  }]}
  • GET/m/you/payments/charges
  • POST/m/you/payments/charges
  • GET/m/you/payments/charges/:id
  • GET/m/you/payments/customers/:id

Simulate latency and failures (Pro)

Real payment APIs are slow and occasionally fail. Add a network profile to the project: a fixed delay before every response, and a percentage of requests that return an error status you choose — per resource and method if needed.

  • A 600 ms delay on charges to test your loading states.
  • 10 % of POST /charges returning 402 to test declined-card handling.

Pin an exact response (Pro)

When a test needs one precise body — a specific event, a known id — pin a frozen response for that method and path. It overrides the generated data and returns byte-for-byte what you set.

Replay webhook payloads

Store the event payloads you care about as records in an events resource, fetch one, and POST it to your own webhook handler from a test or a script. You get a versioned library of realistic events to replay on demand.

What a mock can't do

MockSmith serves endpoints; it does not call your server. It won't push a webhook to you — but it's the perfect place to keep the payloads your test harness fires at your handler.

Frequently asked

Can I point my Stripe SDK at the mock URL?

If your client lets you override the base URL, yes — for the endpoints you've modelled. The mock speaks plain REST/JSON, not Stripe's signing or idempotency semantics, so keep it to the shapes your code reads.

Are simulated latency and errors available for free?

Network simulation and pinned responses are Pro features. Modelling resources, CRUD and pagination are available on the free plan.

Will the data change between test runs?

No — records are generated from a seed and stay stable. A scheduled reset (Pro) can restore the original set on an hourly or daily cadence.

Stop waiting on the backend.

Forge your own mock API in two minutes. Free, up to two projects, no credit card.

Forge a free mock

Read next