Overview
When a subscription billing attempt fails, the dunning system:- Automatically retries failed payments
- Sends notifications to customers and merchants
- Configures retry intervals and attempt limits
- Takes action after final failure (pause, cancel, or skip)
Dunning management is critical for subscription businesses to reduce involuntary churn from failed payments.
How Payment Retries Work
Dunning Service Architecture
The dunning system uses a service-oriented architecture with specialized handlers inapp/services/DunningService.ts:34-121:
Dunning Job Implementation
TheDunningStartJob orchestrates the retry process in app/jobs/dunning/DunningStartJob.ts:17-49:
Configuration Settings
Merchants configure dunning behavior in the Settings page. The settings are stored in a Shopify metaobject.Payment Failure Settings
Number of retry attempts before final action (0-10)Default: 3 attempts
Days to wait between each retry attempt (1-14)Default: 3 days
Action to take after exhausting all retries
skip- Skip the current billing cyclepause- Pause the subscriptioncancel- Cancel the subscription
Inventory Failure Settings
Retry attempts for inventory-related failures (0-10)
Days between inventory failure retries (1-14)
Action after final inventory failure:
skip, pause, or cancelHow often to notify merchants about inventory issues
immediately- Send notification for each failureweekly- Send weekly digestmonthly- Send monthly digest
Settings UI
The billing failure settings interface fromapp/routes/app.settings._index/components/BillingFailureSettings.tsx:50-138:
Retry Flow
Dunning Tracker
The system tracks each dunning process in the database to prevent duplicate retries:Tracker Fields
shop- Shop domaincontractId- Subscription contract GIDbillingCycleIndex- Which billing cycle failedfailureReason- Payment failure error codecompleted- Whether dunning process is completeattemptCount- Number of retry attempts made
The dunning tracker ensures idempotency, preventing the same failure from triggering multiple retry sequences.
Retry Strategies
Standard Retry
Used for most payment failures:- Schedules retry based on
daysBetweenRetryAttempts - Sends customer notification about retry
- Updates dunning tracker with attempt count
Penultimate Attempt
The second-to-last retry attempt:- Sends warning notification to customer
- Informs customer of upcoming final action
- Provides payment update instructions
Final Attempt
The last retry before taking final action:- Executes configured
onFailureaction - Sends final notification to customer
- Sends merchant notification about the failure
- Marks dunning tracker as completed
Inventory-Specific Handling
Inventory failures require different handling:Merchant Notifications
Merchants receive alerts about out-of-stock items
Configurable Frequency
Notification frequency can be immediate, weekly, or monthly
Separate Retry Logic
Independent retry attempts and intervals from payment failures
Restock Detection
Automatically retries when inventory becomes available
Webhook Integration
The dunning system responds to Shopify webhooks:Subscription Billing Attempt Failure
Triggered when a billing attempt fails:Subscription Billing Attempt Success
Triggered when a retry succeeds:Best Practices
Configure Reasonable Retry Counts
3-5 retry attempts balances recovery rate with customer experience
Common Failure Reasons
payment_method_declined
payment_method_declined
The customer’s payment method was declined. This is the most common failure type. Retries often succeed if the customer updates their payment info or has sufficient funds later.
insufficient_inventory
insufficient_inventory
The subscribed products are out of stock. Requires merchant to restock inventory. Uses separate inventory dunning logic.
payment_method_expired
payment_method_expired
The customer’s card has expired. Requires customer to update payment method. Send payment update email immediately.
invalid_payment_method
invalid_payment_method
The payment method is invalid or no longer exists. Requires customer action to add a new payment method.
Notifications
The dunning system sends notifications to both customers and merchants:Customer Notifications
- Retry attempt notification
- Penultimate warning notification
- Final failure notification
- Payment update instructions
Merchant Notifications
- Final attempt failure summary
- Inventory shortage alerts (configurable frequency)
- Bulk failure reports
Related Features
- Contract Management - Actions taken after final failure
- Billing Schedules - When billing attempts occur
- Customer Portal - Where customers update payment methods