@@ -553,6 +553,17 @@ export class StripeSubscriptionService {
553553 const isTrialOngoing =
554554 trialEndDateStr && new Date ( trialEndDateStr ) . getTime ( ) > Date . now ( ) ;
555555
556+ // Initialize or update the licenses object based on billing seats
557+ const currentSeats = metadata ?. userCount || 1 ;
558+ const existingUsedSeats =
559+ team . licenses ?. usedSeats || team . users ?. length || 0 ;
560+ const licenseUpdate : LicensesDto = {
561+ totalSeats : Number ( currentSeats ) ,
562+ usedSeats : existingUsedSeats ,
563+ availableSeats : Number ( currentSeats ) - existingUsedSeats ,
564+ lastUpdated : new Date ( ) ,
565+ } ;
566+
556567 // Find valid line item
557568 let validLineItem = null ;
558569 if ( ! isTrialOngoing ) {
@@ -609,7 +620,7 @@ export class StripeSubscriptionService {
609620 currency : invoice . currency ,
610621 status : SubscriptionStatus . ACTIVE ,
611622 latest_invoice : invoice . id ,
612- seats : metadata ?. userCount || 1 ,
623+ seats : currentSeats ,
613624 invoice_url : invoice . hosted_invoice_url ,
614625 billingType : StripeSubscriptionHelpers . determineBillingType (
615626 {
@@ -635,7 +646,10 @@ export class StripeSubscriptionService {
635646 } ;
636647
637648 await this . updateTeamPlanWithBilling ( metadata . hubId , plan , billingDetails ) ;
638-
649+ // Update team with new license data
650+ await this . stripeSubscriptionRepo . updateTeamById ( metadata . hubId , {
651+ licenses : licenseUpdate ,
652+ } ) ;
639653 // Log appropriate events based on payment type
640654 await this . logPaymentEvents (
641655 metadata . hubId ,
0 commit comments