fix(billing): complete billing module — fix tier change, platform support, merchant portal
- Fix admin tier change: resolve tier_code→tier_id in update_subscription(), delegate to billing_service.change_tier() for Stripe-connected subs - Add platform support to admin tiers page: platform column, filter dropdown, platform selector in create/edit modal, platform_name in tier API response - Filter used platforms in create subscription modal on merchant detail page - Enrich merchant portal API responses with tier code, tier_name, platform_name - Add eager-load of platform relationship in get_merchant_subscription() - Remove stale store_name/store_code references from merchant templates - Add merchant tier change endpoint (POST /change-tier) and tier selector UI replacing broken requestUpgrade() button - Fix subscription detail link to use platform_id instead of sub.id Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -204,12 +204,25 @@ class AdminSubscriptionService:
|
||||
result = self.get_subscription(db, merchant_id, platform_id)
|
||||
sub, merchant = result
|
||||
|
||||
# Handle tier_code separately: resolve to tier_id
|
||||
tier_code = update_data.pop("tier_code", None)
|
||||
if tier_code is not None:
|
||||
if sub.stripe_subscription_id:
|
||||
from app.modules.billing.services.billing_service import billing_service
|
||||
billing_service.change_tier(
|
||||
db, merchant_id, platform_id, tier_code, sub.is_annual
|
||||
)
|
||||
else:
|
||||
tier = self.get_tier_by_code(db, tier_code)
|
||||
sub.tier_id = tier.id
|
||||
|
||||
for field, value in update_data.items():
|
||||
setattr(sub, field, value)
|
||||
|
||||
logger.info(
|
||||
f"Admin updated subscription for merchant {merchant_id} "
|
||||
f"on platform {platform_id}: {list(update_data.keys())}"
|
||||
+ (f", tier_code={tier_code}" if tier_code else "")
|
||||
)
|
||||
|
||||
return sub, merchant
|
||||
|
||||
@@ -96,7 +96,8 @@ class SubscriptionService:
|
||||
db.query(MerchantSubscription)
|
||||
.options(
|
||||
joinedload(MerchantSubscription.tier)
|
||||
.joinedload(SubscriptionTier.feature_limits)
|
||||
.joinedload(SubscriptionTier.feature_limits),
|
||||
joinedload(MerchantSubscription.platform),
|
||||
)
|
||||
.filter(
|
||||
MerchantSubscription.merchant_id == merchant_id,
|
||||
|
||||
Reference in New Issue
Block a user