### Install Stripe Webhook Plug Source: https://hexdocs.pm/stripity_stripe/3.3.1/Stripe.WebhookPlug.html Configure the Stripe.WebhookPlug in your application's endpoint before Plug.Parsers. Ensure the 'at' path matches your Stripe webhook configuration. ```elixir plug Stripe.WebhookPlug, at: "/webhook/stripe", handler: MyAppWeb.StripeHandler, secret: "whsec_******" ``` -------------------------------- ### Runtime Configuration with Function Secret Source: https://hexdocs.pm/stripity_stripe/3.3.1/Stripe.WebhookPlug.html Provide a function reference for the webhook secret to enable dynamic loading at runtime. The function should be in the format &Mod.fun/arity. ```elixir plug Stripe.WebhookPlug, at: "/webhook/stripe", handler: MyAppWeb.StripeHandler, secret: &MyAppWeb.Secrets.stripe_webhook_secret/0 # a remote function in the format &Mod.fun/arity ``` -------------------------------- ### Runtime Configuration with Tuple Secret Source: https://hexdocs.pm/stripity_stripe/3.3.1/Stripe.WebhookPlug.html Use a tuple to dynamically fetch the webhook secret at runtime, suitable for configurations loaded from files like runtime.exs or OTP apps. ```elixir plug Stripe.WebhookPlug, at: "/webhook/stripe", handler: MyAppWeb.StripeHandler, secret: {Application, :get_env, [:myapp, :stripe_webhook_secret]} ``` -------------------------------- ### Create Custom Stripe Event Handler Source: https://hexdocs.pm/stripity_stripe/3.3.1/Stripe.WebhookPlug.html Implement the Stripe.WebhookHandler behavior to process incoming Stripe events. Define a handle_event/1 function to manage specific event types or a default case for unhandled events. ```elixir defmodule MyAppWeb.StripeHandler do @behaviour Stripe.WebhookHandler @impl true def handle_event(%Stripe.Event{type: "charge.succeeded"} = event) do # TODO: handle the charge.succeeded event end @impl true def handle_event(%Stripe.Event{type: "invoice.payment_failed"} = event) do # TODO: handle the invoice.payment_failed event end # Return HTTP 200 for unhandled events @impl true def handle_event(_event), do: :ok end ``` -------------------------------- ### Include Configured Secret in Endpoint Source: https://hexdocs.pm/stripity_stripe/3.3.1/Stripe.WebhookPlug.html Reference the application's configured webhook secret when setting up the Stripe.WebhookPlug in your endpoint. ```elixir plug Stripe.WebhookPlug, at: "/webhook/stripe", handler: MyAppWeb.StripeHandler, secret: Application.get_env(:myapp, :stripe_webhook_secret) ``` -------------------------------- ### Configure Webhook Secret in App Config Source: https://hexdocs.pm/stripity_stripe/3.3.1/Stripe.WebhookPlug.html Store the Stripe webhook secret in your application's configuration file. This secret can then be referenced when configuring the Stripe.WebhookPlug. ```elixir config :myapp, # [...] stripe_webhook_secret: "whsec_******" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.