Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Flowchart

Manav Rathid26aafc5f494
diff --git a/web/apps/photos/src/utils/billing/index.ts b/web/apps/photos/src/utils/billing/index.ts
index 1eecbac553..654ac1cb32 100644
--- a/web/apps/photos/src/utils/billing/index.ts
+++ b/web/apps/photos/src/utils/billing/index.ts
@@ -31,6 +31,51 @@ enum RESPONSE_STATUS {
fail = "fail",
}
+export type PlanSelectionOutcome =
+ | "buyPlan"
+ | "updateSubscriptionToPlan"
+ | "cancelOnMobile"
+ | "contactSupport";
+
+/**
+ * Return the outcome that should happen when the user selects a paid plan on
+ * the plan selection screen.
+ *
+ * @param subscription Their current subscription details.
+ */
+export const planSelectionOutcome = (
+ subscription: Subscription | undefined,
+) => {
+ // This shouldn't happen, but we need this case to handle missing types.
+ if (!subscription) return "buyPlan";
+
+ // The user is a on a free plan and can buy the plan they selected.
+ if (subscription.productID == "free") return "buyPlan";
+
+ // Their existing subscription has expired. They can buy a new plan.
+ if (subscription.expiryTime < Date.now() * 1000) return "buyPlan";
+
+ // -- The user already has an active subscription to a paid plan.
+
+ // Using stripe
+ if (subscription.paymentProvider == "stripe") {
+ // Update their existing subscription to the new plan.
+ return "updateSubscriptionToPlan";
+ }
+
+ // Using one of the mobile app stores
+ if (
+ subscription.paymentProvider == "appstore" ||
+ subscription.paymentProvider == "playstore"
+ ) {
+ // They need to cancel first on the mobile app stores.
+ return "cancelOnMobile";
+ }
+
+ // Some other bespoke case. They should contact support.
+ return "contactSupport";
+};
+
export function hasPaidSubscription(subscription: Subscription) {
return (
subscription &&