Skip to content

armgit / ente

Public Imported from GitHub
0

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

Tweak

Manav Rathi3c5e20dd5037
diff --git a/web/apps/photos/src/components/pages/gallery/PlanSelector.tsx b/web/apps/photos/src/components/pages/gallery/PlanSelector.tsx
index bf6c011ca7..cb3796e4b9 100644
--- a/web/apps/photos/src/components/pages/gallery/PlanSelector.tsx
+++ b/web/apps/photos/src/components/pages/gallery/PlanSelector.tsx
@@ -9,8 +9,8 @@ import type {
Subscription,
} from "@/new/photos/services/plan";
import {
- activateSubscription,
- cancelSubscription,
+ activateStripeSubscription,
+ cancelStripeSubscription,
getPlansData,
isSubscriptionActive,
isSubscriptionActiveFree,
@@ -785,7 +785,7 @@ function StripeSubscriptionOptions({
const reactivate = async () => {
try {
setLoading(true);
- await activateSubscription();
+ await activateStripeSubscription();
setDialogMessage({
title: t("success"),
content: t("SUBSCRIPTION_ACTIVATE_SUCCESS"),
@@ -825,7 +825,7 @@ function StripeSubscriptionOptions({
const cancel = async () => {
try {
setLoading(true);
- await cancelSubscription();
+ await cancelStripeSubscription();
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.tsx
index 84d02082b2..053af03166 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -41,7 +41,7 @@ import {
} from "@/new/photos/services/files";
import {
redirectToCustomerPortal,
- verifySubscription,
+ verifyStripeSubscription,
} from "@/new/photos/services/plan";
import {
filterSearchableFiles,
@@ -1245,11 +1245,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" && typeof sessionID == "string") {
try {
- const subscription = await verifySubscription(sessionID);
+ const subscription = await verifyStripeSubscription(sessionID);
setDialogMessage({
title: t("SUBSCRIPTION_PURCHASE_SUCCESS_TITLE"),
close: { variant: "accent" },
diff --git a/web/packages/new/photos/services/plan.ts b/web/packages/new/photos/services/plan.ts
index e7bb52418a..82a0cf77aa 100644
--- a/web/packages/new/photos/services/plan.ts
+++ b/web/packages/new/photos/services/plan.ts
@@ -171,7 +171,15 @@ export const getPlansData = async (): Promise<PlansData> => {
export const planUsage = (userDetails: UserDetails) =>
isPartOfFamily(userDetails) ? familyUsage(userDetails) : userDetails.usage;
-export const verifySubscription = async (
+/**
+ * Ask remote to acknowledge a subscription that was completed via Stripe,
+ * updating our local state to reflect the new subscription on successful
+ * verification.
+ *
+ * @param sessionID A token passed on completion of the flow. It is forwarded as
+ * the verification data to remote.
+ */
+export const verifyStripeSubscription = async (
sessionID: string,
): Promise<Subscription> => {
ensureOk(
@@ -189,7 +197,12 @@ export const verifySubscription = async (
return ensure(userDetailsSnapshot()?.subscription);
};
-export const activateSubscription = async () => {
+/**
+ * Ask remote to reactivate the user's current Stripe subscription (that user
+ * had previously cancelled), updating our local state to reflect the changes on
+ * success.
+ */
+export const activateStripeSubscription = async () => {
ensureOk(
await fetch(await apiURL("/billing/stripe/activate-subscription"), {
method: "POST",
@@ -199,7 +212,11 @@ export const activateSubscription = async () => {
return syncUserDetails();
};
-export const cancelSubscription = async () => {
+/**
+ * Ask remote to cancel the user's current Stripe subscription, updating our
+ * local state to reflect the changes on success.
+ */
+export const cancelStripeSubscription = async () => {
ensureOk(
await fetch(await apiURL("/billing/stripe/cancel-subscription"), {
method: "POST",