Webhook envelope struct and parsing.
Every ClearBank webhook payload has the following shape:
%{
"Type" => "TransactionSettled",
"Version" => 1,
"Payload" => %{ ... },
"Nonce" => 123456789
}The DigitalSignature and Nonce are in the HTTP headers/body.
Signature verification
Before processing any webhook, always verify the DigitalSignature header
using ClearBank's public key. See ClearBank.Webhook.Verifier.
Webhook delivery guarantees
ClearBank provides at-least-once delivery. Your handler must be
idempotent. Detect duplicates by comparing type, timestamp,
and id in the payload. Respond within 5 seconds with a 200
containing {"nonce": <value>} and a valid DigitalSignature.
Summary
Functions
Builds the JSON response body for a webhook acknowledgement.
Parses a raw webhook body map into a %ClearBank.Webhook{} struct.
Types
@type t() :: %ClearBank.Webhook{ nonce: integer(), payload: map(), type: String.t(), version: non_neg_integer() }
Functions
Builds the JSON response body for a webhook acknowledgement.
Returns a map %{"nonce" => nonce} ready to be JSON-encoded and
returned in your HTTP response.
Examples
response_body = ClearBank.Webhook.ack_body(webhook)
# => %{"nonce" => 123456789}
Parses a raw webhook body map into a %ClearBank.Webhook{} struct.
Examples
raw = Jason.decode!(conn.body)
{:ok, webhook} = ClearBank.Webhook.parse(raw)