Bling.StripeWebhookHandler (bling v0.2.0)

Handles Stripe webhooks for:

  • customer.deleted
    • cancels all subscriptions and removes the payment method
  • customer.updated
    • updates the default payment method
  • customer.subscription.created
    • creates a new subscription and subscription items
  • customer.subscription.updated
    • updates the subscription
  • customer.subscription.deleted
    • cancels the subscription

Additional events can be handled by implementing the handle_stripe_webhook_event/1 function in your Bling module.

usage

Usage

First make sure to create a file like my_app_web/stripe_webhook_handler.ex:

defmodule MyAppWeb.StripeWebhookHandler do
  use Bling.StripeWebhookHandler, bling: MyApp.Bling
end

Then be sure to register it before the Parsers plug in your endpoint.ex file:

defmodule MyAppWeb.Endpoint do
  # ...

  # this MUST be added right BEFORE the parser
  plug Stripe.WebhookPlug,
    at: "/webhooks/stripe",
    handler: MyAppWeb.StripeWebhookHandler,
    secret: {Application, :get_env, [:stripity_stripe, :webhook_secret]}

  # this should already be present
  plug Plug.Parsers,
    parsers: [:urlencoded, :multipart, :json],
    pass: ["*/*"],
    json_decoder: Phoenix.json_library()

Your config should have a webhook_secret key as well:

config :stripity_stripe, api_key: "...", public_key: "...", webhook_key: "..."

Link to this section Summary

Link to this section Functions

Link to this function

handle_event(event, bling)