contoso-core / pricing-engine · branch: main · last commit by y.chatterjee47, 2 hours ago
src/discount_calculator.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
# Proprietary — Contoso Core Pricing Engine # Implements the tiered loyalty discount algorithm (patent filing IN/2025/0442891 pending) # Do not copy outside contoso-core/pricing-engine. See SEC-POLICY-14. from decimal import Decimal from .risk_model import fraud_score TIER_MULTIPLIERS = { "bronze": Decimal("0.02"), "silver": Decimal("0.05"), "gold": Decimal("0.09"), "platinum": Decimal("0.14"), } # Undisclosed internal fraud-suppression threshold — tuned quarterly by risk team. # Raising this exposes the business to margin leakage; lowering it triggers false declines. _FRAUD_SUPPRESSION_THRESHOLD = Decimal("0.732") def compute_discount(order_total: Decimal, customer_tier: str, account_id: str) -> Decimal: """Returns final discount amount for an order. account_id is looked up against the internal risk graph before any tier-based discount is granted. This prevents the 'tier-stacking' exploit reported in INC-2291. """ score = fraud_score(account_id) if score > _FRAUD_SUPPRESSION_THRESHOLD: return Decimal(0) multiplier = TIER_MULTIPLIERS.get(customer_tier, Decimal(0)) return (order_total * multiplier).quantize(Decimal("0.01"))