payemnt billing and credits refactoring

This commit is contained in:
IGNY8 VPS (Salman)
2026-01-20 07:39:51 +00:00
parent a97c72640a
commit bc50b022f1
34 changed files with 3028 additions and 307 deletions

View File

@@ -22,8 +22,21 @@ app.autodiscover_tasks()
# Explicitly import tasks from igny8_core/tasks directory
app.autodiscover_tasks(['igny8_core.tasks'])
# Register billing tasks after Django is ready
@app.on_after_finalize.connect
def setup_billing_tasks(sender, **kwargs):
"""Import billing tasks after Django apps are loaded."""
try:
import igny8_core.business.billing.tasks.invoice_lifecycle
import igny8_core.business.billing.tasks.subscription_renewal
except ImportError as e:
import logging
logging.getLogger(__name__).warning(f"Failed to import billing tasks: {e}")
# Celery Beat schedule for periodic tasks
# NOTE: Do NOT set static task_id in options - it causes results to overwrite instead of creating history
app.conf.beat_schedule = {
# Monthly Credits
'replenish-monthly-credits': {
'task': 'igny8_core.modules.billing.tasks.replenish_monthly_credits',
'schedule': crontab(hour=0, minute=0, day_of_month=1), # First day of month at midnight
@@ -38,21 +51,37 @@ app.conf.beat_schedule = {
'schedule': crontab(hour=9, minute=0), # Daily at 09:00 to warn users
},
# Subscription Renewal Tasks
'send-renewal-notices': {
'task': 'billing.send_renewal_notices',
'schedule': crontab(hour=9, minute=0), # Daily at 09:00
# Stripe/PayPal: No advance notice (industry standard) - auto-pay happens on renewal day
# Bank Transfer: Invoice created 3 days before, reminders on Day 0 and Day +1
'create-bank-transfer-invoices': {
'task': 'billing.create_bank_transfer_invoices',
'schedule': crontab(hour=9, minute=0), # Daily at 09:00 - creates invoices 3 days before renewal
},
'process-subscription-renewals': {
'task': 'billing.process_subscription_renewals',
'schedule': crontab(hour=0, minute=5), # Daily at 00:05
'schedule': crontab(hour=0, minute=5), # Daily at 00:05 - auto-pay for Stripe/PayPal
},
'send-invoice-reminders': {
'task': 'billing.send_invoice_reminders',
'schedule': crontab(hour=10, minute=0), # Daily at 10:00
'send-renewal-day-reminders': {
'task': 'billing.send_renewal_day_reminders',
'schedule': crontab(hour=10, minute=0), # Daily at 10:00 - Day 0 reminder for bank transfer
},
'check-expired-renewals': {
'task': 'billing.check_expired_renewals',
'schedule': crontab(hour=0, minute=15), # Daily at 00:15
'schedule': crontab(hour=0, minute=15), # Daily at 00:15 - expire after 7 days
},
# Send day-after reminders + reset credits for unpaid bank transfer renewals
'send-day-after-reminders': {
'task': 'billing.send_day_after_reminders',
'schedule': crontab(hour=9, minute=15), # Daily at 09:15 - Day +1 urgent + credit reset
},
# Credit Invoice Lifecycle Tasks
'send-credit-invoice-expiry-reminders': {
'task': 'billing.send_credit_invoice_expiry_reminders',
'schedule': crontab(hour=9, minute=30), # Daily at 09:30
},
'void-expired-credit-invoices': {
'task': 'billing.void_expired_credit_invoices',
'schedule': crontab(hour=0, minute=45), # Daily at 00:45
},
# Automation Tasks
'check-scheduled-automations': {
@@ -61,7 +90,7 @@ app.conf.beat_schedule = {
},
'check-test-triggers': {
'task': 'automation.check_test_triggers',
'schedule': crontab(minute='*'), # Every minute (task self-checks if any test mode enabled)
'schedule': crontab(minute='*/5'), # Every 5 minutes (task self-checks if any test mode enabled)
},
# Publishing Scheduler Tasks
'schedule-approved-content': {