Add subcription feature 6
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user