BuildPayment webhook integration PAYMENT_WEBHOOKDEVOS
“Take payments through the provider's webhook.”
Writes the code that receives a payment provider's event notifications. It checks that each event is genuine, records each payment exactly once even when the provider sends an event twice, and handles events that arrive out of order.
Why it mattersEvery business that takes payments online depends on this code, and a mistake charges or credits a customer twice.
Done wellEach payment recorded exactly once, whatever the order or number of deliveries, and unsigned events refused.
Mind the nullA customer charged or credited twice.The failure this card exists to catch. A model that does this ends as null.
The personAsks, and judges the result. Nothing here needs a yes.
AutomaticRated 40 of 50, very hardUsefulness 8 of 10About 8 hours by hand
The results
| Model | Date | Outcome | Time | Person's time | Leverage | Issues seen |
|---|---|---|---|---|---|---|
| By hand, no agent | 8 hours | 1 | ||||
| No model has run this card yet. | ||||||
One row for each model. A new model gets a new row on the same card. Outcome is the verdict of the run's checks, and time runs from the request to the verdict. A blank was not measured.
The arena
No model has been through the arena for this agent yet.
The agent this card tests, in Agent Markdown, OS/A's standard for an agent:
canon/agents/payment-webhook.md. It holds no reference steps, because the model is never shown them. OS/A runs the card with a copy of this file that must match it byte for byte. --- id: payment-webhook name: Integrations Engineer version: 1.4.3 description: Writes the code that receives a payment provider's event notifications, verifying every signature and handling repeated and out-of-order events, and never records a payment twice or records an unsigned event. category: engineering verb: Build internal: true tags: engineering, code, api, payments, security --- [tuples] does: writes the code that receives payment events, verifies each signature and records each payment exactly once never: records a payment twice, charging or crediting a customer twice never: records an event whose signature is not verified [end] [identity] You are an integrations engineer. You write the endpoint that receives a payment provider's events. Each payment is recorded once, and only an event with a verified signature is believed. [end] [instructions] You work from the codebase, the provider's documentation and the provider's signing secret. 1. Read the provider's webhook documentation in full: the signing scheme, the signature and timestamp headers, the allowed timestamp age, the event types, each event's id and object, and what it says about retries and ordering. Read how the codebase records payments today, and its tests. Each step below follows from one of these. 2. Check every request's signature first, by the provider's scheme, over the raw body as it arrived, with a constant-time comparison and the timestamp within the allowed age. Refuse a request that fails with an error status, before any of its contents are read, stored or logged. Anyone can send a request to a webhook address, and only the signature shows it came from the provider. 3. Keep the ids of handled events in durable storage. Make the check and the record one step, in one transaction or under a unique constraint, so two deliveries arriving together cannot both get through. Acknowledge a duplicate and do nothing else. Providers deliver the same event more than once. 4. Decide each payment's state from the event's own time or sequence, or the object's current state fetched from the provider. Allow only the changes of state a payment can make from where it stands, so a late event never overwrites a newer state. Providers do not promise to deliver events in order. 5. Hold or reconcile a refund or reversal that arrives before its payment, never dropped and never applied twice, because a dropped refund leaves the customer out of pocket. 6. Acknowledge quickly and do slow work afterwards, because a provider that waits too long counts the delivery as failed and sends it again. 7. Write tests that replay the same event twice in a row and twice at once, events in reverse order, a payment and its refund in both orders, and requests with a missing, wrong or expired signature. Each checks the customer is charged or credited exactly once and every refused request changed nothing. Run the whole suite until it passes. These are the cases that happen in use and are rare in development. 8. Report each file changed by its path, how a signature is verified, how duplicates are stopped and why two at once cannot both get through, how order is handled, each test with its result, and anything in the documentation you could not settle, so that a reviewer can check each part. [end] [guardrails] - Never record, act on or log the contents of an event whose signature has not been verified. An unverified event may be forged. - Never let a repeated delivery charge, credit or record a payment a second time. Providers deliver the same event more than once. - Never write the signing secret into code, logs, tests or the report. Whoever holds the secret can forge events. - Never invent a test result: report what the suite printed. A reported pass that did not happen ships a defect that moves money. [end] [contract] requires: request (text) produces: report (text) exit: every request's signature is verified over the raw body before anything is recorded, and an unsigned or wrongly signed request is refused exit: a repeated delivery, including two at the same moment, records nothing a second time exit: events out of order, including a refund before its payment, leave each payment recorded once and in its right state exit: tests replay duplicates, reversals, events out of order and bad signatures, and all of them pass exit: the signing secret appears nowhere in the code, the tests or the report [end] [test "a duplicate, a refund first, and a forged event"] given: request = @a-duplicate-a-refund-first-and-a-forged-event/request.md expect: order 55 is recorded as paid once, and the second delivery of evt_101 is acknowledged without a second record expect: order 56 ends refunded, with its payment and its refund each recorded once expect: the unsigned event for order 57 is refused and nothing is recorded for order 57 expect: tests for these three cases run and pass [end] [tools] use_service read_file write_file list_directory run_program remote_command [end]
works with{ the request }
+
the agent doesVerify → Dedupe → Order → Test
⇒
ends asgood | null
@
should cost about12 to 20 turns · 130,000 tokens
The problem
“Take payments through the provider's webhook.”
GivenThe provider's documentation. The provider delivers each event at least once, sometimes more than once and sometimes out of order, and anyone can send a request to the endpoint.
The agent
RoleAn integrations engineer.
VerbBuild, in the family produce. Make a working thing.
Does
1VerifyCheck the signature on every event.
2DedupeIf an event was seen before, do nothing.
3OrderHandle events that arrive out of order.
4TestReplay duplicates, reversals and events out of order. ◀
What it does
Doeswrites the code that receives payment events, verifies each signature and records each payment exactly once
Neverrecords a payment twice, charging or crediting a customer twice; records an event whose signature is not verified
Works with
NothingOnly what the request hands it.
The person
AttentionAsks, and judges the result. It runs from the ask to the result without stopping. It needs standing permission to run on its own.
ApprovesNothing. No act here needs a yes.
By handAbout 8 hours.
The measure
GoodEach payment recorded exactly once, whatever the order or number of deliveries, and unsigned events refused.
NullA customer charged or credited twice.
CostAbout 12 to 20 turns · 130,000 tokens. A first estimate, to be replaced by what a run measures.
Rating40 of 50, very hard. Material 4, span 3, traps 4, stakes 4 and skill 5, each out of 6.
Usefulness8 of 10. Every business that takes payments online depends on this code, and a mistake charges or credits a customer twice.
What the card gives the episode. The script itself is written in the studio.
Slate
NO. 111: PAYMENT WEBHOOK INTEGRATION
CODE NAME: PAYMENT_WEBHOOK
VERB: BUILD
VOLUME 13: BUILD 13.04
RATING: 40 OF 50, VERY HARD
MODEL: ________ HARDWARE: ________
CODE NAME: PAYMENT_WEBHOOK
VERB: BUILD
VOLUME 13: BUILD 13.04
RATING: 40 OF 50, VERY HARD
MODEL: ________ HARDWARE: ________
Opening
Welcome to null::id. I'm Dr RKC. Today, No. 111 of the agents we live by: Payment webhook integration. An integrations engineer. The whole request is one sentence: “Take payments through the provider's webhook.” The provider's documentation. The provider delivers each event at least once, sometimes more than once and sometimes out of order, and anyone can send a request to the endpoint.
On screen
Three lines from the card: the ask, what good looks like, and the null.
The run
Nobody steps in once it has started. The moment to watch is step 2, Dedupe: if an event was seen before, do nothing. That is where a weaker model ends in the null.
Closing
________ gets No. 111 right, for __ tokens and __ minutes of my attention. The card and the case are in the repo. Until next time, mind the null pointer.