285 lines
11 KiB
TypeScript
285 lines
11 KiB
TypeScript
// Metro module 6666 (f6667).
|
|
import _slicedToArray from "../../../../_bundle/_slicedToArray";
|
|
import { useEffect, useCallback, useMemo } from "react";
|
|
import GenericIAPStore from "../../../billing/native/GenericIAPStore";
|
|
import SubscriptionPlanStore from "../../../../stores/billing/SubscriptionPlanStore";
|
|
import SubscriptionStore from "../../../../stores/billing/SubscriptionStore";
|
|
import IAPStore_android from "../../../../stores/native/IAPStore.android";
|
|
import { PurchaseTypeToAnalyticsPaymentType, PurchaseTypes, SubscriptionTypes } from "../../../../Constants";
|
|
import Logger from "../../../debug/Logger";
|
|
import { useStateFromStoresArray, useStateFromStores } from "../../../../_bundle/Module589";
|
|
import BillingActionCreators, { createGenericSubscription, cancelGenericSubscription, resubscribeGenericSubscription } from "../../../../actions/native/BillingActionCreators";
|
|
import useTimeout from "../../../../hooks/useTimeout";
|
|
import useCreateSubscriptionParams from "../../../billing/native/subscription/useCreateSubscriptionParams";
|
|
import useInitialValue from "../../../../hooks/useInitialValue";
|
|
import { getNewAnalyticsLoadId } from "../../../../utils/AnalyticsUtils";
|
|
import { trackPaymentFlowStartedAnalyticsAndCTP } from "../../../experiments/trigger_points/PaymentFlowStartedTriggerPoint";
|
|
import { ProductIds } from "../../../premium/native/ProductIds.android";
|
|
import Module38 from "../../../../_bundle/Module38";
|
|
import { fetchSubscriptions } from "../../../billing/actions/BillingActionCreators";
|
|
import useCancelSubscriptionParams from "../../../billing/native/subscription/useCancelSubscriptionParams";
|
|
import useResubscribeSubscriptionParams from "../../../billing/native/subscription/useResubscribeSubscriptionParams";
|
|
function $mk78883($env) {
|
|
return () => {
|
|
if (!$env[1]) {
|
|
const r4 = $env.$parent;
|
|
(0, r4[1])(r4[2][10]).loadProducts();
|
|
}
|
|
};
|
|
}
|
|
function $mk78884($env) {
|
|
return () => {
|
|
const r7 = $env;
|
|
if (!(r7[4] || $env.$parent[15])) {
|
|
const r11 = $env.$parent;
|
|
r11[15] = true;
|
|
const r6 = (0, r11[0])(r11[2][12]);
|
|
const r10 = r7[3];
|
|
let loadedProducts = r10 == null ? void 0 : r10.map((item) => item.identifier);
|
|
if (loadedProducts == null) {
|
|
loadedProducts = [];
|
|
}
|
|
r6.captureBillingMessage("useNativeIAPPayments failed to load required context", {
|
|
tags: {
|
|
alertPriority: "0"
|
|
},
|
|
extra: {
|
|
loadedProducts,
|
|
connected: r7[0],
|
|
genericProductsLoaded: r7[1],
|
|
storeFront: r7[2]
|
|
}
|
|
});
|
|
}
|
|
};
|
|
}
|
|
let c4268_13, c4268_14, c4268_15;
|
|
let $mk78882 = function() {
|
|
return () => [GenericIAPStore.isGenericIapConnected(), GenericIAPStore.genericProductsLoaded(), GenericIAPStore.getStoreFront(), IAPStore_android.getProducts()];
|
|
};
|
|
let env4268 = {};
|
|
export function useNativeIAPPayments() {
|
|
let env15829;
|
|
const r3 = env15829 = {
|
|
$parent: env4268
|
|
};
|
|
const r18 = _slicedToArray(useStateFromStoresArray([GenericIAPStore, IAPStore_android], $mk78882()), 4);
|
|
let nativePaymentsConnected = r18[0];
|
|
env15829[0] = nativePaymentsConnected;
|
|
const r20 = r18[1];
|
|
env15829[1] = r20;
|
|
const storeFront = r18[2];
|
|
env15829[2] = storeFront;
|
|
env15829[3] = r18[3];
|
|
if (nativePaymentsConnected) {
|
|
nativePaymentsConnected = r20;
|
|
}
|
|
if (nativePaymentsConnected) {
|
|
nativePaymentsConnected = storeFront != null;
|
|
}
|
|
env15829[4] = nativePaymentsConnected;
|
|
useEffect($mk78883(r3), [r20]);
|
|
useTimeout($mk78884(r3), 5000);
|
|
return {
|
|
nativePaymentsConnected,
|
|
storeFront
|
|
};
|
|
}
|
|
export function useCreateSubscription({ planId, skuId, applicationId, analyticsLocation }) {
|
|
let c15830_5, load_id, callback;
|
|
let env15831;
|
|
c15830_5 = void 0;
|
|
load_id = void 0;
|
|
callback = void 0;
|
|
const r10 = env15831 = {
|
|
$parent: env4268
|
|
};
|
|
env15831[0] = void 0;
|
|
env15831[1] = void 0;
|
|
env15831[2] = void 0;
|
|
env15831[3] = void 0;
|
|
env15831[4] = void 0;
|
|
const r25 = _slicedToArray(useStateFromStoresArray([GenericIAPStore, IAPStore_android], $mk78882()), 4);
|
|
let nativePaymentsConnected = r25[0];
|
|
env15831[0] = nativePaymentsConnected;
|
|
const r27 = r25[1];
|
|
env15831[1] = r27;
|
|
const r28 = r25[2];
|
|
env15831[2] = r28;
|
|
env15831[3] = r25[3];
|
|
if (nativePaymentsConnected) {
|
|
nativePaymentsConnected = r27;
|
|
}
|
|
if (nativePaymentsConnected) {
|
|
nativePaymentsConnected = r28 != null;
|
|
}
|
|
env15831[4] = nativePaymentsConnected;
|
|
useEffect($mk78883(r10), [r27]);
|
|
useTimeout($mk78884(r10), 5000);
|
|
let c15830_4 = nativePaymentsConnected;
|
|
const createSubscriptionParams = useCreateSubscriptionParams(useStateFromStores([SubscriptionPlanStore], () => SubscriptionPlanStore.get(planId), [planId]), r28);
|
|
c15830_5 = createSubscriptionParams;
|
|
load_id = useInitialValue(() => getNewAnalyticsLoadId());
|
|
callback = useCallback(() => {
|
|
trackPaymentFlowStartedAnalyticsAndCTP({
|
|
load_id,
|
|
payment_type: PurchaseTypeToAnalyticsPaymentType[PurchaseTypes.SUBSCRIPTION],
|
|
subscription_plan_gateway_plan_id: ProductIds.GENERIC_SUBSCRIPTION,
|
|
subscription_type: SubscriptionTypes.GUILD,
|
|
is_gift: false,
|
|
location: analyticsLocation,
|
|
application_id: applicationId,
|
|
subscription_plan_id: planId,
|
|
sku_id: skuId
|
|
});
|
|
}, [load_id, analyticsLocation, applicationId, planId, skuId]);
|
|
return {
|
|
createSubscription: useCallback(async () => {
|
|
let c25942_3 = 0;
|
|
let r10 = "error consuming pending purchases but we'll try to let user purchase";
|
|
L13: {
|
|
try {
|
|
Module38(c15830_4, "cannot connect to IAP API");
|
|
Module38(c15830_5 != null, "plan not found");
|
|
c25942_3 = 1;
|
|
await BillingActionCreators.restoreAndApplyPurchases();
|
|
r10 = "error consuming pending purchases but we'll try to let user purchase";
|
|
c25942_3 = 0;
|
|
(0, callback)();
|
|
await createGenericSubscription(c15830_5);
|
|
r10 = "error consuming pending purchases but we'll try to let user purchase";
|
|
await fetchSubscriptions();
|
|
r10 = "error consuming pending purchases but we'll try to let user purchase";
|
|
} catch ($e) {
|
|
let r7 = $e;
|
|
if (c25942_3 !== 0) {
|
|
while (true) {
|
|
try {
|
|
c25942_3 = 0;
|
|
c4268_13.error(r10);
|
|
(0, callback)();
|
|
await createGenericSubscription(c15830_5);
|
|
r10 = "error consuming pending purchases but we'll try to let user purchase";
|
|
await fetchSubscriptions();
|
|
r10 = "error consuming pending purchases but we'll try to let user purchase";
|
|
break L13;
|
|
} catch ($e) {
|
|
r7 = $e;
|
|
if (c25942_3 === 0) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
throw r7;
|
|
}
|
|
}
|
|
}, [createSubscriptionParams, nativePaymentsConnected, callback]),
|
|
nativePaymentsConnected
|
|
};
|
|
}
|
|
export function useCancelSubscription(a0, a1) {
|
|
let memo, c15832_6;
|
|
let env15833;
|
|
const r11 = env15833 = {
|
|
$parent: env4268
|
|
};
|
|
const r22 = _slicedToArray(useStateFromStoresArray([GenericIAPStore, IAPStore_android], $mk78882()), 4);
|
|
let nativePaymentsConnected = r22[0];
|
|
env15833[0] = nativePaymentsConnected;
|
|
const r24 = r22[1];
|
|
env15833[1] = r24;
|
|
const r14 = r22[2];
|
|
env15833[2] = r14;
|
|
env15833[3] = r22[3];
|
|
if (nativePaymentsConnected) {
|
|
nativePaymentsConnected = r24;
|
|
}
|
|
if (nativePaymentsConnected) {
|
|
nativePaymentsConnected = r14 != null;
|
|
}
|
|
env15833[4] = nativePaymentsConnected;
|
|
useEffect($mk78883(r11), [r24]);
|
|
useTimeout($mk78884(r11), 5000);
|
|
let c15832_2 = nativePaymentsConnected;
|
|
let c15832_3 = r14;
|
|
const stateFromStores = useStateFromStores([SubscriptionStore], () => SubscriptionStore.getSubscriptionById(a0), [a0]);
|
|
memo = useMemo(() => stateFromStores != null && c15832_3 != null && stateFromStores.currency === c15832_3.currency, [r14, stateFromStores]);
|
|
const cancelSubscriptionParams = useCancelSubscriptionParams(a0);
|
|
c15832_6 = cancelSubscriptionParams;
|
|
return {
|
|
cancelSubscription: useCallback(async () => {
|
|
let c25943_1;
|
|
c25943_1 = void 0;
|
|
Module38(memo, "Cannot update subscription");
|
|
Module38(c15832_2, "Cannot connect to IAP API");
|
|
Module38(c15832_6 != null, "Subscription not found");
|
|
let c29809_0 = await cancelGenericSubscription(c15832_6.requestIdentifier, c15832_6.subscriptionId, a1);
|
|
await fetchSubscriptions();
|
|
return c29809_0;
|
|
}, [memo, cancelSubscriptionParams, nativePaymentsConnected, a1]),
|
|
nativePaymentsConnected
|
|
};
|
|
}
|
|
export function useResubscribeSubscription(a0) {
|
|
let memo2, c15834_5;
|
|
let env15835;
|
|
const r9 = env15835 = {
|
|
$parent: env4268
|
|
};
|
|
const r21 = _slicedToArray(useStateFromStoresArray([GenericIAPStore, IAPStore_android], $mk78882()), 4);
|
|
let nativePaymentsConnected = r21[0];
|
|
env15835[0] = nativePaymentsConnected;
|
|
const r23 = r21[1];
|
|
env15835[1] = r23;
|
|
const r24 = r21[2];
|
|
env15835[2] = r24;
|
|
env15835[3] = r21[3];
|
|
if (nativePaymentsConnected) {
|
|
nativePaymentsConnected = r23;
|
|
}
|
|
if (nativePaymentsConnected) {
|
|
nativePaymentsConnected = r24 != null;
|
|
}
|
|
env15835[4] = nativePaymentsConnected;
|
|
useEffect($mk78883(r9), [r23]);
|
|
useTimeout($mk78884(r9), 5000);
|
|
let c15834_1 = nativePaymentsConnected;
|
|
let c15834_2 = r24;
|
|
const stateFromStores2 = useStateFromStores([SubscriptionStore], () => SubscriptionStore.getSubscriptionById(a0), [a0]);
|
|
memo2 = useMemo(() => stateFromStores2 != null && c15834_2 != null && stateFromStores2.currency === c15834_2.currency, [r24, stateFromStores2]);
|
|
const resubscribeSubscriptionParams = useResubscribeSubscriptionParams(a0);
|
|
c15834_5 = resubscribeSubscriptionParams;
|
|
return {
|
|
resubscribeSubscription: useCallback(async () => {
|
|
let c25944_1;
|
|
c25944_1 = void 0;
|
|
Module38(memo2, "Cannot update subscription");
|
|
Module38(c15834_1, "Cannot connect to IAP API");
|
|
Module38(c15834_5 != null, "Subscription not found");
|
|
Module38(stateFromStores2 != null, "Subscription not found");
|
|
let c29810_0 = await resubscribeGenericSubscription(c15834_5, stateFromStores2.isACOM);
|
|
await fetchSubscriptions();
|
|
return c29810_0;
|
|
}, [memo2, nativePaymentsConnected, resubscribeSubscriptionParams, stateFromStores2]),
|
|
nativePaymentsConnected
|
|
};
|
|
}
|
|
export function useGoogleSkuIds() {
|
|
return c4268_14;
|
|
}
|
|
c4268_13 = new Logger("NativePaymentHooks.ios.tsx");
|
|
c4268_14 = {
|
|
isFetchingGoogleSkus: false,
|
|
fetchError: null
|
|
};
|
|
c4268_15 = false;
|
|
const r48 = {
|
|
useNativeIAPPayments,
|
|
useGoogleSkuIds,
|
|
useCreateSubscription,
|
|
useCancelSubscription,
|
|
useResubscribeSubscription
|
|
};
|
|
export default r48;
|