π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Move wip chkpt
Manav Rathifc8bf78fc34d
diff --git a/web/apps/photos/src/components/pages/gallery/PlanSelector.tsx b/web/apps/photos/src/components/pages/gallery/PlanSelector.tsxindex fe67b9c2c6..1a42658ec2 100644--- a/web/apps/photos/src/components/pages/gallery/PlanSelector.tsx+++ b/web/apps/photos/src/components/pages/gallery/PlanSelector.tsx@@ -6,7 +6,9 @@ import type {PlansData,Subscription,} from "@/new/photos/services/plan";-import billingService, {+import {+ activateSubscription,+ cancelSubscription,getPlansData,hasAddOnBonus,isSubscriptionActive,@@ -807,7 +809,7 @@ function StripeSubscriptionOptions({const reactivate = async () => {try {setLoading(true);- await billingService.activateSubscription();+ await activateSubscription();setDialogMessage({title: t("success"),content: t("SUBSCRIPTION_ACTIVATE_SUCCESS"),@@ -846,7 +848,7 @@ function StripeSubscriptionOptions({const cancel = async () => {try {setLoading(true);- await billingService.cancelSubscription();+ await cancelSubscription();setDialogMessage({title: t("success"),content: t("SUBSCRIPTION_CANCEL_SUCCESS"),diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsxindex f22ae33855..1a2c4abd37 100644--- a/web/apps/photos/src/pages/gallery.tsx+++ b/web/apps/photos/src/pages/gallery.tsx@@ -39,6 +39,7 @@ import {getLocalTrashedFiles,sortFiles,} from "@/new/photos/services/files";+import { verifySubscription } from "@/new/photos/services/plan";import {filterSearchableFiles,setSearchCollectionsAndFiles,@@ -115,7 +116,7 @@ import {getAllLocalCollections,} from "services/collectionService";import { syncFiles } from "services/fileService";-import billingService, { redirectToCustomerPortal } from "services/plan";+import { redirectToCustomerPortal } from "services/plan";import { preFileInfoSync, sync } from "services/sync";import { syncTrash } from "services/trashService";import uploadManager from "services/upload/uploadManager";@@ -1237,13 +1238,11 @@ export async function checkSubscriptionPurchase(router: NextRouter,setLoading: SetLoading,) {- const { session_id: sessionId, status, reason } = router.query ?? {};+ const { session_id: sessionID, status, reason } = router.query ?? {};- if (status == "success") {+ if (status == "success" && typeof sessionID == "string") {try {- const subscription = await billingService.verifySubscription(- sessionId as string,- );+ const subscription = await verifySubscription(sessionID);setDialogMessage(getSubscriptionPurchaseSuccessMessage(subscription),);diff --git a/web/packages/new/photos/services/plan.ts b/web/packages/new/photos/services/plan.tsindex e94f247818..423c9fa304 100644--- a/web/packages/new/photos/services/plan.ts+++ b/web/packages/new/photos/services/plan.ts@@ -14,8 +14,8 @@ import {} from "@ente/shared/storage/localStorage";import { getToken } from "@ente/shared/storage/localStorage/helpers";import isElectron from "is-electron";-import type { BonusData, UserDetails } from "./user";import { z } from "zod";+import type { BonusData, UserDetails } from "./user";const PlanPeriod = z.enum(["month", "year"]);@@ -73,71 +73,6 @@ const PlansData = z.object({export type PlansData = z.infer<typeof PlansData>;class billingService {- public async cancelSubscription() {- try {- const response = await HTTPService.post(- await apiURL("/billing/stripe/cancel-subscription"),- null,- null,- {- "X-Auth-Token": getToken(),- },- );- const { subscription } = response.data;- setData(LS_KEYS.SUBSCRIPTION, subscription);- } catch (e) {- log.error("subscription cancel failed", e);- throw e;- }- }-- public async activateSubscription() {- try {- const response = await HTTPService.post(- await apiURL("/billing/stripe/activate-subscription"),- null,- null,- {- "X-Auth-Token": getToken(),- },- );- const { subscription } = response.data;- setData(LS_KEYS.SUBSCRIPTION, subscription);- } catch (e) {- log.error("failed to activate subscription", e);- throw e;- }- }-- public async verifySubscription(- sessionID: string = null,- ): Promise<Subscription> {- try {- const token = getToken();- if (!token) {- return;- }- const response = await HTTPService.post(- await apiURL("/billing/verify-subscription"),- {- paymentProvider: "stripe",- productID: null,- verificationData: sessionID,- },- null,- {- "X-Auth-Token": token,- },- );- const { subscription } = response.data;- setData(LS_KEYS.SUBSCRIPTION, subscription);- return subscription;- } catch (e) {- log.error("Error while verifying subscription", e);- throw e;- }- }-public async leaveFamily() {if (!getToken()) {return;@@ -172,6 +107,56 @@ export const getPlansData = async (): Promise<PlansData> => {return z.object({ data: PlansData }).parse(await res.json()).data;};+const SubscriptionResponse = z.object({+ data: z.object({+ subscription: Subscription,+ }),+});++export const verifySubscription = async (+ sessionID: string,+): Promise<Subscription> => {+ const res = await fetch(await apiURL("/billing/verify-subscription"), {+ method: "POST",+ headers: await authenticatedRequestHeaders(),+ body: JSON.stringify({+ paymentProvider: "stripe",+ productID: null,+ verificationData: sessionID,+ }),+ });+ ensureOk(res);+ const { subscription } = SubscriptionResponse.parse(await res.json()).data;+ setData(LS_KEYS.SUBSCRIPTION, subscription);+ return subscription;+};++export const activateSubscription = async () => {+ const res = await fetch(+ await apiURL("/billing/stripe/activate-subscription"),+ {+ method: "POST",+ headers: await authenticatedRequestHeaders(),+ },+ );+ ensureOk(res);+ const { subscription } = SubscriptionResponse.parse(await res.json()).data;+ setData(LS_KEYS.SUBSCRIPTION, subscription);+};++export const cancelSubscription = async () => {+ const res = await fetch(+ await apiURL("/billing/stripe/cancel-subscription"),+ {+ method: "POST",+ headers: await authenticatedRequestHeaders(),+ },+ );+ ensureOk(res);+ const { subscription } = SubscriptionResponse.parse(await res.json()).data;+ setData(LS_KEYS.SUBSCRIPTION, subscription);+};+/*** Start the flow to purchase or update a subscription by redirecting the user* to the payments app.