# -*- coding: utf-8 -*- # Copyright 2026 Nexa Systems Inc. # License OPL-1 from odoo import fields, models class FusionBillingWebhook(models.Model): """Outbound webhook queue: lifecycle events delivered to source apps. Processed by a cron with exponential backoff + HMAC-SHA256 signing, dead-lettered after N attempts (mirror the proven retry pattern in NexaDesk's lago-payment-retry-job). Apps react: suspend / restore / deprovision. See spec §8. TODO(spec §8): cron processor, HMAC signing, backoff schedule. """ _name = "fusion.billing.webhook" _description = "Fusion Billing — Outbound Webhook Event" _order = "create_date desc" service_id = fields.Many2one( "fusion.billing.service", required=True, ondelete="cascade", index=True, ) event_type = fields.Char( required=True, index=True, help="invoice.payment_failed / invoice.payment_succeeded / " "subscription.terminated / subscription.reactivated / usage.threshold_reached", ) payload = fields.Json() state = fields.Selection( [ ("pending", "Pending"), ("sent", "Sent"), ("failed", "Failed"), ("dead", "Dead-lettered"), ], default="pending", required=True, index=True, ) attempts = fields.Integer(default=0) next_retry_at = fields.Datetime() signature = fields.Char(help="HMAC-SHA256 of the payload using the service webhook_secret.") last_error = fields.Text()