Skip to content

Commit

Permalink
Merge pull request #4918 from systeminit/fix-si-internal
Browse files Browse the repository at this point in the history
fix(auth-api): Add a new plan state for SI Internal
  • Loading branch information
stack72 authored Nov 4, 2024
2 parents 9b06498 + c392da2 commit 9e51cbc
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions bin/auth-api/src/lib/lago.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,33 @@ export async function getCustomerActiveSubscription(userPk: string) {
// We default to an NOT_FOUND plan so we are fine here for now
}

try {
const si_internal_resp = await client.subscriptions.findSubscription(
`${userPk}_si_internal`,
);
if (si_internal_resp.ok) {
const charges = _.get(
si_internal_resp.data.subscription,
"plan.charges",
[],
) as ChargeObject[];
const paidCharge = _.find(
charges,
(charge: ChargeObject) => charge.billable_metric_code === "resource-hours" && parseFloat(_.get(charge, "properties.amount", "0")) > 0,
);
return {
planCode: si_internal_resp.data.subscription.plan_code,
subscriptionAt: si_internal_resp.data.subscription.subscription_at,
endingAt: si_internal_resp.data.subscription.ending_at,
isTrial: false,
exceededFreeTier: !!paidCharge,
};
}
} catch (err) {
/* empty */
// We default to an NOT_FOUND plan so we are fine here for now
}

return {
planCode: "NOT_FOUND",
isTrial: false,
Expand Down

0 comments on commit 9e51cbc

Please sign in to comment.