PhoenixKit.Modules.Billing.Workers.SubscriptionDunningWorker (phoenix_kit v1.7.42)

Copy Markdown View Source

Oban worker for dunning (failed payment recovery).

When a subscription payment fails, the subscription enters past_due status and this worker handles retry attempts during the grace period.

Dunning Process

  1. Initial payment fails → subscription status = past_due
  2. Grace period starts (configurable, default 3 days)
  3. This worker retries payment at intervals
  4. If payment succeeds → status = active
  5. If max attempts reached or grace period ends → status = cancelled

Retry Schedule

Default retry schedule (can be configured):

  • Attempt 1: Immediate (handled by RenewalWorker)
  • Attempt 2: 24 hours later
  • Attempt 3: 48 hours later (2 days)
  • Attempt 4: 72 hours later (3 days, grace period ends)

Configuration

# Settings (stored in database)
billing_subscription_grace_days: 3
billing_dunning_max_attempts: 3

Manual Trigger

%{subscription_id: 123}
|> SubscriptionDunningWorker.new()
|> Oban.insert()