stripe-test-cards-and-webhooks
Use for any question or task about testing Stripe payments, including one webhook handler and checkout that fails for 3D Secure cards: test-mode keys, test…
от testland★ 18 звёзд на GitHub
Установить stripe-test-cards-and-webhooks в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
stripe-test-cards-and-webhooks
Overview
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.
When to use
- Tests for code that integrates Stripe.
- Verifying webhook handling.
- 3DS challenge flow tests per the 3DS flows reference in
payment-flow-test-author(its payment-states reference).
Authoring
Install
npm install stripe
pip install stripe
Test keys come from the Stripe Dashboard (Developers → API keys → toggle to "View test data").
Initialize
import Stripe from 'stripe';
const stripe = new Stripe(process.env.STRIPE_TEST_KEY!);
Canonical test cards
| 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.
PaymentIntent end-to-end
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/);
});
Webhook handler test
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.
Stripe CLI local forwarding
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.
Idempotency
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
});
Checkout fulfillment: only when paid, only once
Stripe's fulfillment guide sets two rules that most handlers miss (docs.stripe.com/checkout/fulfillment):
- Delayed payment methods. For methods such as ACH Direct Debit and other
bank debits, "funds won't be immediately available when Checkout
completes":
checkout.session.completedarrives while the payment is still processing. Check the session'spayment_statusbefore fulfilling (the guide fulfills when it is notunpaid), fulfill oncheckout.session.async_payment_succeeded, and handlecheckout.session.async_payment_failedwithout shipping. - More than one caller. The fulfill function "might be called multiple times, possibly concurrently, for the same Checkout Session" (the webhook and the success page, or a redelivered event). A read-then-check of the order status races; claim the session atomically before 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):
| Eve
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- .tessl-plugin/plugin.json
- evals/contractor-stabilised-the-suite-before-friday/criteria.json
- evals/contractor-stabilised-the-suite-before-friday/task.md
- evals/every-declined-card-shows-the-same-message/criteria.json
- evals/every-declined-card-shows-the-same-message/task.md
- evals/nightly-retries-double-the-test-charges/criteria.json
- evals/nightly-retries-double-the-test-charges/task.md
- evals/one-in-five-staging-deliveries-rejected/criteria.json
- evals/one-in-five-staging-deliveries-rejected/task.md
- evals/payments-job-burns-the-runner-for-six-hours/criteria.json
- evals/payments-job-burns-the-runner-for-six-hours/task.md
- evals/stripe-delayed-payment/criteria.json
- evals/stripe-delayed-payment/task.md
- evals/stripe-raw-body/criteria.json
- evals/stripe-raw-body/task.md
- evals/stripe-renewal-clock/criteria.json
- evals/stripe-renewal-clock/task.md
FAQ
Что делает скилл stripe-test-cards-and-webhooks?
Use for any question or task about testing Stripe payments, including one webhook handler and checkout that fails for 3D Secure cards: test-mode keys, test cards for success, declines and 3D Secure, stripe listen to forward webhooks locally, stripe trigger fixtures, and Stripe-Signature verification.
Как установить скилл stripe-test-cards-and-webhooks?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл stripe-test-cards-and-webhooks запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
AnthropicGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
claude-api
AnthropicReference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
algorithmic-art
AnthropicCreating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
mcp-integration
AnthropicThis skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…