nihalaninihal commited on
Commit
aea9d7d
·
1 Parent(s): 7f33a54

Fix window_ticks policy enforcement in billing refund validation

Browse files

The issue_refund() method checked max_amount and requires_approval but
never enforced window_ticks. Now compares invoice date_tick against
current tick minus window_ticks, returning policy_violation=True when
outside the refund window.

sentinelops_arena/systems/billing.py CHANGED
@@ -44,7 +44,7 @@ class BillingSystem:
44
  "invoice_count": len(customer_invoices),
45
  }
46
 
47
- def issue_refund(self, invoice_id: str, amount: float, reason: str) -> Dict:
48
  """Validate refund against current policy and process it."""
49
  if self._rate_limit_check():
50
  return {"error": "Rate limit exceeded. Try again next tick."}
@@ -57,7 +57,20 @@ class BillingSystem:
57
  # Check refund policy
58
  if amount > self.refund_policy.max_amount:
59
  return {
60
- "error": f"Refund amount ${amount:.2f} exceeds max allowed ${self.refund_policy.max_amount:.2f}"
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  }
62
 
63
  if invoice["status"] == InvoiceStatus.REFUNDED.value:
 
44
  "invoice_count": len(customer_invoices),
45
  }
46
 
47
+ def issue_refund(self, invoice_id: str, amount: float, reason: str, current_tick: int = 0) -> Dict:
48
  """Validate refund against current policy and process it."""
49
  if self._rate_limit_check():
50
  return {"error": "Rate limit exceeded. Try again next tick."}
 
57
  # Check refund policy
58
  if amount > self.refund_policy.max_amount:
59
  return {
60
+ "error": f"Refund amount ${amount:.2f} exceeds max allowed ${self.refund_policy.max_amount:.2f}",
61
+ "policy_violation": True,
62
+ }
63
+
64
+ # Check refund window
65
+ invoice_tick = invoice.get("date_tick", 0)
66
+ if current_tick - invoice_tick > self.refund_policy.window_ticks:
67
+ return {
68
+ "error": (
69
+ f"Invoice {invoice_id} is outside the refund window "
70
+ f"({self.refund_policy.window_ticks} ticks). "
71
+ f"Invoice date tick: {invoice_tick}, current tick: {current_tick}"
72
+ ),
73
+ "policy_violation": True,
74
  }
75
 
76
  if invoice["status"] == InvoiceStatus.REFUNDED.value: