/qa-payment:stripe-test-cards-and-webhooksfrom qa-payment
Provides Stripe test cards, webhook handler setup, and signature verification for testing payment flows including success, decline, and 3D Secure scenarios.
Ships in qa-payment. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Stripe's test-mode is feature-complete: every API call works against test data, no real money moves. Per docs.stripe.com/testing, test keys (sk_test_* / pk_test_*) accept canonical test cards that deterministically produce success / decline / 3DS challenge.
payment-flow-test-author (its payment-states reference).npm install stripe
pip install stripe
Test keys come from the Stripe Dashboard (Developers → API keys → toggle to "View test data").
import Stripe from 'stripe';
const stripe = new Stripe(process.env.STRIPE_TEST_KEY!);
| Card | Behaviour |
|---|---|
| 4242 4242 4242 4242 | Success (Visa) |
| 5555 5555 5555 4444 | Success (Mastercard) |
| 4000 0000 0000 0002 | Decline (generic_decline) |
| 4000 0000 0000 0341 | Attaches to a Customer, then every charge fails (pm_card_chargeCustomerFail) |
| 4000 0000 0000 9995 | Decline (insufficient_funds) |
| 4000 0000 0000 9987 | Decline (lost_card) |
| 4000 0000 0000 0069 | Expired card |
| 4000 0027 6000 3184 | 3DS authentication required (challenge) |
| 4000 0000 0000 3055 | 3DS supported but frictionless |
| 4100 0000 0000 0019 | Fraud-prevention block |
Test PAN any future expiry; any 3-digit CVC.
test('successful payment via 4242', async () => {
const intent = await stripe.paymentIntents.create({
amount: 1000,
currency: 'usd',
payment_method: 'pm_card_visa',
confirm: true,
return_url: 'https://example.com/return',
});
expect(intent.status).toBe('succeeded');
});
test('declined payment', async () => {
await expect(
stripe.paymentIntents.create({
amount: 1000,
currency: 'usd',
payment_method: 'pm_card_chargeDeclined',
confirm: true,
return_url: 'https://example.com/return',
})
).rejects.toThrow(/card was declined/);
});
import { buffer } from 'micro';
import handler from './stripe-webhook';
test('webhook handler validates signature', async () => {
const payload = JSON.stringify({ type: 'payment_intent.succeeded', data: {...} });
const signature = stripe.webhooks.generateTestHeaderString({
payload,
secret: process.env.STRIPE_WEBHOOK_SECRET!,
});
const req = { headers: { 'stripe-signature': signature }, body: Buffer.from(payload) };
const res = await handler(req as any);
expect(res.statusCode).toBe(200);
});
Per docs.stripe.com/webhooks/signatures:
the Stripe CLI's generateTestHeaderString produces a valid
HMAC-SHA256 signature for testing.
Per docs.stripe.com/stripe-cli:
stripe listen --forward-to http://localhost:3000/webhooks/stripe
# Forwards real Stripe webhook events to your local endpoint
stripe trigger payment_intent.succeeded
# Sends a synthetic event to test your handler
The CLI also exposes a signing secret (different from your prod webhook secret) for local testing.
test('idempotency key prevents duplicate charges', async () => {
const key = 'order-12345';
const r1 = await stripe.paymentIntents.create({...}, { idempotencyKey: key });
const r2 = await stripe.paymentIntents.create({...}, { idempotencyKey: key });
expect(r1.id).toBe(r2.id); // Same PaymentIntent
});
Stripe's fulfillment guide sets two rules that most handlers miss (docs.stripe.com/checkout/fulfillment):
checkout.session.completed arrives while the payment is still
processing. Check the session's payment_status before fulfilling (the
guide fulfills when it is not unpaid), fulfill on
checkout.session.async_payment_succeeded, and handle
checkout.session.async_payment_failed without shipping.UPDATE orders SET status = 'fulfilling'
WHERE checkout_session_id = $1 AND status = 'awaiting_fulfillment'
RETURNING id; -- no row returned: another caller already claimed it, do not ship
Test each path with signed events (see the handler test above):
| Event and session state | Expected |
|---|---|
checkout.session.completed, payment_status: 'unpaid' (bank debit) | Nothing shipped; order waits |
checkout.session.async_payment_succeeded | Shipped once |
checkout.session.async_payment_failed | Not shipped; order cancelled or customer told |
Same session fulfilled twice at once (Promise.all) | Shipped once |
Jest or Sinon fake timers move only your process's clock; Stripe's billing runs on Stripe's time. Use a test clock (docs.stripe.com/billing/testing/test-clocks/api-advanced-usage):
const clock = await stripe.testHelpers.testClocks.create({ frozen_time: start });
const customer = await stripe.customers.create({
test_clock: clock.id,
payment_method: 'pm_card_visa',
invoice_settings: { default_payment_method: 'pm_card_visa' },
});
const sub = await stripe.subscriptions.create({ customer: customer.id, items: [{ price }] });
async function advanceTo(t: number) {
await stripe.testHelpers.testClocks.advance(clock.id, { frozen_time: t });
// advancing takes a few seconds; assert only once the clock is ready
while ((await stripe.testHelpers.testClocks.retrieve(clock.id)).status !== 'ready') {
await new Promise((r) => setTimeout(r, 2000));
}
}
Rules from the same page that break naive tests:
draft for about an hour; advance one more hour
before expecting it paid.customer or subscription.4000 0000 0000 0341
(pm_card_chargeCustomerFail). Cards that simulate issuer declines
cannot be attached to a Customer at all
(docs.stripe.com/testing), so the test
would fail at setup instead of at renewal. Expect invoice.payment_failed.npm test
For webhook-integration tests with stripe listen running:
stripe listen --forward-to http://localhost:3000/webhooks/stripe &
npm test
jobs:
stripe-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v4
- run: npm ci && npm test
env:
STRIPE_TEST_KEY: ${{ secrets.STRIPE_TEST_KEY }}
STRIPE_WEBHOOK_SECRET: ${{ secrets.STRIPE_WEBHOOK_SECRET }}
| Anti-pattern | Why it fails | Fix |
|---|---|---|
| Mocking Stripe SDK directly | Loses signature verification, error mapping | Test against real test-mode API |
| Hardcoded test cards in many tests | Update breakage when Stripe changes | Use named constants for the card PANs |
| Skip webhook signature verification | Webhook replay attack | Always verify |
| Tests without idempotency key | Retried tests duplicate-create | Always set idempotency |
| Mix prod + test keys | Real money risk | Strict per-env key separation |
| Test webhook handler without raw body | body-parser strips bytes; signature mismatch | Use raw body middleware |
| One-off webhook event tests | Per-event-type integration coverage missed | Test the full event matrix relevant to your flow |
| Long-running stripe listen in CI | Hangs builds | Use stripe listen --print-secret then background |
Fulfilling on checkout.session.completed alone | Bank debits complete unpaid; goods ship before the money arrives | Check payment_status; fulfill on async_payment_succeeded |
| Fake timers for renewals and trials | Stripe's billing clock never moves | Test clocks, waiting for ready |
trigger to fast-forward dispute states.payment-flow-test-author (its payment-states reference: state machines + 3DS flows);
PCI scope: pci-dss-control-test-author (qa-compliance).payment-gateway-sandboxes (Adyen / PayPal / Braintree).payment-flow-test-author (refunds, disputes, webhook replay).evals/contractor-stabilised-the-suite-before-friday/criteria.json (opens in a new tab)evals/contractor-stabilised-the-suite-before-friday/task.md (opens in a new tab)evals/every-declined-card-shows-the-same-message/criteria.json (opens in a new tab)evals/every-declined-card-shows-the-same-message/task.md (opens in a new tab)evals/nightly-retries-double-the-test-charges/criteria.json (opens in a new tab)evals/nightly-retries-double-the-test-charges/task.md (opens in a new tab)evals/one-in-five-staging-deliveries-rejected/criteria.json (opens in a new tab)evals/one-in-five-staging-deliveries-rejected/task.md (opens in a new tab)evals/payments-job-burns-the-runner-for-six-hours/criteria.json (opens in a new tab)evals/payments-job-burns-the-runner-for-six-hours/task.md (opens in a new tab)evals/stripe-delayed-payment/criteria.json (opens in a new tab)evals/stripe-delayed-payment/task.md (opens in a new tab)evals/stripe-raw-body/criteria.json (opens in a new tab)evals/stripe-raw-body/task.md (opens in a new tab)evals/stripe-renewal-clock/criteria.json (opens in a new tab)evals/stripe-renewal-clock/task.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub testland/qa --plugin qa-payment4 skills in this plugin
/payment-flow-test-authorUse when a payment integration needs refund, dispute or payment-webhook tests: a refund matrix (full, partial, over-refund) for Stripe, Adyen, PayPal and Braintree, chargebacks with card-network reason codes, and webhook replay through each gateway's simulator./payment-gateway-sandboxesUse when code integrated with Adyen, PayPal or Braintree needs tests in sandbox mode: test credentials, sandbox URLs, deterministic test card numbers and each gateway's webhook simulator. For Stripe use stripe-test-cards-and-webhooks or stripe-subscription-billing-test-author./stripe-subscription-billing-test-authorUse when Stripe subscriptions or recurring billing need tests: trial to paid, proration on upgrade and downgrade, dunning on failed renewals, cancel and reactivate, and the subscription webhook events, using Stripe test clocks to skip through billing cycles without waiting.Other plugins' skills for the same job