fix(loyalty): read Google Wallet config from core settings instead of module config
Module config only reads from os.environ (not .env), so wallet settings were always None. Core Settings already loads these via env_file=".env". Also adds comprehensive wallet creation tests with mocked Google API. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -655,7 +655,10 @@ class CardService:
|
||||
query = (
|
||||
db.query(LoyaltyTransaction)
|
||||
.join(LoyaltyCard, LoyaltyTransaction.card_id == LoyaltyCard.id)
|
||||
.options(joinedload(LoyaltyTransaction.store))
|
||||
.options(
|
||||
joinedload(LoyaltyTransaction.store),
|
||||
joinedload(LoyaltyTransaction.card).joinedload(LoyaltyCard.customer),
|
||||
)
|
||||
.filter(LoyaltyCard.merchant_id == merchant_id)
|
||||
)
|
||||
if store_id:
|
||||
|
||||
@@ -14,7 +14,7 @@ from typing import Any
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.modules.loyalty.config import config
|
||||
from app.core.config import settings
|
||||
from app.modules.loyalty.exceptions import (
|
||||
GoogleWalletNotConfiguredException,
|
||||
WalletIntegrationException,
|
||||
@@ -35,14 +35,14 @@ class GoogleWalletService:
|
||||
@property
|
||||
def is_configured(self) -> bool:
|
||||
"""Check if Google Wallet is configured."""
|
||||
return bool(config.google_issuer_id and config.google_service_account_json)
|
||||
return bool(settings.loyalty_google_issuer_id and settings.loyalty_google_service_account_json)
|
||||
|
||||
def _get_credentials(self):
|
||||
"""Get Google service account credentials."""
|
||||
if self._credentials:
|
||||
return self._credentials
|
||||
|
||||
if not config.google_service_account_json:
|
||||
if not settings.loyalty_google_service_account_json:
|
||||
raise GoogleWalletNotConfiguredException()
|
||||
|
||||
try:
|
||||
@@ -51,7 +51,7 @@ class GoogleWalletService:
|
||||
scopes = ["https://www.googleapis.com/auth/wallet_object.issuer"]
|
||||
|
||||
self._credentials = service_account.Credentials.from_service_account_file(
|
||||
config.google_service_account_json,
|
||||
settings.loyalty_google_service_account_json,
|
||||
scopes=scopes,
|
||||
)
|
||||
return self._credentials
|
||||
@@ -92,7 +92,7 @@ class GoogleWalletService:
|
||||
if not self.is_configured:
|
||||
raise GoogleWalletNotConfiguredException()
|
||||
|
||||
issuer_id = config.google_issuer_id
|
||||
issuer_id = settings.loyalty_google_issuer_id
|
||||
class_id = f"{issuer_id}.loyalty_program_{program.id}"
|
||||
|
||||
class_data = {
|
||||
@@ -203,7 +203,7 @@ class GoogleWalletService:
|
||||
# Create class first
|
||||
self.create_class(db, program)
|
||||
|
||||
issuer_id = config.google_issuer_id
|
||||
issuer_id = settings.loyalty_google_issuer_id
|
||||
object_id = f"{issuer_id}.loyalty_card_{card.id}"
|
||||
|
||||
object_data = self._build_object_data(card, object_id)
|
||||
|
||||
Reference in New Issue
Block a user