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