mix pin_stripe.sync_webhook_handlers (PinStripe v0.4.0)

View Source

Sync webhook handlers with Stripe's configured webhook endpoints

This task will:

  1. Fetch all webhook endpoints from your Stripe account using the Stripe CLI
  2. Extract all enabled events from those endpoints
  3. Compare them with handlers in your WebhookHandler module
  4. Generate handlers for any missing events

This is useful for keeping your local webhook handlers in sync with your Stripe webhook configuration, especially after adding new events in the Stripe Dashboard.

Example

mix pin_stripe.sync_webhook_handlers

Options

  • --api-key or -k - The Stripe API key to use (prompts to use config key if not provided)
  • --handler-type or -t - Type of handler to generate: "function", "module", or "ask" (default: prompts user)
  • --skip-confirmation or -y - Skip confirmation prompts and generate all missing handlers
  • --create-handler-module - Module name to create if no WebhookHandler module exists

Prerequisites

This task requires the Stripe CLI to be installed and authenticated:

# Install Stripe CLI (macOS)
brew install stripe/stripe-cli/stripe

# Login to Stripe
stripe login

Handler Types

Function Handler (inline)

Generates inline function handlers in your WebhookHandler module:

handle "customer.created", fn event ->
  # Handle customer.created event
  :ok
end

Module Handler

Generates separate modules with a handle_event/1 function:

# In your WebhookHandler module
handle "customer.created", MyApp.StripeWebhookHandlers.CustomerCreated

# Generated module
defmodule MyApp.StripeWebhookHandlers.CustomerCreated do
  def handle_event(event) do
    # Handle customer.created event
    :ok
  end
end

Ask (interactive)

Prompts you for each event individually, allowing you to choose function or module handlers on a per-event basis.