UNPKG

optumflex-subscription-core

Version:

Core logic and utilities for subscription management, pricing calculations, and data processing - framework agnostic

253 lines 7.45 kB
import { PricingPackage, BillingCycle, CartItem, CheckoutPayload, DiscountInfo, PlanType } from '../types/subscription'; /** * Set API key for the package (call this once at app startup) */ export declare const setApiKey: (key: string, endpoint?: string) => void; /** * Ensure package is initialized before executing any function */ export declare const ensureInitialized: () => Promise<void>; /** * Get package validation status */ export declare const getPackageStatus: () => { isInitialized: boolean; error?: string; domain?: string; expiresAt?: string; }; /** * Parse features from API response format */ export declare const parseFeatures: (featuresArr: any[]) => string[]; /** * Parse a single plan from API response */ export declare const parsePlan: (pkg: any) => PricingPackage; /** * Find the minimum price cycle for a plan */ export declare const getMinimumPriceCycle: (prices: PricingPackage["prices"]) => BillingCycle; /** * Get available billing cycles for a plan */ export declare const getAvailableCycles: (prices: PricingPackage["prices"]) => BillingCycle[]; /** * Calculate discount information for a plan and cycle */ export declare const calculateDiscountInfo: (plan: PricingPackage, cycle: BillingCycle) => DiscountInfo; /** * Sort plans based on criteria */ export declare const sortPlans: (plans: PricingPackage[], sortBy: string, selectedCycles: { [planId: string]: BillingCycle; }) => PricingPackage[]; /** * Generate checkout URL with cart data */ export declare const generateCheckoutUrl: (cart: CheckoutPayload[], baseUrl: string) => string; /** * Handle buy now functionality for a single plan */ export declare const handleBuyNow: (plan: PricingPackage, cycle: BillingCycle, companyInfo?: { application?: string; }) => void; /** * Format price with currency symbol */ export declare const formatPrice: (price: number) => string; /** * Calculate total cart value */ export declare const calculateCartTotal: (cart: { plan: PricingPackage; cycle: BillingCycle; }[]) => number; /** * Create checkout payload from cart items */ export declare const createCheckoutPayload: (cart: CartItem[]) => CheckoutPayload[]; /** * Check if a plan has any discounts */ export declare const hasDiscounts: (plan: PricingPackage) => boolean; /** * Get the best discount percentage for a plan */ export declare const getBestDiscountPercentage: (plan: PricingPackage) => number; /** * Validate plan data */ export declare const validatePlan: (plan: any) => boolean; /** * Filter plans by search query */ export declare const filterPlansBySearch: (plans: PricingPackage[], searchQuery: string) => PricingPackage[]; /** * Get period label for display */ export declare const getPeriodLabel: (period: string) => string; /** * Get icon for plan based on index */ export declare const getIcon: (index: number) => string; /** * Get icon color class based on index */ export declare const getIconColor: (index: number) => string; /** * Handle period selection for a plan */ export declare const handlePeriodSelect: (planId: string, period: string, selectedPeriods: { [key: string]: string; }, setSelectedPeriods: (periods: { [key: string]: string; }) => void) => void; /** * Get default billing cycles for all plans */ export declare const getDefaultCycles: (plans: PricingPackage[]) => { [planId: string]: BillingCycle; }; /** * Format currency with proper symbol and formatting */ export declare const formatCurrency: (amount: number, currency?: string) => string; /** * Calculate savings amount and percentage */ export declare const calculateSavings: (originalPrice: number, discountedPrice: number) => { amount: number; percentage: number; }; /** * Process raw API response and convert to subscription data format */ export declare const processSubscriptionData: (apiResponse: any) => { subscriptionPlans: PricingPackage[]; modelPortfolios: PricingPackage[]; }; /** * Get subscription data with default cycles set */ export declare const getSubscriptionData: (apiResponse: any) => { subscriptionPlans: PricingPackage[]; modelPortfolios: PricingPackage[]; defaultCycles: { [planId: string]: BillingCycle; }; }; /** * Create subscription state from API response */ export declare const createSubscriptionState: (apiResponse: any, options?: { initialPlanType?: PlanType; initialSortBy?: string; }) => { subscriptionPlans: PricingPackage[]; modelPortfolios: PricingPackage[]; selectedCycles: { [planId: string]: BillingCycle; }; planType: PlanType; sortBy: string; }; /** * Update selected cycles for plans */ export declare const updateSelectedCycles: (currentCycles: { [planId: string]: BillingCycle; }, planId: string, cycle: BillingCycle) => { [planId: string]: BillingCycle; }; /** * Get sorted and filtered plans for display */ export declare const getDisplayPlans: (plans: PricingPackage[], sortBy: string, selectedCycles: { [planId: string]: BillingCycle; }, searchQuery?: string) => PricingPackage[]; /** * Generate checkout URL for a single plan */ export declare const generateSinglePlanCheckoutUrl: (plan: PricingPackage, cycle: BillingCycle, companyInfo: { application: string; }) => string; /** * Get plan statistics */ export declare const getPlanStatistics: (plans: PricingPackage[]) => { totalPlans: number; plansWithDiscounts: number; averagePrice: number; priceRange: { min: number; max: number; }; }; /** * Validate API response structure */ export declare const validateApiResponse: (response: any) => boolean; /** * Transform API response to component-ready format */ export declare const transformApiResponse: (apiResponse: any) => { isValid: boolean; data?: { subscriptionPlans: PricingPackage[]; modelPortfolios: PricingPackage[]; defaultCycles: { [planId: string]: BillingCycle; }; }; error?: string; }; /** * Check if a billing cycle is selected for a specific plan */ export declare const isSelected: (selectedCycles: { [planId: string]: BillingCycle; }, planId: string, cycle: BillingCycle) => boolean; /** * Get displayed plans with sorting and filtering applied */ export declare const getDisplayedPlans: (plans: PricingPackage[], sortBy: string, selectedCycles: { [planId: string]: BillingCycle; }, searchQuery?: string) => PricingPackage[]; /** * Scroll to a specific section on the page */ export declare const scrollToSection: (sectionId: string) => void; /** * Handle keyboard events for accessibility */ export declare const handleKeyDown: (event: React.KeyboardEvent, action: () => void) => void; /** * Get CSS classes for cycle selection styling */ export declare const getCycleSelectionClasses: (isSelected: boolean, baseClasses?: string) => string; /** * Generate benefits data structure */ export declare const generateBenefitsData: (benefits: Array<{ icon: React.ReactNode; title: string; description: string; }>) => { icon: React.ReactNode; title: string; description: string; id: number; }[]; /** * Generate FAQ data structure */ export declare const generateFAQData: (faqs: Array<{ question: string; answer: string; }>) => { question: string; answer: string; id: number; }[]; //# sourceMappingURL=subscription-utils.d.ts.map