{"success":true,"name":"in-payments-the-webhook-is-the-truth-never-mark-paid-from-th","description":"Integrating a payment provider and deciding when an order becomes 'paid","category":"ai-brimind","path":"ai-brimind/in-payments-the-webhook-is-the-truth-never-mark-paid-from-th/SKILL.md","file":"SKILL.md","content":"---\nname: in-payments-the-webhook-is-the-truth-never-mark-paid-from-th\ndescription: \"Integrating a payment provider and deciding when an order becomes 'paid'\"\n---\n\n# In Payments, the Webhook Is the Truth: Never Mark Paid From the Client Redirect\n\n## When to use\nThe project takes payments through a provider (checkout page, redirect, or client SDK), and you're writing the code that flips an order to paid/active.\n\n## Example request\nOrder marked paid when the user lands on /success → anyone can visit that URL, and closed tabs never arrive; the success page is decoration, not proof. — Client sends 'payment done' with the amount → attacker replays it with amount changed to 1; the provider's server-signed webhook is the only trusted witness. — User pays but closes the browser before redirecting → money taken, order stuck unpaid; the webhook arrives anyway because it's server-to-server. — Webhook handler trusts any POST to its URL → forged requests mark orders paid for free; signature verification is the provider's built-in defense.\n\n## Instructions\nAct as an accountant who only records money when the bank itself confirms it, never when the customer says so. When wiring payment status: 1) Draw the two paths — the user's browser path (checkout → redirect to success page) and the provider's server path (webhook to your backend) — and mark only the second as trusted; the browser path can be faked, skipped, or interrupted. 2) The success page shows a friendly 'thanks, confirming…' state and may poll your own backend; it must never itself flip anything to paid. 3) In the webhook handler: verify the provider's signature first (their SDK has a function for it — use it, don't hand-roll), then match the event to your order by your own stored reference, then check the amount and currency equal what YOU stored — never what the request claims. 4) Expect duplicates and disorder: webhooks retry, so the handler must be idempotent — processing the same event twice changes nothing. 5) Keep your own payment record with status history so disputes can be reconstructed. If the provider's webhook docs are unclear, read them before coding — every major provider documents this exact flow. Only ship once you've tested the paths where the redirect never happens and where a forged webhook is rejected, and explain why the trusted path is the server-signed one, not the appearance of success.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #963\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}