Some checks failed
Adds the backend half of the Android tablet rollout. Merchants can
pair tablets to specific stores from /merchants/loyalty/devices (or
admins can pair on behalf from the merchant detail page). Each
pairing issues a long-lived JWT shown ONCE in the response with a
server-rendered QR PNG containing {api_url, store_code, auth_token} —
the tablet scans it on first boot and persists the three fields.
The store API (/api/v1/store/loyalty/*) now accepts these device JWTs
alongside user JWTs. Revoking a device row immediately rejects its
token (401 TERMINAL_DEVICE_REVOKED). Tokens expire after 1 year;
re-pair to renew.
- Migration loyalty_010 + TerminalDevice model
- create_device_token / verify_device_token JWT helpers
- 5 endpoints x 2 portals (merchant + admin on-behalf)
- Bearer-auth wiring in app/api/deps.py
- Pages, shared list partial with one-time pairing-QR modal,
Alpine.js factories
- Locale strings (en authoritative; fr/de/lb seeded with EN copy
for translation)
- 6 integration tests covering pair, list, revoke, idempotency,
cross-merchant rejection, store-API auth via device JWT
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
149 lines
3.3 KiB
Python
149 lines
3.3 KiB
Python
# app/modules/loyalty/schemas/__init__.py
|
|
"""
|
|
Loyalty module Pydantic schemas.
|
|
|
|
Request and response models for the loyalty API endpoints.
|
|
|
|
Usage:
|
|
from app.modules.loyalty.schemas import (
|
|
# Program
|
|
ProgramCreate,
|
|
ProgramUpdate,
|
|
ProgramResponse,
|
|
# Card
|
|
CardEnrollRequest,
|
|
CardResponse,
|
|
# Stamp
|
|
StampRequest,
|
|
StampResponse,
|
|
# Points
|
|
PointsEarnRequest,
|
|
PointsRedeemRequest,
|
|
# PIN
|
|
PinCreate,
|
|
PinVerifyRequest,
|
|
)
|
|
"""
|
|
|
|
from app.modules.loyalty.schemas.card import (
|
|
CardDetailResponse,
|
|
# Card operations
|
|
CardEnrollRequest,
|
|
CardListResponse,
|
|
CardLookupResponse,
|
|
CardResponse,
|
|
TransactionListResponse,
|
|
# Transactions
|
|
TransactionResponse,
|
|
)
|
|
from app.modules.loyalty.schemas.pin import (
|
|
# Staff PIN
|
|
PinCreate,
|
|
PinDetailListResponse,
|
|
PinDetailResponse,
|
|
PinListResponse,
|
|
PinResponse,
|
|
PinUpdate,
|
|
PinVerifyRequest,
|
|
PinVerifyResponse,
|
|
)
|
|
from app.modules.loyalty.schemas.points import (
|
|
PointsAdjustRequest,
|
|
PointsAdjustResponse,
|
|
# Points operations
|
|
PointsEarnRequest,
|
|
PointsEarnResponse,
|
|
PointsRedeemRequest,
|
|
PointsRedeemResponse,
|
|
PointsVoidRequest,
|
|
PointsVoidResponse,
|
|
)
|
|
from app.modules.loyalty.schemas.program import (
|
|
# Merchant settings
|
|
MerchantSettingsResponse,
|
|
MerchantSettingsUpdate,
|
|
MerchantStatsResponse,
|
|
# Points rewards
|
|
PointsRewardConfig,
|
|
# Program CRUD
|
|
ProgramCreate,
|
|
ProgramListResponse,
|
|
ProgramResponse,
|
|
# Stats
|
|
ProgramStatsResponse,
|
|
ProgramUpdate,
|
|
TierConfig,
|
|
)
|
|
from app.modules.loyalty.schemas.stamp import (
|
|
StampRedeemRequest,
|
|
StampRedeemResponse,
|
|
# Stamp operations
|
|
StampRequest,
|
|
StampResponse,
|
|
StampVoidRequest,
|
|
StampVoidResponse,
|
|
)
|
|
from app.modules.loyalty.schemas.terminal_device import (
|
|
# Terminal device pairing & management
|
|
TerminalDeviceCreate,
|
|
TerminalDeviceListResponse,
|
|
TerminalDevicePairingResponse,
|
|
TerminalDeviceResponse,
|
|
TerminalDeviceRevoke,
|
|
TerminalDeviceUpdate,
|
|
)
|
|
|
|
__all__ = [
|
|
# Program
|
|
"ProgramCreate",
|
|
"ProgramUpdate",
|
|
"ProgramResponse",
|
|
"ProgramListResponse",
|
|
"PointsRewardConfig",
|
|
"TierConfig",
|
|
"ProgramStatsResponse",
|
|
"MerchantStatsResponse",
|
|
"MerchantSettingsResponse",
|
|
"MerchantSettingsUpdate",
|
|
# Card
|
|
"CardEnrollRequest",
|
|
"CardResponse",
|
|
"CardDetailResponse",
|
|
"CardListResponse",
|
|
"CardLookupResponse",
|
|
"TransactionResponse",
|
|
"TransactionListResponse",
|
|
# Stamp
|
|
"StampRequest",
|
|
"StampResponse",
|
|
"StampRedeemRequest",
|
|
"StampRedeemResponse",
|
|
"StampVoidRequest",
|
|
"StampVoidResponse",
|
|
# Points
|
|
"PointsEarnRequest",
|
|
"PointsEarnResponse",
|
|
"PointsRedeemRequest",
|
|
"PointsRedeemResponse",
|
|
"PointsVoidRequest",
|
|
"PointsVoidResponse",
|
|
"PointsAdjustRequest",
|
|
"PointsAdjustResponse",
|
|
# PIN
|
|
"PinCreate",
|
|
"PinUpdate",
|
|
"PinResponse",
|
|
"PinDetailResponse",
|
|
"PinListResponse",
|
|
"PinDetailListResponse",
|
|
"PinVerifyRequest",
|
|
"PinVerifyResponse",
|
|
# Terminal device
|
|
"TerminalDeviceCreate",
|
|
"TerminalDeviceUpdate",
|
|
"TerminalDeviceRevoke",
|
|
"TerminalDeviceResponse",
|
|
"TerminalDevicePairingResponse",
|
|
"TerminalDeviceListResponse",
|
|
]
|