Bling.StripeWebhookHandler (bling v0.4.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

Register this module 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: Bling.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_secret: "..."

Link to this section Summary

Link to this section Functions

Link to this function

handle_event(event)