Building dispute response prep with Stripe and Claude
A charge.dispute.created event fires from Stripe at 4:11am. A few seconds later, Claude has read the dispute reason ("product_not_received"), pulled the matching order from your system, located the shipping carrier tracking number and the delivery confirmation timestamp, retrieved the customer's two prior support conversations, identified that the customer received an automated delivery confirmation at the email on file, drafted a structured dispute response that maps each piece of evidence to one of Stripe's required evidence fields (shipping_documentation, customer_communication, service_documentation), and dropped the whole package into a Linear ticket for the revenue ops lead to review and submit before the response deadline. By the time revenue ops opens Linear at 9am, the case is one human review away from submission — not three hours of evidence gathering.
That's the dispute response workflow most teams are trying to build with Stripe and an LLM. Stripe gives you generous time to respond (typically 7-21 days), but the evidence gathering is tedious, the categorization is error-prone, and disputes that miss the deadline are automatically lost. Building a half-decent AI step here pays for itself the first time it wins a $400 dispute that would have otherwise auto-lost.
The hard part is the event flow. Stripe webhooks are signed, can arrive out of order, keep the same event ID across retries, and carry high stakes: a missed charge.dispute.created is, eventually, a missed deadline. This guide walks through the glue layer end to end: the architecture, seven concrete steps to wire it up, and the production concerns you need to know about.
The flow
There are two webhook flows that need to be reliable:
- Stripe's dispute events into the AI step — is mission-critical and sensitive to ordering. Neither Stripe nor Hookdeck guarantees delivery order, so a
charge.dispute.updatedcan arrive before thecharge.dispute.createdthat preceded it, and a careless handler overwrites a later state with an earlier one. Stripe signs every event and assigns each one a unique event ID for idempotency, but it's up to you to use both correctly. - The AI's outputs back into Linear, Slack, and your evidence storage — must reach all of them reliably. The drafted response, the supporting documents, and the audit log must all land in their respective systems, even when one is briefly down.
Most teams build this with a POST /webhooks/stripe endpoint that calls Claude inline, then writes to a Linear ticket. That's enough to demo. The reasons it isn't enough to run on real chargeback volume are why Hookdeck Event Gateway sits in the middle.
What you'll need
- A Stripe account with admin access to register webhook endpoints
- An Anthropic API key with access to a Claude model
- A Hookdeck Event Gateway account — the free tier covers this workflow at low volume
- Hookdeck CLI installed:
npm install hookdeck-cli -gorbrew install hookdeck - A handler endpoint that gathers internal evidence, calls Claude, and POSTs the result back
- A destination for the response — Linear (or Jira, Asana), object storage for the evidence package, Slack for revenue ops
Step 1: Create the Hookdeck Event Gateway source for Stripe
In the Hookdeck Event Gateway dashboard:
- Create Connection → New Source
- Type: Stripe — Hookdeck Event Gateway has a pre-configured Stripe source that verifies the
Stripe-Signatureheader automatically (see the Stripe webhooks guide) - Name:
stripe-dispute-events - Provide your Stripe webhook signing secret (
whsec_…)
Copy the generated source URL.
Step 2: Register the Stripe webhook endpoint
In the Stripe Dashboard:
- Developers → Webhooks → Add endpoint
- Endpoint URL: paste the Hookdeck source URL
- Description: "AI dispute response prep"
- Events to send:
charge.dispute.created,charge.dispute.updated,charge.dispute.closed,charge.dispute.funds_,withdrawn charge.dispute.funds_reinstated - Save
Trigger a test event from the Stripe CLI or dashboard:
stripe trigger charge.dispute.created
The full event payload should appear in the Hookdeck Event Gateway dashboard within a second. If Stripe Thin Events are enabled for your account, see Stripe Thin Events best practices for the slightly different payload shape.
Step 3: Add the destination — your Claude dispute-prep handler
The handler:
- Receives the canonical dispute event from the transformation in step 4
- Gathers internal evidence — order details, shipping records, support history, customer interactions
- Calls Claude with an evidence-mapping prompt that returns Stripe-compatible structured output
- POSTs the result to a second Hookdeck source for fan-out
A minimal handler:
export default {
async fetch(request, env) {
const event = await request.json();
// Hookdeck delivers at least once and deduplication is best effort,
// so skip events this handler has already finished
const eventKey = `event:${event.stripe_event_id}`;
if (await env.DISPUTE_STATE.get(eventKey)) {
return new Response('duplicate', { status: 200 });
}
// Delivery order isn't guaranteed, so keep only the newest state per dispute
const stateKey = `dispute:${event.dispute_id}`;
const latest = await env.DISPUTE_STATE.get(stateKey, 'json');
if (!latest || event.created >= latest.created) {
await env.DISPUTE_STATE.put(stateKey, JSON.stringify({
type: event.type,
created: event.created,
}));
}
// A late created event still gets a draft, unless the dispute has closed
if (event.type !== 'charge.dispute.created' || latest?.type === 'charge.dispute.closed') {
return new Response('ignored', { status: 200 });
}
const chargeId = event.charge_id;
// Gather internal evidence in parallel
const [order, shipping, support] = await Promise.all([
fetch(`${env.INTERNAL_API}/orders/by-charge/${chargeId}`, {
headers: { authorization: `Bearer ${env.INTERNAL_TOKEN}` },
}).then(r => r.json()),
fetch(`${env.INTERNAL_API}/shipping/by-charge/${chargeId}`, {
headers: { authorization: `Bearer ${env.INTERNAL_TOKEN}` },
}).then(r => r.json()),
fetch(`${env.INTERNAL_API}/support/by-charge/${chargeId}`, {
headers: { authorization: `Bearer ${env.INTERNAL_TOKEN}` },
}).then(r => r.json()),
]);
const response = await fetch('https://api.anthropic.com/v1/messages', {
method: 'POST',
headers: {
'x-api-key': env.ANTHROPIC_API_KEY,
'anthropic-version': '2023-06-01',
'content-type': 'application/json',
},
body: JSON.stringify({
model: 'claude-sonnet-4-5',
max_tokens: 4096,
system: DISPUTE_PROMPT,
messages: [{
role: 'user',
content: JSON.stringify({
dispute_reason: event.reason,
dispute_amount: event.amount,
dispute_currency: event.currency,
response_deadline: event.deadline,
order,
shipping,
support_conversations: support,
}),
}],
}),
});
const result = await response.json();
const draft = JSON.parse(result.content[0].text);
await fetch(env.HOOKDECK_CALLBACK_URL, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({
dispute_id: event.dispute_id,
charge_id: chargeId,
reason: event.reason,
amount: event.amount,
currency: event.currency,
deadline: event.deadline,
draft,
}),
});
await env.DISPUTE_STATE.put(eventKey, '1', { expirationTtl: 60 * 60 * 24 * 30 });
return new Response('ok', { status: 200 });
},
};
DISPUTE_STATE is a key-value store such as a Workers KV namespace. A database with conditional writes is the stronger choice if concurrent deliveries for one dispute are a concern.
Configure the Hookdeck Event Gateway destination:
- Type: HTTP
- URL: your handler URL
- Authentication: an HTTP header carrying a shared secret
Step 4: Add transformation, dedupe, and rate-limit rules
Filter — drop event types you don't care about for this pipeline:
{
"body": {
"type": {
"$in": [
"charge.dispute.created",
"charge.dispute.updated",
"charge.dispute.closed"
]
}
}
}
Transformation — flatten Stripe's nested event into the canonical shape your handler uses. Preserve the Stripe event ID for idempotency:
addHandler('transform', (request, context) => {
const event = request.body;
const obj = event.data.object;
request.body = {
stripe_event_id: event.id,
type: event.type,
dispute_id: obj.id,
charge_id: obj.charge,
reason: obj.reason,
amount: obj.amount,
currency: obj.currency,
status: obj.status,
deadline: obj.evidence_details?.due_by,
created: event.created,
};
return request;
});
Dedupe — Stripe assigns each event a unique ID and retries with the same ID on transient failures. Add a deduplication rule to the connection, after the transformation so that body.stripe_event_id exists:
- Strategy: Include fields, set to
body.stripe_event_id - Time Window:
1 hour
One hour is the longest window Hookdeck allows, and deduplication is best effort. Stripe can retry an event for up to three days, so the rule stops repeats that arrive close together, and the handler's check on stripe_event_id in step 3 catches the rest.
Ordering — Hookdeck doesn't guarantee delivery order, so this check lives in the handler. In step 3, it compares each event's created timestamp with the newest one stored for that dispute_id, and an older event can't overwrite newer state.
Rate limit — disputes are typically low-volume, but a vendor-side issue can produce a burst. A conservative cap keeps Claude calls in check:
- Max delivery rate:
3per second
Retry policy — aggressive on the inbound leg, because missing a dispute event means missing a deadline:
- Initial delay:
30 seconds - Max attempts:
25 - Strategy:
exponential - Apply on status codes:
408, 429, 500, 502, 503, 504, 529
Hookdeck stops automatic retries after one week or 50 attempts, whichever comes first, so this policy runs up to the one-week limit. That's deliberately generous: dispute deadlines run 7-21 days, so even an extended outage shouldn't cause a missed case.
Step 5: Test the inbound leg locally with the CLI
Route the inbound connection to the CLI:
hookdeck login
hookdeck listen 3000 stripe-dispute-events
A local inspector:
// inspect.js
const http = require('http');
http.createServer((req, res) => {
let body = '';
req.on('data', chunk => body += chunk);
req.on('end', () => {
console.log('Dispute event:', JSON.parse(body));
res.writeHead(200);
res.end('ok');
});
}).listen(3000);
Trigger from Stripe:
stripe trigger charge.dispute.created
Verify the canonical event lands in your terminal and the stripe_event_id is preserved. Iterate on the transformation; press r to replay the most recent event when changing the handler.
Step 6: Wire dispute drafts back through Hookdeck
The drafted response fans out:
- Linear / Jira / Asana — create a ticket with the draft attached for revenue ops review
- Object storage (S3, R2) — store the structured evidence package as a JSON file
- Slack — notify the revenue ops channel that a new dispute needs review, with deadline highlighted
Create a second connection with the source dispute-response-drafts and one destination per downstream.
For Linear, set the destination URL to https://api.linear.app/graphql. Hookdeck keeps the handler's POST method. Add LINEAR_TOKEN, LINEAR_REVENUE_OPS_TEAM, and LINEAR_DISPUTE_LABEL as transformation environment variables. A transformation builds the ticket creation:
addHandler('transform', (request, context) => {
const { dispute_id, reason, amount, currency, deadline, draft } = request.body;
const formattedAmount = (amount / 100).toFixed(2);
const deadlineISO = new Date(deadline * 1000).toISOString().slice(0, 10);
request.headers = {
...request.headers,
authorization: process.env.LINEAR_TOKEN,
'content-type': 'application/json',
};
request.body = {
query: `mutation IssueCreate($input: IssueCreateInput!) {
issueCreate(input: $input) { success issue { id identifier } }
}`,
variables: {
input: {
teamId: process.env.LINEAR_REVENUE_OPS_TEAM,
title: `Dispute ${dispute_id} — ${reason} — ${currency.toUpperCase()} ${formattedAmount} — due ${deadlineISO}`,
description: draft.markdown_summary,
priority: 2, // High
labelIds: [process.env.LINEAR_DISPUTE_LABEL],
},
},
};
return request;
});
A second connection from the same source writes the full JSON evidence package to object storage; a third pings Slack with a deadline-highlighted summary.
Retry policy on these callbacks:
- Initial delay:
15 seconds - Max attempts:
20 - Strategy:
exponential
Step 7: Run the full chain end to end
Trigger a real dispute event:
stripe trigger charge.dispute.created
You should see, in order:
- The signed event lands in
stripe-dispute-events - Hookdeck Event Gateway verifies, transforms, dedupes, and delivers to your handler
- Your handler gathers evidence and calls Claude
- The drafted response lands in
dispute-response-drafts - A Linear ticket is created
- A JSON package is written to object storage
- A Slack message lands in the revenue ops channel with the deadline highlighted
Resend the same event from the Stripe Dashboard or with stripe events resend, which keeps the event.id. Within the hour, Hookdeck Event Gateway records the resend as an ignored event with the cause DUPLICATE, and nothing duplicates downstream. Then retry the original event in the Hookdeck Event Gateway dashboard. A retry skips the connection rules, so this time your handler's own check returns duplicate.
If anything fails, the Hookdeck Event Gateway dashboard tells you exactly where, with payload and response visibility at every hop.
Why Hookdeck and not just a try/except in your app server?
Three properties of billing-event workflows make a direct integration the wrong choice once you're past the demo:
Billing events are sensitive to ordering and idempotency. Stripe guarantees at-least-once delivery and assigns each event a unique ID. Without idempotency on the AI step, every retry becomes another Claude call and another Linear ticket. Without a timestamp check, a late dispute.updated can overwrite newer state. Hookdeck Event Gateway's deduplication rule drops repeats that arrive within an hour, before they cost a Claude call, and every delivery is on record when you need to see what arrived and when. Longer-range idempotency and ordering stay in your handler, because the gateway doesn't guarantee either.
Audit trail is non-negotiable for revenue ops. When the finance lead asks "what evidence did we submit for dispute X, when did the event arrive, and what did Claude say?", you need a single answer. Hookdeck Event Gateway stores every event, every transformation, every retry, and every response. The revenue ops team gets a dashboard, not a Slack message to engineering asking for log queries.
Observability protects revenue. A silent failure in the dispute pipeline doesn't show up in product metrics; it shows up two weeks later when finance reconciles auto-lost cases. Hookdeck Event Gateway's Issues feature surfaces failures the day they happen, so revenue ops can react before the deadline passes. You can build all of this on your own: a durable queue with deduplication, retry workers with long-tail policies, an audit log, an observability layer, a replay tool. That's the work Hookdeck collapses into a connection in a dashboard. The hours you don't spend on infrastructure are hours you spend on improving the dispute prompt, the evidence library, and the win-rate.
Going to production
Observability for finance and revenue ops. Wire Issues alerts to a #revenue-ops-alerts Slack channel. A stuck dispute pipeline should be visible to finance, not just engineering.
Tune retries against the deadline. Stripe gives you days to respond, so retry policies can afford to be patient. But the first 24 hours matter most — the human review still needs to happen. Aggressive early retries and a slow tail is the right shape.
Replay deliberately when the prompt changes. When you update the evidence-mapping prompt, Hookdeck Event Gateway's replay lets you re-run past disputes still in your retention period through the new prompt against a preview destination, so revenue ops can A/B the output before flipping live.
Handle PII responsibly. Dispute payloads contain customer details, last-four card digits, and amounts. The transformation in step 4 removes most of that before delivery, but Hookdeck still stores the original request and shows it in the dashboard. Use a private project and add only the people who should see PCI-relevant data.
Plan for Stripe API rate limits on the write-back leg if you submit evidence automatically. This article stops at the drafted response, but if you extend the pipeline to call Stripe's POST /v1/disputes/{id} to submit evidence directly, the max delivery rate on that destination should respect Stripe's 100/sec limit (lower in test mode).
What to build next
This pattern generalizes: Apply it to subscription churn risk analysis (customer.subscription.deleted), failed-payment retry orchestration (invoice.payment_failed), fraud signal aggregation (radar.early_), or revenue-anomaly detection across charge.succeeded events.
If you're building any of this, the fastest way to get past the demo phase is to stop maintaining your own webhook infrastructure. The AI Agents & LLMs use case covers the Hookdeck setup this pattern relies on: delivery timeouts, concurrency limits, filters and replay. Start with the Hookdeck free tier (you can run this entire workflow without paying anything until you hit real volume) and use the CLI to keep your development loop fast.