Merchant.Webhooks (Merchant v0.6.0)
View SourceProvides functions for working with webhooks
Summary
Functions
Verify webhook payload and return a Merchant event.
Types
@type update_params() :: create_params()
Functions
@spec construct_event(String.t(), String.t(), String.t(), String.t(), integer()) :: {:ok, Merchant.WebhookEvent.t()} | {:error, any()}
Verify webhook payload and return a Merchant event.
payload is the raw, unparsed content body sent by Stripe, 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 is the value of Revolut-Signature header, which can be fetched
with Plug.Conn.get_req_header/2.
secret is your webhook endpoint's secret.
tolerance is the allowed deviation in seconds from the current system time
to the timestamp found in signature. Defaults to 300 seconds (5 minutes).
Revolut Merchant API reference: https://developer.revolut.com/docs/guides/accept-payments/tutorials/work-with-webhooks/verify-the-payload-signature
Example
case Merchant.Webhooks.construct_event(payload, timestamp, signature, secret) do
{:ok, %Merchant.WebhookEvent{} = event} ->
# Return 200 to Revolut and handle event
{:error, reason} ->
# Reject webhook by responding with non-2XX
end
@spec create(create_params()) :: {:ok, Merchant.WebhookWithSigningSecret.t()} | Merchant.Client.error()
@spec delete(String.t()) :: :ok | Merchant.Client.error()
@spec retrieve(String.t()) :: {:ok, Merchant.WebhookWithSigningSecret.t()} | Merchant.Client.error()
@spec retrieve_list() :: {:ok, [Merchant.Webhook.t()]} | Merchant.Client.error()
@spec rotate_signing_secret(String.t()) :: {:ok, Merchant.WebhookWithSigningSecret.t()} | Merchant.Client.error()
@spec update(String.t(), update_params()) :: {:ok, Merchant.Webhook.t()} | Merchant.Client.error()