Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

Refactor subscription selection logic in getBestSubscription function to prioritize Stripe subscriptions over AppSumo, simplifying the return conditions for better clarity and maintainability.

Bill Yang50d2f93a5498
diff --git a/server/src/lib/subscriptionUtils.ts b/server/src/lib/subscriptionUtils.ts
index 652bb535b..bd09aa182 100644
--- a/server/src/lib/subscriptionUtils.ts
+++ b/server/src/lib/subscriptionUtils.ts
@@ -326,13 +326,13 @@ export async function getBestSubscription(
getStripeSubscription(stripeCustomerId),
]);
- // If we have both, return the one with higher event limit
- if (appsumoSub && stripeSub) {
- const bestSub = appsumoSub.eventLimit >= stripeSub.eventLimit ? appsumoSub : stripeSub;
- logger.info(
- `Organization has both AppSumo (${appsumoSub.eventLimit} events) and Stripe (${stripeSub.eventLimit} events). Using ${bestSub.source} with ${bestSub.eventLimit} events.`
- );
- return bestSub;
+
+ if (stripeSub) {
+ return stripeSub;
+ }
+
+ if (appsumoSub) {
+ return appsumoSub;
}
// Return whichever one exists