View Source Ibanity.Webhook (ibanity v1.1.0)

Creates an Ibanity Event from webhook's payload if signature is valid.

Summary

Functions

Verify webhook payload and return an Ibanity webhook event. payload is the raw, unparsed content body sent by Ibanity, which can be retrieved with Plug.Conn.read_body/2. Note that Plug.Parsers will read and discard the body, so you must implement a custom body reader if the plug is located earlier in the pipeline. signature_header is the value of Signature header, which can be fetched with Plug.Conn.get_req_header/2. application is the configured Ibanity application that should be used to fetch the webhook signing keys from the API and compare with the webhook audience. Defaults to :default tolerance is the allowed deviation in seconds from the current system time to the timestamps found in the signature token. Defaults to 30 seconds.

Functions

Link to this function

construct_event(payload, signature_header, application \\ :default, tolerance \\ 30)

View Source
@spec construct_event(String.t(), String.t(), atom(), integer()) ::
  {:ok, Struct} | {:error, any()}

Verify webhook payload and return an Ibanity webhook event. payload is the raw, unparsed content body sent by Ibanity, which can be retrieved with Plug.Conn.read_body/2. Note that Plug.Parsers will read and discard the body, so you must implement a custom body reader if the plug is located earlier in the pipeline. signature_header is the value of Signature header, which can be fetched with Plug.Conn.get_req_header/2. application is the configured Ibanity application that should be used to fetch the webhook signing keys from the API and compare with the webhook audience. Defaults to :default tolerance is the allowed deviation in seconds from the current system time to the timestamps found in the signature token. Defaults to 30 seconds.

Example

case Ibanity.Webhook.construct_event(payload, signature) do
  {:ok, event} ->
    # Return 200 to Ibanity and handle event
  {:error, reason} ->
    # Reject webhook by responding with non-2XX
end