// Metro module 3842 (f3843). import Record from "../lib/Record"; import GooglePlayPriceChangeRecord from "../modules/premium/native/google_play_price_changes/GooglePlayPriceChangeRecord"; import InvoiceRecord from "./InvoiceRecord"; import { PaymentGateways, SubscriptionStatusTypes, SubscriptionStatusTypesSets, SubscriptionTypes } from "../Constants"; import { SubscriptionPauseReason, SubscriptionPauseReasonSets } from "../components/billing/BillingConstants"; import { PREMIUM_PLANS, SubscriptionPlanInfo, SubscriptionPlans } from "../modules/premium/PremiumConstants"; import { getBasePlanIdForSubscriptionItems } from "../modules/premium/PremiumSubscription"; import Module38 from "../_bundle/Module38"; import { isIOS } from "../utils/PlatformUtils"; import { isGooglePlayBillingSupported } from "../modules/device/BillingPlatformUtils"; import { isPremiumAtLeast } from "../utils/PremiumTypeUtils"; const createSubscriptionItemFromServer = function createSubscriptionItemFromServer(a0) { return { id: a0.id, planId: a0.plan_id, quantity: a0.quantity }; }; class SubscriptionRecord extends Record { constructor(a0) { let planId5, planId6; super(); this.id = a0.id; this.type = a0.type; this.items = a0.items; this.createdAt = a0.createdAt; this.canceledAt = a0.canceledAt; this.currentPeriodStart = a0.currentPeriodStart; this.currentPeriodEnd = a0.currentPeriodEnd; this.status = a0.status; this.paymentSourceId = a0.paymentSourceId; this.paymentGateway = a0.paymentGateway; this.paymentGatewayPlanId = a0.paymentGatewayPlanId; this.paymentGatewaySubscriptionId = a0.paymentGatewaySubscriptionId; this.trialId = a0.trialId; this.trialEndsAt = a0.trialEndsAt; this.renewalMutations = a0.renewalMutations; this.currency = a0.currency; this.pauseEndsAt = a0.pauseEndsAt; this.pauseReason = a0.pauseReason; this.metadata = a0.metadata; this.latestInvoice = a0.latestInvoice; this.useStorekitResubscribe = a0.useStorekitResubscribe; this.price = a0.price; this.userId = a0.userId; this.streakStartedAt = a0.streakStartedAt; this.eligiblePaymentGateways = a0.eligiblePaymentGateways; this.priceChange = a0.priceChange; const renewalMutations = this.renewalMutations; let planId = a0.items[0].planId; let planId2 = null; if (a0.type === SubscriptionTypes.PREMIUM) { const r66 = SubscriptionPlanInfo[a0.items[0].planId]; const { interval, intervalCount } = r66; planId = getBasePlanIdForSubscriptionItems(a0.items, interval, intervalCount); const r3 = renewalMutations != null; planId5 = null; planId6 = planId; if (r3) { const basePlanIdForSubscriptionItems2 = getBasePlanIdForSubscriptionItems(renewalMutations.items, interval, intervalCount); planId2 = basePlanIdForSubscriptionItems2; planId5 = basePlanIdForSubscriptionItems2; planId6 = planId; } } else { const r1 = renewalMutations != null && renewalMutations.items.length > 0; planId5 = null; planId6 = planId; if (r1) { const planId4 = renewalMutations.items[0].planId; planId2 = planId4; planId5 = planId4; planId6 = planId; } } this.planId = planId6; this.additionalPlans = a0.items.filter((item) => item.planId !== planId); if (renewalMutations != null && planId5 != null) { renewalMutations.planId = planId5; renewalMutations.additionalPlans = renewalMutations.items.filter((item) => item.planId !== planId2); } } static createFromServer(a0) { const r1 = { id: a0.id, type: a0.type, createdAt: new Date(a0.created_at), canceledAt: a0.canceled_at != null ? new Date(a0.canceled_at) : null, currentPeriodStart: new Date(a0.current_period_start), currentPeriodEnd: new Date(a0.current_period_end), status: a0.status, paymentSourceId: a0.payment_source_id, paymentGateway: a0.payment_gateway, paymentGatewayPlanId: a0.payment_gateway_plan_id, paymentGatewaySubscriptionId: a0.payment_gateway_subscription_id, trialId: a0.trial_id, trialEndsAt: a0.trial_ends_at != null ? new Date(a0.trial_ends_at) : null, items: a0.items.map(createSubscriptionItemFromServer), renewalMutations: a0.renewal_mutations != null ? { items: a0.renewal_mutations.items.map(createSubscriptionItemFromServer), paymentGatewayPlanId: a0.renewal_mutations.payment_gateway_plan_id } : null, streakStartedAt: a0.streak_started_at != null ? new Date(a0.streak_started_at) : null, currency: a0.currency, pauseEndsAt: a0.pause_ends_at != null ? new Date(a0.pause_ends_at) : null, pauseReason: a0.pause_reason, metadata: a0.metadata, useStorekitResubscribe: a0.use_storekit_resubscribe, price: a0.price, userId: a0.user_id, ...a0.latest_invoice != null ? { latestInvoice: InvoiceRecord.createInvoiceFromServer(a0.latest_invoice) } : {} }; let eligible_payment_gateways = a0.eligible_payment_gateways; if (eligible_payment_gateways == null) { eligible_payment_gateways = null; } r1.eligiblePaymentGateways = eligible_payment_gateways; r1.priceChange = a0.price_change != null ? GooglePlayPriceChangeRecord.createFromServer(a0.price_change) : null; return new SubscriptionRecord(r1); } getCurrentSubscriptionPlanIdForGroup(c13676_0) { return this.items.find((item) => c13676_0.includes(item.planId))?.planId; } get isPremium() { return this.type === SubscriptionTypes.PREMIUM; } get isACOM() { return this.paymentGateway === PaymentGateways.APPLE_ADVANCED_COMMERCE; } get planIdForCurrencies() { let planIdFromItems2; if (this.isPremium) { Module38(this.planIdFromItems != null && this.planIdFromItems !== "", "Premium subscription has no planId for currencies"); planIdFromItems2 = this.planIdFromItems; } else { planIdFromItems2 = this.planId; } return planIdFromItems2; } get planIdFromItems() { return this.getCurrentSubscriptionPlanIdForGroup(Object.values(SubscriptionPlans)); } get premiumPlanIdFromItems() { return this.getCurrentSubscriptionPlanIdForGroup([...PREMIUM_PLANS]); } get isPurchasedViaDesktop() { return this.paymentGateway == null; } get isPurchasedViaAppleGeneric() { return this.paymentGateway === PaymentGateways.APPLE_PARTNER || this.isACOM; } get isPurchasedViaApple() { return this.paymentGateway === PaymentGateways.APPLE || this.isACOM; } get isPurchasedViaGoogle() { return this.paymentGateway === PaymentGateways.GOOGLE; } get isPurchasedExternally() { return this.isPurchasedViaApple || this.isPurchasedViaGoogle; } get isOnPlatformMatchingExternalPaymentGateway() { return this.isPurchasedViaApple && isIOS() || this.isPurchasedViaGoogle && isGooglePlayBillingSupported(); } get hasExternalPlanChange() { return this.isPurchasedExternally && this.renewalMutations != null && this.paymentGatewayPlanId !== this.renewalMutations.paymentGatewayPlanId; } get hasPremiumNitroMonthly() { return this.items.find((item) => item.planId === SubscriptionPlans.PREMIUM_MONTH_TIER_2) != null; } get isBoostOnly() { return this.items.every((item) => [SubscriptionPlans.PREMIUM_MONTH_GUILD, SubscriptionPlans.PREMIUM_YEAR_GUILD].includes(item.planId)); } get isPausedOrPausePending() { return SubscriptionStatusTypesSets.ALL_PAUSE.has(this.status); } get isPaused() { return this.status === SubscriptionStatusTypes.PAUSED; } get isPausedForFractionalPremium() { return this.status === SubscriptionStatusTypes.PAUSED && this.pauseReason === SubscriptionPauseReason.FRACTIONAL_PREMIUM; } get isPausedAllowsUpdatesButNotResume() { return this.status === SubscriptionStatusTypes.PAUSED && SubscriptionPauseReasonSets.CAN_MAKE_SUBSCRIPTION_UPDATES.has(this.pauseReason); } get isPausedAllowsResumeButNotUpdates() { return this.status === SubscriptionStatusTypes.PAUSED && (this.pauseReason === null || !SubscriptionPauseReasonSets.CAN_MAKE_SUBSCRIPTION_UPDATES.has(this.pauseReason)); } get isEnded() { return this.status === SubscriptionStatusTypes.ENDED; } get endedAt() { return this.status === SubscriptionStatusTypes.ENDED ? this.metadata?.ended_at != null ? new Date(this.metadata.ended_at) : this.currentPeriodEnd : null; } get isActive() { return this.status === SubscriptionStatusTypes.ACTIVE; } get statusAllowsPerks() { return SubscriptionStatusTypesSets.ALLOW_PERKS.has(this.status); } get hasActiveTrial() { return this.trialId != null && this.trialEndsAt != null && new Date() < this.trialEndsAt; } get hasActiveDiscount() { if (this.metadata == null) { return false; } const active_discount_id = this.metadata.active_discount_id; const active_discount_expires_at = this.metadata.active_discount_expires_at; return active_discount_id != null && active_discount_expires_at != null && new Date() <= new Date(active_discount_expires_at); } get premiumSince() { let streakStartedAt = this.streakStartedAt; if (streakStartedAt == null) { streakStartedAt = this.createdAt; } return streakStartedAt; } get hasAnyPremiumNitro() { return this.items.some((item) => PREMIUM_PLANS.has(item.planId)); } get hasAnyPremiumGroup() { return this.items.some((item) => item.planId === SubscriptionPlans.PREMIUM_GROUP_MONTH); } hasPremiumAtLeast(c13677_0) { return !!this.isPremium && this.items.some((item) => isPremiumAtLeast(SubscriptionPlanInfo[item.planId].premiumType, c13677_0)); } } export default SubscriptionRecord; export { SubscriptionRecord };