payment-flow-test-author
FreeNo executable scriptsNot checkedUse when a payment integration needs refund, dispute or payment-webhook tests: a refund matrix (full, partial, over-refund) for Stripe, Adyen, PayPal and…
by testland★ 18 GitHub starsAbout this skill
payment-flow-test-author
Overview
The three highest-incident payment surfaces after the happy path - refunds, disputes, and webhook handling - are one suite-authoring job, because they share the same substrate: the gateway's async state machine. This workflow builds all three phases in dependency order, driven by the canonical states in references/payment-flow-states.md.
Common bugs each phase catches: double-refund and partial-refund-not-summing (Phase 1); missed evidence deadlines and unreconciled chargeback fees (Phase 2); non-idempotent redelivery handling and spoofable handlers (Phase 3).
When to use
- New payment integration; need refund / dispute / webhook coverage.
- A refund- or webhook-related incident; need to backfill tests.
- Gateway migration; need to re-validate flow logic.
Phase 0 - Map the state machine
Before writing any test, translate the canonical lifecycle (created → requires_action → processing → succeeded → refunded / disputed) into your gateway's vocabulary using references/payment-flow-states.md. Every assertion below is on a state from that grid, and every async assertion waits on the webhook, never the synchronous API return.
Phase 1 - The refund matrix
Inventory refund touchpoints
grep -rn 'refund\|Refund\|REFUND' --include='*.{ts,js,py,java,go,rb,cs}' .
Categorise per gateway + per code path (order cancellation, CS portal, subscription downgrade, dispute-lost automation).
The 7 canonical refund cases
For each (gateway, touchpoint):
| # | Test | Expected |
|---|---|---|
| 1 | Full refund of captured charge | refund.status = succeeded; charge.amount_refunded = charge.amount |
| 2 | Partial refund (50%) | refund.amount = 0.5x charge.amount |
| 3 | Multiple partials summing to full | Cumulative refunded = charge.amount; charge.refunded = true |
| 4 | Over-refund attempt (101%) | Gateway rejects; descriptive error |
| 5 | Refund of already-fully-refunded charge | Rejected with "charge_already_refunded" or equivalent |
| 6 | Refund of failed charge | Rejected; no refund created |
| 7 | Refund of disputed charge | Per gateway policy: blocks or allows without reversing the dispute |
Per-gateway refund APIs
Stripe, per docs.stripe.com/refunds:
test('over-refund rejected', async () => {
const intent = await createSucceededIntent({ amount: 1000 });
await expect(
stripe.refunds.create({ payment_intent: intent.id, amount: 1500 })
).rejects.toThrow(/refund_amount_exceeds_charge_amount/);
});
Adyen refunds are async, per
docs.adyen.com/online-payments/refund:
the call returns [refund-received]; completion arrives as a [REFUND]
notification - assert via webhook, not the sync response. PayPal uses
CapturesRefundRequest per
developer.paypal.com/docs/api/payments/v2#captures_refund;
Braintree requires settlement first (gateway.testing.settle, sandbox-only)
before gateway.transaction.refund.
Refund idempotency
test('idempotent refund', async () => {
const intent = await createSucceededIntent({ amount: 1000 });
const key = 'refund-' + intent.id;
const r1 = await stripe.refunds.create({ payment_intent: intent.id, amount: 500 }, { idempotencyKey: key });
const r2 = await stripe.refunds.create({ payment_intent: intent.id, amount: 500 }, { idempotencyKey: key });
expect(r1.id).toBe(r2.id);
});
Without idempotency, network retries double-refund the customer.
Phase 2 - The chargeback / dispute suite
- Pick the 3-5 reason codes most common for your business from references/reason-codes.md - each code has different evidence requirements.
- Trigger a disputable charge in the gateway's test mode (Stripe
pm_card_createDisputeper docs.stripe.com/testing#disputes; an Adyen[CHARGEBACK]notification per docs.adyen.com/risk-management/disputes-api; a PayPal sandbox dispute per developer.paypal.com/docs/api/customer-disputes/v1). - Assert the dispute lands in
needs_response(or the gateway equivalent) with the expected reason. - Submit evidence before
evidence_details.due_byand asserthas_evidenceis set, per docs.stripe.com/disputes/responding. - Drive each disposition - won (winning evidence), lost (no response),
accepted - and confirm the final state via the
charge.dispute.closedwebhook. - Verify the ledger reverses funds plus the chargeback fee on a lost dispute.
test('lost dispute reverses funds in ledger', async () => {
const intent = await
Install payment-flow-test-author in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
Bundled files
FAQ
What does the payment-flow-test-author skill do?
Use 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.
How do I install the payment-flow-test-author skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the payment-flow-test-author skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
by Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
by Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
by Anthropicmcp-integration
This 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…
by Anthropic