import { Plans } from '@automattic/data-stores'; /** * Intermediate structure that normalizes plan pricing from different sources * (PricingMetaForGridPlan, WPCOMProductVariant) into a common shape suitable * for discount calculations. * * All prices are in the smallest currency unit (e.g. cents). */ export interface PlanPriceInfo { /** Billing period length in months (1, 12, 24, 36) */ termMonths: number; /** Regular price per month — no intro offer, no site-level discount */ regularPricePerMonth: number; /** Site-level discounted price per month (currency conversion / proration credit), if any */ discountedPricePerMonth?: number; introOffer?: { /** Monthly-equivalent price during the intro period */ pricePerMonth: number; /** How many months the intro offer lasts */ durationMonths: number; /** False once the offer has already been used by this user */ isActive: boolean; }; } /** * Calculates the total cost of a plan over `durationMonths` months. * * Handles partial billing periods via pro-ration (e.g. a yearly plan priced at * $200/year costs $100 for 6 months). * * When `useIntroOffer` is true (default) and an active intro offer exists, the * intro price is applied for the first `introOffer.durationMonths` months, and * the regular (or discounted) price for the remainder. * * @example * // Monthly plan: $10 intro for 1 month, then $20/month; cost for 6 months: * // 1×$10 + 5×$20 = $110 (in cents: 1100 + 10000 = 11000) * getPlanPriceForDuration( info, 6, { useIntroOffer: true } ) // 11000 * * @example * // Yearly plan: $100/yr intro, $200/yr regular; cost for 6 months: * // useIntroOffer=true → 6×($100/12) = $50 (5000 cents) * // useIntroOffer=false → 6×($200/12) = $100 (10000 cents) */ export declare function getPlanPriceForDuration(info: PlanPriceInfo, durationMonths: number, { useIntroOffer }?: { useIntroOffer?: boolean; }): number; /** * Calculates the percentage discount between a reference price and a cheaper price. * * Always uses Math.floor — conservative, never overstates savings. * * Returns `undefined` (not 0) when there is no saving, allowing callers to * distinguish "no discount" from a computed "0% discount". */ export declare function calculateDiscountPercentage(referencePrice: number, cheaperPrice: number): number | undefined; /** * Converts a `PricingMetaForGridPlan` (from @automattic/data-stores Plans hooks) * into a `PlanPriceInfo` suitable for use with `getPlanPriceForDuration` and * `calculateDiscountPercentage`. * * Returns null when required pricing data is absent (e.g. free/enterprise plans * that have no monthly price, or plans whose billing period is unknown). */ export declare function fromPricingMetaForGridPlan(meta: Plans.PricingMetaForGridPlan): PlanPriceInfo | null; /** * Minimal structural type describing the pricing fields needed from a product * variant. `WPCOMProductVariant` (defined in checkout) satisfies this interface * structurally, so it can be passed directly without importing the checkout type * into this package. * * Key invariants: * - `priceBeforeDiscounts` is always the full-term cost at the regular rate. * - `priceInteger` is the actual amount charged, which embeds both intro and * non-intro portions when an intro offer spans only part of the term * (e.g. a 1-year intro on a 2-year plan). * - When `priceInteger < priceBeforeDiscounts`, the intro price portion is * derived by subtracting the non-intro months at the regular rate. */ export interface VariantPriceData { introductoryInterval: number; /** 'month' | 'year' */ introductoryTerm: string; /** Full-term price at the regular (non-intro) rate */ priceBeforeDiscounts: number; /** Actual price charged for the full term (may embed an intro offer) */ priceInteger: number; termIntervalInMonths: number; } /** * Converts a variant price data object (structurally compatible with * `WPCOMProductVariant`) into a `PlanPriceInfo`. * * `discountedPricePerMonth` is intentionally not set: `WPCOMProductVariant` * does not separate site-level discounts from the intro price. Coupon discounts * in checkout are tracked separately via `product.coupon_savings_integer`. * * Per-month values are derived by dividing full-term prices (integers in the * smallest currency unit) by the number of months. The result is rounded to the * nearest integer (Math.round) so that all fields in the returned `PlanPriceInfo` * remain whole-cent values safe for use with currency formatters. The rounding * error is at most 0.5¢ per month and is negligible for percentage comparisons. */ export declare function fromVariantPriceData(variant: VariantPriceData): PlanPriceInfo; //# sourceMappingURL=plan-pricing-utils.d.ts.map