{"success":true,"name":"treat-third-party-services-as-unreliable-partners-verify-web","description":"Integrating a payment, SMS, or email provider whose callbacks drive your data","category":"ai-brimind","path":"ai-brimind/treat-third-party-services-as-unreliable-partners-verify-web/SKILL.md","file":"SKILL.md","content":"---\nname: treat-third-party-services-as-unreliable-partners-verify-web\ndescription: \"Integrating a payment, SMS, or email provider whose callbacks drive your data\"\n---\n\n# Treat Third-Party Services as Unreliable Partners: Verify Webhooks, Expect Retries, Keep Your Own Record\n\n## When to use\nThe app integrates an external service (payment gateway, SMS/email provider, calendar sync) whose webhooks or responses change YOUR data — and the design assumes the partner always answers, calls back exactly once, and never lies.\n\n## Example request\nOrder marked 'paid' when the frontend says the payment popup succeeded → the browser closed early or the user faked the call; only the provider's server-side confirmation (webhook or verification API) is allowed to change money-state. A webhook endpoint trusts any request that hits it → anyone who finds the URL can mark orders paid with curl; providers sign their webhooks precisely so you can verify the signature before believing a word. The provider retries a webhook it thinks failed → your handler runs twice and grants the subscription twice; webhook handlers need the same idempotency discipline as any write endpoint, keyed by the provider's event ID. Payment succeeded but your server was down during the webhook → without a reconciliation path (re-fetch status from the provider's API), that order stays 'pending' forever; your DB and theirs WILL disagree someday, and you need the tie-breaker plan.\n\n## Instructions\nAct as an integration architect who treats every third-party service as a business partner in another country: useful, professional, but running on their own clock, their own outages, and their own version of the truth — so the contract between you must survive missed calls, repeated calls, and forged calls. For any integration where external events change your data, do this: (1) Draw the flow of truth first: for money and other critical state, the ONLY writer is server-side confirmation — a signed webhook or your server calling the provider's API to verify — never the frontend reporting 'the popup said success', because the frontend is the user's territory, not the provider's. (2) Guard the webhook door: verify the signature/secret the provider documents (they all provide one — HMAC header, signing secret) and reject unsigned or mis-signed calls; an unverified webhook endpoint is a public 'edit my database' form. (3) Make every webhook handler idempotent by design: providers retry on timeouts and their retries are a FEATURE — store the provider's event ID and skip events you have already processed, so 'delivered twice' changes your data once. Answer them fast (accept, record, respond 200, do heavy work after) so slow processing does not trigger the very retries you then mishandle. (4) Plan for the disagreement day: keep your own record of every external interaction (event ID, payload essentials, timestamp, processing result) and build the reconciliation path — a way to re-ask the provider 'what is the real status of payment X?' and repair your side — because a webhook lost during your downtime is not an if. (5) Sandbox everything through your environment walls: test keys and test webhooks in dev (providers have sandbox modes for exactly this), and never let a test event path write to production data. Only call the integration done once you can answer: 'what happens if their callback never arrives, arrives twice, or arrives forged?' — the answers must be 'we reconcile', 'we deduplicate', and 'we reject', and each answer must point to a line of code, not to optimism.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #222\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}