File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed 
readthedocs/subscriptions Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -140,10 +140,15 @@ def get_context_data(self, **kwargs):
140140            context ["features" ] =  features .values ()
141141            # When Stripe marks the subscription as ``past_due``, 
142142            # it means the usage of RTD service for the current period/month was not paid at all. 
143-             # Show the end date as the last period the customer paid. 
143+             # Show the end date as the last period the customer paid, 
144+             # or in case the subscription is not paid at all, 
145+             # default to the first unpaid invoice end date. 
144146            context ["subscription_end_date" ] =  stripe_subscription .current_period_end 
145147            if  stripe_subscription .status  ==  SubscriptionStatus .past_due :
146-                 latest_paid_invoice  =  stripe_subscription .invoices .filter (paid = True ).first ()
148+                 latest_paid_invoice  =  (
149+                     stripe_subscription .invoices .filter (paid = True ).first ()
150+                     or  stripe_subscription .invoices .filter (paid = False ).last ()
151+                 )
147152                context ["subscription_end_date" ] =  latest_paid_invoice .period_end 
148153
149154        return  context 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments