[web] Redirect to payment portal if subscription is past due
This commit is contained in:
parent
a581e31ef9
commit
a15e9b0c9a
2 changed files with 25 additions and 3 deletions
|
@ -4,8 +4,10 @@ import { Box, Skeleton } from "@mui/material";
|
|||
import Typography from "@mui/material/Typography";
|
||||
import { GalleryContext } from "pages/gallery";
|
||||
import { useContext, useEffect, useMemo, useState } from "react";
|
||||
import billingService from "services/billingService";
|
||||
import { getUserDetailsV2 } from "services/userService";
|
||||
import { UserDetails } from "types/user";
|
||||
import { hasStripeSubscription, isSubscriptionPastDue } from "utils/billing";
|
||||
import { isFamilyAdmin, isPartOfFamily } from "utils/user/family";
|
||||
import { MemberSubscriptionManage } from "../MemberSubscriptionManage";
|
||||
import SubscriptionCard from "./SubscriptionCard";
|
||||
|
@ -50,9 +52,20 @@ export default function UserDetailsSection({ sidebarView }) {
|
|||
[userDetails],
|
||||
);
|
||||
|
||||
const handleSubscriptionCardClick = isMemberSubscription
|
||||
? openMemberSubscriptionManage
|
||||
: galleryContext.showPlanSelectorModal;
|
||||
const handleSubscriptionCardClick = () => {
|
||||
if (isMemberSubscription) {
|
||||
openMemberSubscriptionManage();
|
||||
} else {
|
||||
if (
|
||||
hasStripeSubscription(userDetails.subscription) &&
|
||||
isSubscriptionPastDue(userDetails.subscription)
|
||||
) {
|
||||
billingService.redirectToCustomerPortal();
|
||||
} else {
|
||||
galleryContext.showPlanSelectorModal();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
|
|
|
@ -17,6 +17,7 @@ const PAYMENT_PROVIDER_STRIPE = "stripe";
|
|||
const PAYMENT_PROVIDER_APPSTORE = "appstore";
|
||||
const PAYMENT_PROVIDER_PLAYSTORE = "playstore";
|
||||
const FREE_PLAN = "free";
|
||||
const THIRTY_DAYS_IN_MICROSECONDS = 30 * 24 * 60 * 60 * 1000 * 1000;
|
||||
|
||||
enum FAILURE_REASON {
|
||||
AUTHENTICATION_FAILED = "authentication_failed",
|
||||
|
@ -151,6 +152,14 @@ export function hasExceededStorageQuota(userDetails: UserDetails) {
|
|||
}
|
||||
}
|
||||
|
||||
export function isSubscriptionPastDue(subscription: Subscription) {
|
||||
const currentTime = Date.now() * 1000;
|
||||
return (
|
||||
subscription.expiryTime < currentTime &&
|
||||
subscription.expiryTime > currentTime - THIRTY_DAYS_IN_MICROSECONDS
|
||||
);
|
||||
}
|
||||
|
||||
export function isPopularPlan(plan: Plan) {
|
||||
return plan.storage === 100 * ONE_GB;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue