Skip to content

Commit 3c5570a

Browse files
authored
[payment] GitHub: Ignore all "free tier" plans (#16567)
1 parent 3208796 commit 3c5570a

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

components/ee/payment-endpoint/src/github/subscription-mapper.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

components/ee/payment-endpoint/src/github/subscription-reconciler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export class GithubSubscriptionReconciler {
8585
await Promise.all(
8686
Plans.getAvailablePlans("USD")
8787
.filter((p) => !!p.githubId)
88+
.filter((p) => !Plans.isFreePlan(p.chargebeeId)) // don't sync free plans, as we cover those explicitly
8889
.map((p) => this.reconcilePlan(p, token)),
8990
);
9091
}

0 commit comments

Comments
 (0)