A successful sandbox payment should lead to one paid order and one fulfillment job. This guide tests the boundaries between those steps: a correct card number is only the start. The downloadable project includes executable order checks and a separate durable transaction example.
Choose the Stripe fixture for the behavior
For manual entry in a Stripe sandbox, use a future expiry and a CVC of the required length. For automated API tests, Stripe recommends its documented test PaymentMethods where supported. Keep test credentials and webhook signing secrets in their matching environment; do not use live mode to test real payment details. See Stripe’s testing reference.
| Card number | Scenario | Sandbox expectation |
|---|---|---|
| 4000000000000002 | Generic | card_declined / generic_decline |
| 4000000000009995 | Funds | card_declined / insufficient_funds |
| 4000000000009987 | Lost | card_declined / lost_card |
| 4000000000009979 | Stolen | card_declined / stolen_card |
| 4000000000000069 | Expired | expired_card |
| 4000000000000127 | Cvc | incorrect_cvc |
| 4000000000000119 | Processing | processing_error |
| 4000000000006975 | Velocity | card_declined / card_velocity_exceeded |
| 4242424242424241 | Checksum | incorrect_number |
Source: Stripe testing documentation. Selected fixtures checked 2026-11-08. These local checks do not call Stripe.
The central card reference contains success cards by brand. The 3DS guide uses the same fixture data for authentication cases. These are selected scenarios, not every possible decline or account configuration. A local checksum check proves neither a Stripe response nor card ownership.
Match the PaymentIntent to your server order
This teaching model supports one test-mode PaymentIntent, an attached customer, a positive integer amount in minor units and an exact captured amount. It deliberately rejects partial captures, missing customer linkage and unexpected shapes. Load the expected values from your database, not from the browser’s request.
export function stripeOrderState(intent, order) {
// order is trusted server data. This model supports one test-mode PaymentIntent.
if (!order || typeof order.id !== 'string' || !order.id ||
typeof order.intentId !== 'string' || !order.intentId ||
typeof order.customerId !== 'string' || !order.customerId ||
!Number.isSafeInteger(order.amount) || order.amount <= 0 ||
typeof order.currency !== 'string' || !/^[a-z]{3}$/.test(order.currency) ||
order.livemode !== false) return 'review';
if (!intent || intent.object !== 'payment_intent' || intent.id !== order.intentId ||
intent.customer !== order.customerId || intent.metadata?.order_id !== order.id ||
intent.amount !== order.amount || intent.currency !== order.currency ||
intent.livemode !== false) return 'review';
if (intent.status === 'succeeded') {
return intent.amount_received === order.amount ? 'paid' : 'review';
}
const states = {requires_action: 'action-required', processing: 'pending',
requires_capture: 'authorized', requires_payment_method: 'payment-method-required',
requires_confirmation: 'confirmation-required', canceled: 'canceled'};
return Object.hasOwn(states, intent.status) ? states[intent.status] : 'review';
}| Case | Input / condition | Expected result |
|---|---|---|
| matched | Matched test order, USD 10.00 received | "paid" |
| requires-action | Authentication still needed | "action-required" |
| processing | Provider is processing | "pending" |
| manual-capture | Authorized but not captured | "authorized" |
| wrong-customer | Another customer | "review" |
| wrong-amount | USD 9.00 received for USD 10.00 order | "review" |
| live-object | Live object in a test workflow | "review" |
requires_capture maps to authorized, not paid. processing remains pending. A different customer’s payment or a USD 9.00 receipt for a USD 10.00 order goes to review. This restriction is part of the example’s contract; a real business supporting partial or incremental capture needs its own explicit rules. Consult the PaymentIntent lifecycle when implementing those rules.
Keep signature verification before interpretation
The handler receives four application dependencies: the verifier, an order lookup, the raw body and a durable recording callback. All are supplied in the downloadable tests; there are no undefined fulfillment helpers.
export async function receiveStripe(rawBody, signature, verify, loadOrder, recordPaid) {
let event;
try { event = await verify(rawBody, signature); }
catch { return {status: 400, result: 'invalid-signature'}; }
// Single-account snapshot-event example. Connect/thin events need an adapter.
if (!event || event.object !== 'event' || event.livemode !== false || event.account ||
typeof event.id !== 'string' || !event.id) return {status: 400, result: 'unsupported-event'};
if (event.type !== 'payment_intent.succeeded') return {status: 200, result: 'ignored'};
const intent = event.data?.object;
const order = await loadOrder(intent?.id);
if (stripeOrderState(intent, order) !== 'paid') return {status: 422, result: 'review'};
// recordPaid must atomically commit a unique order fulfillment job and event ID.
// Storage failures propagate so the HTTP adapter can return a retryable failure.
await recordPaid({eventId: event.id, orderId: order.id, intentId: intent.id});
return {status: 200, result: 'recorded'};
}In an HTTP integration, supply the official SDK’s stripe.webhooks.constructEvent with the original body bytes, Stripe-Signature header and the correct endpoint secret. JSON parsing or reserializing before verification changes the signed input. The adapter must catch storage failures and return a retryable error; acknowledge only after durable acceptance. Follow Stripe’s webhook instructions and signature troubleshooting.
The offline verifier in our test file uses a small private HMAC fixture format. It does not implement Stripe’s timestamped signature protocol and must not replace the SDK. Its purpose is to demonstrate that modified bytes and verification failures cannot reach order storage:
test('Tampering with signed fixture bytes cannot enqueue fulfillment', async () => {
const original = Buffer.from(JSON.stringify(event()));
const changed = Buffer.from(original.toString().replace('1000', '9000'));
const d = delivery(event(), {bytes:changed, signature:sign(original)});
assert.deepEqual(await d.run(), {status:400,result:'invalid-signature'});
assert.equal(d.writes.length, 0);
});This handler accepts single-account snapshot events. Connect account routing, thin events, refunds and disputes are outside its contract. Log a safe review reason and investigate a persistent mismatch; repeated delivery cannot repair an incorrect order mapping.
Commit the paid state and job together
A process-local set disappears on restart. Checking for an event and then inserting a job in separate transactions also leaves a race. The Python example uses SQLite uniqueness and a transaction to record the event, mark the order paid and enqueue one order job:
def record_paid(path, event_id, order_id, intent_id, fail_before_commit=False):
# Called ONLY after signature, environment, customer, amount and order checks.
# BEGIN IMMEDIATE serializes writers; uniqueness also covers distinct event IDs.
db = sqlite3.connect(path, timeout=10)
try:
db.execute('BEGIN IMMEDIATE')
order = db.execute('SELECT intent FROM orders WHERE id=?', (order_id,)).fetchone()
if order != (intent_id,):
raise ValueError('Order/intent mismatch')
seen = db.execute('SELECT order_id FROM events WHERE id=?', (event_id,)).fetchone()
if seen is not None and seen != (order_id,):
raise ValueError('Event already belongs to another order')
db.execute('INSERT OR IGNORE INTO events VALUES (?,?)', (event_id, order_id))
db.execute('UPDATE orders SET paid=1 WHERE id=?', (order_id,))
db.execute('INSERT OR IGNORE INTO jobs VALUES (?,?)', (order_id, intent_id))
if fail_before_commit:
raise RuntimeError('Simulated crash before commit')
db.commit()
except Exception:
db.rollback()
raise
finally:
db.close()The tests open separate connections, race 32 deliveries across eight workers, retry after a simulated pre-commit crash and submit two different event IDs for the same order. The expected result is one job. An event ID reused for a different order is rejected.
This is a transaction demonstration, not a production shipping worker. After commit, a worker can still crash between calling an external fulfillment service and recording completion. Use a stable order key with a downstream operation that supports idempotency, and persist retries. Database durability, worker recovery and deployment topology need separate integration tests.
Run and adapt the project
Extract the complete offline guide project . Use Node.js 22 or later and Python 3.9 or later; no package installation or credentials are needed:
node --test guide-examples.test.mjs payment-guide-examples.test.mjs
node guide-demo.mjs stripe
python3 stripe-outbox.py
The JavaScript and Python examples exercise separate boundaries; the download is not an assembled web service. Adapt the storage callback to your own stack, then run a sandbox end-to-end test with the SDK/API version pinned in your application. Record that version, the provider event ID, expected order state and job count. Verify invalid signatures, duplicate deliveries, delayed events and a storage outage before relying on the integration. Use the payment-form checklist to cover the input and recovery screens around it.
The linked Stripe fixture and webhook documentation were last checked against provider documentation on . Providers do change what they publish — the official link beside each claim is authoritative.