feat(loyalty): production readiness round 2 — 12 security, integrity & correctness fixes
Some checks failed
Some checks failed
Security: - Fix TOCTOU race conditions: move balance/limit checks after row lock in redeem_points, add_stamp, redeem_stamps - Add PIN ownership verification to update/delete/unlock store routes - Gate adjust_points endpoint to merchant_owner role only Data integrity: - Track total_points_voided in void_points - Add order_reference idempotency guard in earn_points Correctness: - Fix LoyaltyProgramAlreadyExistsException to use merchant_id parameter - Add StorefrontProgramResponse excluding wallet IDs from public API - Add bounds (±100000) to PointsAdjustRequest.points_delta Audit & config: - Add CARD_REACTIVATED transaction type with audit record - Improve admin audit logging with actor identity and old values - Use merchant-specific PIN lockout settings with global fallback - Guard MerchantLoyaltySettings creation with get_or_create pattern Tests: 27 new tests (265 total) covering all 12 items — unit and integration. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -43,11 +43,11 @@ class LoyaltyProgramNotFoundException(ResourceNotFoundException):
|
||||
class LoyaltyProgramAlreadyExistsException(ConflictException):
|
||||
"""Raised when store already has a loyalty program."""
|
||||
|
||||
def __init__(self, store_id: int):
|
||||
def __init__(self, merchant_id: int):
|
||||
super().__init__(
|
||||
message=f"Store {store_id} already has a loyalty program",
|
||||
message=f"Merchant {merchant_id} already has a loyalty program",
|
||||
error_code="LOYALTY_PROGRAM_ALREADY_EXISTS",
|
||||
details={"store_id": store_id},
|
||||
details={"merchant_id": merchant_id},
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user