1 import { CYCLE, PLANS } from '@proton/shared/lib/constants';
2 import { getCheckout, getOptimisticCheckResult } from '@proton/shared/lib/helpers/checkout';
3 import type { Cycle, PlanIDs, PlansMap } from '@proton/shared/lib/interfaces';
5 // This is currently hardcoded. Once the payments backend supports renewals at different cycles,
6 // it will be changed to more generic code. Currently there is no way to tell which plan renews at which cycle,
7 // so we have to hardcode it.
8 export const isSpecialRenewPlan = (planIDs: PlanIDs) => !!planIDs[PLANS.VPN2024];
10 const getRenewCycle = (cycle: Cycle, planIDs: PlanIDs): CYCLE => {
11 if (!isSpecialRenewPlan(planIDs)) {
15 if (cycle === CYCLE.MONTHLY || cycle === CYCLE.THREE || cycle === CYCLE.YEARLY) {
18 // 15,24,30 all renew at yearly.
22 export const getOptimisticRenewCycleAndPrice = ({
34 const nextCycle = getRenewCycle(cycle, planIDs);
35 const latestCheckout = getCheckout({
38 checkResult: getOptimisticCheckResult({
46 // The API doesn't return the correct next cycle or RenewAmount for the VPN plan since we don't have chargebee
47 // So we calculate it with the cycle discount here
48 renewPrice: latestCheckout.withDiscountPerCycle,
49 renewalLength: nextCycle,