@@ -75,6 +75,12 @@ export class GithubSubscriptionMapper {
7575 plan : Plan ,
7676 model : SubscriptionModel ,
7777 ) {
78+ if ( Plans . isFreePlan ( plan . chargebeeId ) ) {
79+ // don't sync free plans, as we cover those explicitly
80+ log . debug ( { userId : user . id } , "skip syncing purchased free plan" , { plan } ) ;
81+ return ;
82+ }
83+
7884 model . add (
7985 Subscription . create ( {
8086 userId : user . id ,
@@ -119,13 +125,13 @@ export class GithubSubscriptionMapper {
119125 public mapSubscriptionChange ( user : User , context : ChangeContext , model : SubscriptionModel ) {
120126 const { prevPlan, oldSubscription, newAmount, newStartDate, newPlan } = context ;
121127
122- if ( prevPlan . type == "free" ) {
128+ if ( Plans . isFreePlan ( prevPlan . type ) ) {
123129 // we've changed from the free plan which means we've purchased a new subscription
124130 log . debug ( { userId : user . id } , "upgrading from free plan" ) ;
125131 this . mapSubscriptionPurchase ( user , context . accountID , context . effectiveDate , newPlan , model ) ;
126132 return ;
127133 }
128- if ( newPlan . type == "free" ) {
134+ if ( Plans . isFreePlan ( newPlan . type ) ) {
129135 // we've changed to the free plan which means we're canceling the current subscription
130136 log . debug ( { userId : user . id } , "downgrading to free plan" ) ;
131137 this . mapSubscriptionCancel ( user . id , new Date ( ) . toISOString ( ) , model ) ;
0 commit comments