@@ -81,7 +81,7 @@ export async function previewSeatChange(
8181 newQuantity : number ,
8282) {
8383 validateQuantity ( newQuantity ) ;
84- const { owner, subscriptionItem, proSeatsUsed } =
84+ const { owner, subscription , subscriptionItem, proSeatsUsed } =
8585 await getOwnerSubscription ( organizationId ) ;
8686 const customerId = owner . stripeCustomerId ;
8787 const subscriptionId = owner . stripeSubscriptionId ;
@@ -96,6 +96,8 @@ export async function previewSeatChange(
9696 ) ;
9797 }
9898
99+ const currentQuantity = subscriptionItem . quantity ?? 1 ;
100+
99101 const previewParams = {
100102 customer : customerId ,
101103 subscription : subscriptionId ,
@@ -115,11 +117,21 @@ export async function previewSeatChange(
115117 . autoPagingToArray ( { limit : 1000 } )
116118 : preview . lines . data ;
117119
118- const currentQuantity = subscriptionItem . quantity ?? 1 ;
119- const proratedAmount = previewLines . reduce ( ( total , line ) => {
120+ let proratedAmount = previewLines . reduce ( ( total , line ) => {
120121 if ( ! line . proration ) return total ;
121122 return total + line . amount ;
122123 } , 0 ) ;
124+
125+ if ( proratedAmount === 0 && newQuantity !== currentQuantity ) {
126+ const currentPeriodEnd = subscription . current_period_end ;
127+ proratedAmount = previewLines . reduce ( ( total , line ) => {
128+ if ( line . period . end <= currentPeriodEnd ) {
129+ return total + line . amount ;
130+ }
131+ return total ;
132+ } , 0 ) ;
133+ }
134+
123135 const nextPaymentDate = preview . period_end ;
124136
125137 return {
0 commit comments