Skip to content

[payment] GitHub: Ignore all "free tier" plans #16567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions components/ee/payment-endpoint/src/github/subscription-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ export class GithubSubscriptionMapper {
plan: Plan,
model: SubscriptionModel,
) {
if (Plans.isFreePlan(plan.chargebeeId)) {
// don't sync free plans, as we cover those explicitly
log.debug({ userId: user.id }, "skip syncing purchased free plan", { plan });
return;
}

model.add(
Subscription.create({
userId: user.id,
Expand Down Expand Up @@ -119,13 +125,13 @@ export class GithubSubscriptionMapper {
public mapSubscriptionChange(user: User, context: ChangeContext, model: SubscriptionModel) {
const { prevPlan, oldSubscription, newAmount, newStartDate, newPlan } = context;

if (prevPlan.type == "free") {
if (Plans.isFreePlan(prevPlan.type)) {
// we've changed from the free plan which means we've purchased a new subscription
log.debug({ userId: user.id }, "upgrading from free plan");
this.mapSubscriptionPurchase(user, context.accountID, context.effectiveDate, newPlan, model);
return;
}
if (newPlan.type == "free") {
if (Plans.isFreePlan(newPlan.type)) {
// we've changed to the free plan which means we're canceling the current subscription
log.debug({ userId: user.id }, "downgrading to free plan");
this.mapSubscriptionCancel(user.id, new Date().toISOString(), model);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export class GithubSubscriptionReconciler {
await Promise.all(
Plans.getAvailablePlans("USD")
.filter((p) => !!p.githubId)
.filter((p) => !Plans.isFreePlan(p.chargebeeId)) // don't sync free plans, as we cover those explicitly
.map((p) => this.reconcilePlan(p, token)),
);
}
Expand Down