// Metro module 6251 (f6252). import _objectWithoutProperties from "../../../_bundle/_objectWithoutProperties"; import { useCallback } from "react"; import { setGPlayAnalytics } from "../../gplay/native/GPlayAnalyticsStore"; import AuthenticationStore from "../../../stores/AuthenticationStore"; import SubscriptionStore from "../../../stores/billing/SubscriptionStore"; import IAPStore_android from "../../../stores/native/IAPStore.android"; import { Endpoints, AnalyticEvents } from "../../../Constants"; import { PaymentGateways } from "../../../_bundle/Module505"; import { HTTP } from "../../../_bundle/sendRequest"; import InvalidGooglePlayPurchase from "../../billing/errors/InvalidGooglePlayPurchase"; import { BillingError } from "../../../errors/index"; import { isSpendingLimitError, showSpendingLimitReachedAlert } from "../../parent_tools/native/showSpendingLimitReachedAlert"; import { intl, t } from "../../../intl/index.native"; import { ErrorCodes } from "../../../errors/BillingError"; import AlertActionCreators from "../../../actions/AlertActionCreators"; import { TrialIdToProductOfferId, DiscountIdToProductOfferId, ProductIds, BOGO_OFFER_ID } from "./ProductIds.android"; import { useStateFromStores } from "../../../_bundle/Module589"; import { usePremiumTrialOffer } from "../hooks/usePremiumTrialOffer.android"; import { usePremiumDiscountOffer } from "../hooks/usePremiumDiscountOffer.native"; import { useIsEligibleForBogoOffer } from "./hooks/useIsEligibleForBogoOffer.android"; import { getBasePurchaseFlowAnalyticsFields } from "./PremiumAnalyticsUtils"; import { trackPaymentFlowStartedAnalyticsAndCTP } from "../../experiments/trigger_points/PaymentFlowStartedTriggerPoint"; import GPlayManager_android from "../../gplay/native/GPlayManager.android"; import { convertToMinorCurrencyUnits } from "../../../_bundle/convertToMajorCurrencyUnits"; import { captureBillingException } from "../../../utils/BillingUtils"; import { updatePendingDowngrade, subscribe, purchase } from "../../../actions/native/GPlayActionCreators"; import AnalyticsUtils from "../../../utils/AnalyticsUtils"; import { HermesBuiltin } from "../../../_hermes/prelude"; function $mk117979($env) { return function getOfferId(a0, a1, a2, a3, a4) { const offerIds = a4?.offerIds; if (offerIds != null) { if (a2 != null) { const r34 = TrialIdToProductOfferId[a2.trial_id]; return r34 == null ? void 0 : r34[a0]; } if (a3 != null) { const r25 = DiscountIdToProductOfferId[a3.discountId]; return r25 == null ? void 0 : r25[a0]; } } return a1 ? a0 === ProductIds.PREMIUM_TIER_2_MONTHLY ? BOGO_OFFER_ID : null : null; }; } function $mk117980($env) { return function showPurchaseErrorModal(a0) { const r17 = a0 instanceof BillingError ? a0 : new BillingError(a0); if (isSpendingLimitError(r17)) { showSpendingLimitReachedAlert(); } else { const r33 = intl.string(t.LFFx5G); const body = r17.code !== ErrorCodes.UNKNOWN && r17.code !== -1 && r17.message != null ? r17.message : r33; AlertActionCreators.show({ title: intl.string(t["U+H+kd"]), body, isDismissable: true }); } }; } let _excluded; let env3969 = {}; const validatePurchase = async function validatePurchase(c25765_0) { let c25765_3; let c25765_4 = 0; let c29706_0, c29706_1, c29706_2, c29706_3, c29706_4, c29706_5, c29706_6; try { c29706_0 = void 0; c29706_1 = void 0; c29706_2 = void 0; c29706_3 = void 0; c29706_4 = void 0; c29706_5 = void 0; c29706_0 = c25765_0.productId; c29706_1 = c25765_0.premiumSubscription; c29706_2 = c25765_0.offerId; c29706_3 = c25765_0.currency; c29706_4 = c25765_0.price; c29706_5 = c25765_0.isGift; await void 0; c25765_4 = 1; await HTTP.post({ url: Endpoints.GOOGLE_PLAY_VALIDATE_PURCHASE, body: { product_id: c29706_0, offer_id: c29706_2, subscription_id: c29706_1?.id, currency: c29706_3, price: c29706_4, is_gift: c29706_5 }, rejectWithError: false }); c25765_4 = 0; } catch ($e) { const r30 = $e; let r8 = r30; c25765_3 = r30; if (c25765_4 !== 0) { while (true) { try { const r96 = c25765_3; c25765_4 = 0; c29706_6 = r96; throw new InvalidGooglePlayPurchase(c29706_6); } catch (r92) { r8 = r92; c25765_3 = r92; if (c25765_4 === 0) { break; } } } } throw r8; } }; _excluded = ["succeededOnlyFields"]; export function useHandlePremiumPurchase() { let env15616 = { $parent: env3969 }; const stateFromStores = useStateFromStores([SubscriptionStore], () => SubscriptionStore.getPremiumTypeSubscription()); env15616[0] = stateFromStores; const premiumTrialOffer = usePremiumTrialOffer(); env15616[1] = premiumTrialOffer; const premiumDiscountOffer = usePremiumDiscountOffer(); env15616[2] = premiumDiscountOffer; const isEligibleForBogoOffer = useIsEligibleForBogoOffer(); env15616[3] = isEligibleForBogoOffer; const r3 = stateFromStores != null; env15616[4] = r3; const id = stateFromStores?.id; env15616[5] = id; const paymentGatewayPlanId = stateFromStores?.paymentGatewayPlanId; env15616[6] = paymentGatewayPlanId; const paymentGatewaySubscriptionId = stateFromStores?.paymentGatewaySubscriptionId; env15616[7] = paymentGatewaySubscriptionId; let c15617_0 = async (c29707_0) => { let r22, allowPlanChange, isOneTimePurchase; let c29707_1, c29707_2, c29707_3, c29707_4; let c29707_5 = 0; const r16 = void 0; const r15 = env3969; L45: { try { let env31411; L16: { L13: { L14: { L10: { c29707_3 = r16; const r54 = env31411 = { $parent: r15 }; c29707_2 = r54; env31411[0] = void 0; env31411[1] = void 0; env31411[2] = void 0; env31411[3] = void 0; env31411[4] = void 0; env31411[5] = void 0; env31411[6] = void 0; env31411[7] = void 0; env31411[8] = void 0; env31411[9] = void 0; env31411[10] = void 0; env31411[11] = void 0; env31411[12] = void 0; r22 = c29707_0; env31411[0] = r22.productId; env31411[1] = r22.skuId; env31411[2] = r22.analyticsLoadId; env31411[3] = r22.analyticsLocation; env31411[4] = r22.analyticsLocations; env31411[5] = r22.analyticsData; const isGift = r22.isGift; if (isGift !== void 0) { env31411[6] = isGift; isOneTimePurchase = r22.isOneTimePurchase; if (isOneTimePurchase !== void 0) { break L10; } } else { env31411[6] = false; isOneTimePurchase = r22.isOneTimePurchase; if (isOneTimePurchase !== void 0) { break L10; } } env31411[7] = false; allowPlanChange = r22.allowPlanChange; if (allowPlanChange !== void 0) { break L13; } break L14; } env31411[7] = isOneTimePurchase; allowPlanChange = r22.allowPlanChange; if (allowPlanChange !== void 0) { break L13; } } env31411[8] = true; env31411[9] = r22.applicationId; env31411[10] = r22.giftInfoOptions; env31411[11] = r22.onPurchaseComplete; env31411[12] = r22.onPurchaseError; env31411[13] = void 0; env31411[14] = void 0; env31411[15] = void 0; env31411[16] = void 0; env31411[17] = void 0; env31411[18] = void 0; env31411[19] = void 0; env31411[20] = void 0; env31411[21] = void 0; break L16; } env31411[8] = allowPlanChange; env31411[9] = r22.applicationId; env31411[10] = r22.giftInfoOptions; env31411[11] = r22.onPurchaseComplete; env31411[12] = r22.onPurchaseError; env31411[13] = void 0; env31411[14] = void 0; env31411[15] = void 0; env31411[16] = void 0; env31411[17] = void 0; env31411[18] = void 0; env31411[19] = void 0; env31411[20] = void 0; env31411[21] = void 0; } await void 0; env31411[13] = AuthenticationStore.getId(); env31411[14] = IAPStore_android.getProduct(env31411[0]); env31411[15] = getBasePurchaseFlowAnalyticsFields({ isGift: env31411[6], analyticsLoadId: env31411[2], analyticsLocation: env31411[3], analyticsLocations: env31411[4] }); const r116 = env31411[5]; c29707_1 = r116; if (r116 == null) { c29707_1 = {}; } env31411[16] = c29707_1; env31411[17] = env31411[16].succeededOnlyFields; env31411[18] = (0, _objectWithoutProperties)(env31411[16], _excluded); const r127 = { ...env31411[15], subscription_plan_gateway_plan_id: env31411[0], sku_id: env31411[1], price: env31411[14]?.price, regular_price: env31411[14]?.price }; const r140 = env31411[14]; const currency = r140 == null ? void 0 : r140.currencyCode.toLowerCase(); L31: { const r144 = c29707_3; r127.currency = currency; r127.application_id = env31411[9]; HermesBuiltin.copyDataProperties(r127, env31411[18]); env31411[19] = r127; setGPlayAnalytics(env31411[0], { ...env31411[19], succeededOnlyFields: env31411[17] }); const r156 = env31411[0]; const r157 = r144.$parent; const r158 = r157[3]; const r31 = r157[1]; const r30 = r157[2]; const r29 = env31411[14]; env31411[20] = $mk117979(env3969)(r156, r158, r31, r30, r29); trackPaymentFlowStartedAnalyticsAndCTP({ ...env31411[19], payment_gateway: PaymentGateways.GOOGLE }); c29707_5 = 1; if (!env31411[6] && !env31411[7]) { if (c29707_3.$parent[4] && !env31411[8]) { break L31; } if (c29707_3.$parent[6] != null && c29707_3.$parent[7] != null && c29707_3.$parent[5] != null) { const r208 = c29707_3; const r215 = env31411[0]; const r216 = r208.$parent; updatePendingDowngrade(r215, r216[6], r216[7], r216[5]); } await (0, validatePurchase)({ productId: env31411[0], premiumSubscription: c29707_3.$parent[0], offerId: env31411[20] }); const r244 = c29707_3; const r251 = env31411[0]; const r252 = env31411[13]; const r253 = r244.$parent; await subscribe(r251, r252, r253[6], r253[7], env31411[20]); } else { if (env31411[6] && env31411[10] != null) { if (GPlayManager_android.giftInfoOptionsCache != null && GPlayManager_android.giftInfoOptionsCache[env31411[0]] != null) { delete GPlayManager_android.giftInfoOptionsCache[env31411[0]]; } GPlayManager_android.giftInfoOptionsCache[env31411[0]] = { ...env31411[10] }; } env31411[21] = null; if (env31411[14] != null) { c29707_5 = 2; env31411[21] = convertToMinorCurrencyUnits(env31411[14].price / 100, env31411[14].currencyCode); c29707_5 = 1; } const r333 = c29707_3; const r340 = env31411[14]; const r341 = r340 == null; let currency2 = void 0; if (!r341) { const currencyCode = r340.currencyCode; currency2 = currencyCode == null ? void 0 : currencyCode.toLowerCase(); } await validatePurchase({ productId: env31411[0], premiumSubscription: r333.$parent[0], offerId: null, currency: currency2, price: env31411[21], isGift: env31411[6] }); await purchase(env31411[0], env31411[13]); } } const r185 = env31411[11]; if (r185 != null) { r185({ paymentGateway: PaymentGateways.GOOGLE }); } c29707_5 = 0; } catch ($e) { const r52 = $e; let r7 = r52; c29707_4 = r52; let r53 = c29707_5; if (r53 !== 0) { while (true) { if (r53 === 1) { try { const r522 = c29707_4; c29707_5 = 0; env31411[23] = r522; AnalyticsUtils.track(AnalyticEvents.PAYMENT_FLOW_FAILED, { ...env31411[19], payment_gateway: PaymentGateways.GOOGLE, error_message: env31411[23].message }); const r541 = env31411[12]; if (r541 != null) { r541(); } captureBillingException(env31411[23]); const r552 = env31411[23]; $mk117980(env3969)(r552); if (!(env31411[23] instanceof InvalidGooglePlayPurchase)) { break L45; } throw env31411[23]; } catch (r519) { r7 = r519; c29707_4 = r519; r53 = c29707_5; if (r53 === 0) { break; } } } else { try { const r425 = c29707_4; c29707_5 = 1; env31411[22] = r425; captureBillingException(env31411[22]); const r436 = c29707_3; const r443 = env31411[14]; const r444 = r443 == null; let currency3 = void 0; if (!r444) { const currencyCode2 = r443.currencyCode; currency3 = currencyCode2 == null ? void 0 : currencyCode2.toLowerCase(); } await validatePurchase({ productId: env31411[0], premiumSubscription: r436.$parent[0], offerId: null, currency: currency3, price: env31411[21], isGift: env31411[6] }); await purchase(env31411[0], env31411[13]); const r509 = env31411[11]; if (r509 != null) { r509({ paymentGateway: PaymentGateways.GOOGLE }); } c29707_5 = 0; break L45; } catch (r422) { r7 = r422; c29707_4 = r422; r53 = c29707_5; if (r53 === 0) { break; } } } } } throw r7; } } }; return useCallback(function() { return c15617_0.apply(this, arguments); }, [r3, paymentGatewayPlanId, paymentGatewaySubscriptionId, id, premiumTrialOffer, premiumDiscountOffer, stateFromStores, isEligibleForBogoOffer]); }