Add subcription feature 6

This commit is contained in:
Urtzi Alfaro
2026-01-16 15:19:34 +01:00
parent 6b43116efd
commit 4bafceed0d
35 changed files with 3826 additions and 1789 deletions

View File

@@ -1545,6 +1545,52 @@ class SubscriptionOrchestrationService:
tenant_id=tenant_id)
return None
async def get_invoices(self, tenant_id: str) -> Dict[str, Any]:
"""
Get invoice history for a tenant's subscription
This is an orchestration method that coordinates between:
1. SubscriptionService (to get subscription data)
2. PaymentService (to get invoices from provider)
Args:
tenant_id: Tenant ID
Returns:
Dictionary with invoices data
"""
try:
# Get subscription from database
subscription = await self.subscription_service.get_subscription_by_tenant_id(tenant_id)
if not subscription:
logger.warning("get_invoices_no_subscription",
tenant_id=tenant_id)
return {"invoices": []}
# Check if subscription has a customer ID
if not subscription.customer_id:
logger.warning("get_invoices_no_customer_id",
tenant_id=tenant_id)
return {"invoices": []}
# Get invoices from payment provider
invoices_result = await self.payment_service.stripe_client.get_invoices(subscription.customer_id)
logger.info("invoices_retrieved",
tenant_id=tenant_id,
customer_id=subscription.customer_id,
invoice_count=len(invoices_result.get("invoices", [])))
return invoices_result
except Exception as e:
logger.error("get_invoices_failed",
error=str(e),
tenant_id=tenant_id,
exc_info=True)
return {"invoices": []}
async def update_payment_method(
self,
tenant_id: str,