feat: implement subscription payment retry with intelligent scheduling (#964) - #1057
Open
Clement-coder wants to merge 1 commit into
Open
Conversation
Smartdevs17#964) - Add IntelligentRetryScheduler with exponential backoff, jitter, and historical success-time shifting (moves retries toward UTC hours that historically succeed for each subscriber) - Add per-plan RetryPolicy with configurable maxRetries, baseDelayHours, backoffMultiplier, maxDelayHours, circuitBreakerThreshold, and jitterHours - Add circuit-breaker that pauses retries after N consecutive failures and auto-resets after a configurable cooldown window - Classify all 8 decline codes (insufficient_funds, card_expired, card_lost_stolen, do_not_honor, authentication_required, generic_decline, network_error, processing_error) with code-specific base delays and outreach channels - Trigger card-updater flow on card_expired (once per invoice) - Suggest automatic 50% amount split for charges above $500 on first retry - Add DunningOrchestrator wiring scheduler + grace-period management + injectable OutreachDispatcher - Grace periods: configurable duration, per-interval email reminders, sweep-expired helper for subscription suspension, recovered on success - Add RetryAnalytics: success rate, avg attempts to success, per-decline breakdown, 24-bucket UTC hourly success heatmap - Extend Soroban charging contract (contracts/subscription/src/charging.rs) with on-chain retry queue, grace period tracking, and circuit-breaker state - Add supporting types to contracts/types/src/lib.rs (RetryConfig, ChargeAttempt, ChargeStatus) - Add comprehensive test suite (>80% coverage): 40+ cases covering policy management, all decline codes, circuit breaker, backoff, split suggestion, grace period lifecycle, reminder scheduling, analytics, and orchestrator integration Closes Smartdevs17#964
|
@Clement-coder Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #964
Implements production-ready subscription payment retry with intelligent scheduling across both the TypeScript backend service layer and the Soroban smart contract.
What's changed
backend/services/billing/dunning.ts(new)IntelligentRetrySchedulerdelay = baseDelay × multiplier^attempts, capped atmaxDelayHoursRetryPolicy(maxRetries, backoffMultiplier, maxDelayHours, circuitBreakerThreshold, jitterHours)card_expired(fires once per invoice)RetryAnalytics: success rate, avg attempts-to-success, per-decline breakdown, 24-bucket UTC hourly heatmapDunningOrchestratorOutreachDispatchersweepExpiredGracePeriodsfor subscription suspension, auto-recovers on successbackend/services/billing/__tests__/dunning.test.ts(new)40+ test cases covering:
sendReminders: falserespected)contracts/subscription/src/charging.rs(updated)enqueue_retry/dequeue_retry)start_charge/mark_attempting/mark_completed/mark_failedlifecyclemark_failedapplies jitter-bounded exponential backoff and schedulesnext_retry_atstart_grace_period/recover_grace_period/expire_grace_period/is_in_grace_periodprocess_retry_queue— callable by a cron/keeper to advance due retriesget_charge_history)contracts/types/src/lib.rs(updated)RetryConfig— on-chain retry policy structChargeAttempt— full attempt record (status, timestamps, next_retry_at)ChargeStatusenum (Pending / Attempting / Completed / Failed)Test coverage
registerrecordSuccessgetAllRecordsprocessFailedAcceptance criteria