{"product_id":"idempotent-payment-webhook-with-postgres-http-api","title":"Idempotent Payment Webhook with Postgres \u0026 HTTP API","description":"\u003ch3\u003eStop duplicate payments with an idempotent payment webhook for n8n\u003c\/h3\u003e\n\u003cp\u003eThis n8n workflow exposes a payment webhook that uses \u003cstrong\u003ePostgres\u003c\/strong\u003e as an idempotency store, ensuring your external payment provider API is called \u003cem\u003eonly once\u003c\/em\u003e per \u003cstrong\u003eIdempotency-Key\u003c\/strong\u003e—and replaying the stored result on retries.\u003c\/p\u003e\n\n\u003ch3\u003eWhat this workflow does\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003e\n\u003cstrong\u003eReceives webhook requests\u003c\/strong\u003e via a POST endpoint with an \u003cstrong\u003eIdempotency-Key\u003c\/strong\u003e header and a JSON payment payload.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eCreates\/ensures Postgres storage\u003c\/strong\u003e (the required \u003ccode\u003eidempotency_keys\u003c\/code\u003e table and indexes) so request status and stored responses are tracked safely.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eValidates and scopes the key\u003c\/strong\u003e by client ID, then computes a \u003cstrong\u003eSHA-256 fingerprint\u003c\/strong\u003e of a canonicalized payload to detect mismatches.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eAtomically claims the idempotency key\u003c\/strong\u003e in Postgres:\n    \u003cul\u003e\n      \u003cli\u003eIf new: it proceeds to call the payment provider.\u003c\/li\u003e\n      \u003cli\u003eIf completed: it \u003cstrong\u003ereplays the stored response\u003c\/strong\u003e to the caller.\u003c\/li\u003e\n      \u003cli\u003eIf the same key is reused with a \u003cstrong\u003edifferent payload\u003c\/strong\u003e: it rejects as a duplicate-order mismatch.\u003c\/li\u003e\n      \u003cli\u003eIf the request is still running: it returns an \u003cstrong\u003ein-progress\u003c\/strong\u003e \/ duplicate-order error.\u003c\/li\u003e\n    \u003c\/ul\u003e\n  \u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eCalls the configured provider endpoint once\u003c\/strong\u003e using an HTTP Request, forwarding the same \u003cstrong\u003eIdempotency-Key\u003c\/strong\u003e header.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eStores outcome back to Postgres\u003c\/strong\u003e, classifying provider responses as replayable success\/decline or failed (retryable timeout\/5xx\/429), and responds with \u003cstrong\u003eIdempotency-Key\u003c\/strong\u003e and \u003cstrong\u003eIdempotent-Replayed\u003c\/strong\u003e headers.\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch3\u003eUse cases\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003ePrevent accidental double-charges when clients retry payment webhooks after timeouts.\u003c\/li\u003e\n  \u003cli\u003eGuarantee consistent payment results for SaaS billing flows under network instability.\u003c\/li\u003e\n  \u003cli\u003eHandle high-volume inbound payment events safely by deduplicating via Idempotency-Key + payload fingerprinting.\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch3\u003eTechnical details\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003e\n\u003cstrong\u003eNodes\/stack:\u003c\/strong\u003e Webhook, if, Code, Postgres, Sticky Note, HTTP Request\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eCore mechanisms:\u003c\/strong\u003e Postgres-backed idempotency, SHA-256 payload fingerprinting, atomic claim\/replay logic\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eConfig:\u003c\/strong\u003e set \u003ccode\u003eproviderUrl\u003c\/code\u003e and policy values such as \u003ccode\u003eleaseSeconds\u003c\/code\u003e and \u003ccode\u003eproviderTimeoutMs\u003c\/code\u003e (as provided in the workflow setup)\u003c\/li\u003e\n\u003c\/ul\u003e","brand":"N8N Commerce","offers":[{"title":"Default Title","offer_id":46154015244467,"sku":"N8N-20288","price":13.99,"currency_code":"GBP","in_stock":true}],"thumbnail_url":"\/\/cdn.shopify.com\/s\/files\/1\/0749\/6279\/6723\/files\/JjjIWWRn_SPGOcm0a_Cg4_a35mpLfA.png?v=1790932671","url":"https:\/\/buyflowscripts.com\/products\/idempotent-payment-webhook-with-postgres-http-api","provider":"N8N Commerce","version":"1.0","type":"link"}