Files
discord-decomp/modules/gplay/native/GPlayManager.android.tsx
T
2026-11-01 12:12:55 +02:00

606 lines
21 KiB
TypeScript

// Metro module 6298 (f6299).
import _objectWithoutProperties from "../../../_bundle/_objectWithoutProperties";
import * as _Module17 from "react-native";
import GiftPromotionStore from "../../premium/gifting/GiftPromotionStore";
import { setPaymentSuccess, showOldPaymentFlowSuccess } from "../../premium/native/PremiumPlanPurchasedStore";
import AuthenticationStore from "../../../stores/AuthenticationStore";
import SubscriptionStore from "../../../stores/billing/SubscriptionStore";
import IAPStore_android from "../../../stores/native/IAPStore.android";
import { useGPlayAnalyticsStore } from "./GPlayAnalyticsStore";
import { GPlayConnectionState, GPlayPurchaseState, GPlayDowngradeCommand } from "./Constants";
import { PaymentGateways, AnalyticEvents, AppStates } from "../../../Constants";
import { OrderStatus } from "../../payments/PaymentConstants";
import { SubscriptionPlanInfo } from "../../premium/PremiumConstants";
import Logger from "../../debug/Logger";
import Dispatcher from "../../../Dispatcher";
import { loadUserCountry, loadSkus, verifyPurchase, sendPaymentCompleteAnalytics, downgradeSubscription } from "../../../actions/native/GPlayActionCreators";
import MurmurHashV3 from "../../../_bundle/MurmurHashV3";
import { IAPProductIds, getPlanIdForGift, SubscriptionProductIds } from "../../premium/native/ProductIds.android";
import Module3771 from "../../../_bundle/Module3771";
import { DRAFT_ORDER_LOOKBACK_DAYS, getOrders, markOrderAsSigningInProgress } from "../../payments/native/OrderActionCreators";
import { captureBillingException } from "../../../utils/BillingUtils";
import { fetchSubscriptions } from "../../billing/actions/BillingActionCreators";
import AnalyticsUtils from "../../../utils/AnalyticsUtils";
import AlertActionCreators from "../../../actions/native/AlertActionCreators";
import { intl, t } from "../../../intl/index.native";
function $mk114920($env) {
return function executePendingDowngrade() {
return $env[36].apply(this, arguments);
};
}
function $mk114921($env) {
return () => {
AlertActionCreators.openLazy({
importer: $mk117981($env)
});
};
}
function $mk117981($env) {
return () => import("../../../components_native/premium/PremiumActivatedAlert").then($mk118762($env));
}
function $mk118762($env) {
return (a0) => {
let env32122 = {
$parent: $env
};
env32122[0] = a0.default;
return (a0) => {
const r1 = env32122.$parent.$parent;
let env32166 = {
$parent: r1
};
env32166[0] = a0;
return r1[21](env32122[0], {
...a0,
subscription: env32122.$parent[0],
onClose: () => {
env32166[0].onClose();
const r4 = env32166.$parent;
const r3 = r4[1];
const r7 = r4[2];
r3(r7[29]).popWithKey((0, r4[0])(r7[30]).PREMIUM_KEY);
}
});
};
};
}
let handlePurchaseStateUpdated, handlePurchaseUpdated, handleDowngradeCommand, clearPendingDowngrade, fetchAndAlertActiveSubscription, handleAppStateUpdated, _excluded, c4013_22, BillingManager, c4013_24, c4013_25;
let env4013 = {};
const handleConnectionStateUpdated = function handleConnectionStateUpdated({ connectionState }) {
Dispatcher.dispatch({
type: "GPLAY_UPDATE_CONNECTION_STATE",
connectionState
});
if (connectionState === GPlayConnectionState.CONNECTED) {
loadUserCountry().finally(() => loadSkus());
}
};
handlePurchaseStateUpdated = function handlePurchaseStateUpdated(a0) {
Dispatcher.dispatch({
type: "GPLAY_UPDATE_PURCHASE_STATE",
billingResult: a0.billingResult,
isActivePurchase: a0.isActivePurchase
});
};
handlePurchaseUpdated = async function handlePurchaseUpdated(c25768_0) {
let c25768_1, c25768_4;
let c25768_5 = 0;
let c29708_0, c29708_1, c29708_2, c29708_3, c29708_4, c29708_5, c29708_6, c29708_7, c29708_8, c29708_9, c29708_10, c29708_11, c29708_13, c29708_12;
let r18 = "[handlePurchaseUpdated] Error verifying purchase ";
let r17 = "[handlePurchaseUpdated] Failed to find or sign order: ";
L75: {
L57: {
try {
c29708_0 = void 0;
c29708_0 = c25768_0.purchase;
c29708_1 = void 0;
c29708_2 = void 0;
c29708_3 = void 0;
c29708_4 = void 0;
c29708_5 = void 0;
c29708_6 = void 0;
c29708_7 = void 0;
c29708_8 = void 0;
c29708_9 = void 0;
c29708_10 = void 0;
c29708_11 = void 0;
await void 0;
r18 = "[handlePurchaseUpdated] Error verifying purchase ";
r17 = "[handlePurchaseUpdated] Failed to find or sign order: ";
if (IAPStore_android.isPurchasingProduct(c29708_0.productId)) {
break L75;
}
c29708_1 = useGPlayAnalyticsStore.getState().analyticsByProductId[c29708_0.productId];
c29708_2 = c4013_25[c29708_0.productId];
c29708_3 = MurmurHashV3.v3(c29708_0.purchaseToken);
if (c29708_2 != null) {
Dispatcher.dispatch({
type: "GIFT_PROMOTION_GIFT_OPTIONS_CACHE_ACTION",
key: c29708_3,
giftOptions: {
...c29708_2
}
});
} else {
c29708_2 = GiftPromotionStore.getGiftOptionsForKey(c29708_3);
}
c25768_5 = 2;
Dispatcher.dispatch({
type: "GPLAY_VERIFICATION_START",
productId: c29708_0.productId
});
if (IAPProductIds.includes(c29708_0.productId)) {
c25768_5 = 3;
c29708_4 = Module3771().subtract(DRAFT_ORDER_LOOKBACK_DAYS, "days").toISOString();
c29708_5 = getPlanIdForGift(c29708_0.productId);
c29708_6 = c29708_5 != null ? SubscriptionPlanInfo[c29708_5]?.skuId : void 0;
const orders = await getOrders({
status: OrderStatus.DRAFT,
createdAfter: c29708_4,
skuId: c29708_6,
paymentGateway: PaymentGateways.GOOGLE,
isGift: true
});
r18 = "[handlePurchaseUpdated] Error verifying purchase ";
r17 = "[handlePurchaseUpdated] Failed to find or sign order: ";
const r489 = "[handlePurchaseUpdated] Signing order from backend query";
const r491 = "[handlePurchaseUpdated] No draft order found for signing";
c29708_7 = orders;
if (c29708_7.length > 0) {
c29708_8 = c29708_7[0].id;
c4013_22.info(r489, {
orderId: c29708_8,
productId: c29708_0.productId,
skuId: c29708_6
});
await markOrderAsSigningInProgress(c29708_8);
r18 = "[handlePurchaseUpdated] Error verifying purchase ";
r17 = "[handlePurchaseUpdated] Failed to find or sign order: ";
c25768_5 = 2;
} else {
c4013_22.warn(r491, {
productId: c29708_0.productId,
skuId: c29708_6
});
c25768_5 = 2;
}
}
if (c29708_0.purchaseState === GPlayPurchaseState.PENDING) {
c25768_5 = 0;
Dispatcher.dispatch({
type: "GPLAY_VERIFICATION_END",
productId: c29708_0.productId
});
break L57;
}
const r224 = await verifyPurchase(c29708_0, c29708_2);
r18 = "[handlePurchaseUpdated] Error verifying purchase ";
r17 = "[handlePurchaseUpdated] Failed to find or sign order: ";
const r246 = "[handlePurchaseUpdated] One Time Purchase verified and consumed: ";
c29708_9 = r224;
if (c29708_9 != null && c29708_2 != null) {
Dispatcher.dispatch({
type: "GIFT_PROMOTION_GIFT_OPTIONS_CLEAR_CACHE_ACTION",
key: c29708_3
});
delete c4013_25[c29708_0.productId];
}
if (c29708_9 != null) {
Dispatcher.dispatch({
type: "GPLAY_PURCHASE_VERIFIED",
productId: c29708_0.productId
});
}
L36: {
if (c29708_9 != null) {
if (!SubscriptionProductIds.includes(c29708_0.productId)) {
sendPaymentCompleteAnalytics(c29708_0);
c4013_22.info(HermesInternal.concat.call(r246, c29708_0.productId));
c25768_5 = 1;
break L36;
}
}
if (c29708_9 != null && c29708_9.pendingDowngrade != null) {
Dispatcher.dispatch({
type: "GPLAY_UPDATE_PENDING_DOWNGRADE",
pendingDowngrade: c29708_9.pendingDowngrade
});
await fetchSubscriptions();
r18 = "[handlePurchaseUpdated] Error verifying purchase ";
r17 = "[handlePurchaseUpdated] Failed to find or sign order: ";
c25768_5 = 1;
} else if (c29708_0.isActive) {
await (0, fetchAndAlertActiveSubscription)();
r18 = "[handlePurchaseUpdated] Error verifying purchase ";
r17 = "[handlePurchaseUpdated] Failed to find or sign order: ";
c25768_5 = 1;
} else {
await fetchSubscriptions();
r18 = "[handlePurchaseUpdated] Error verifying purchase ";
r17 = "[handlePurchaseUpdated] Failed to find or sign order: ";
c25768_5 = 1;
}
}
c25768_5 = 0;
Dispatcher.dispatch({
type: "GPLAY_VERIFICATION_END",
productId: c29708_0.productId
});
break L75;
} catch ($e) {
const r66 = $e;
let r8 = r66;
c25768_4 = r66;
let r67 = c25768_5;
if (r67 !== 0) {
while (true) {
if (r67 === 1) {
try {
const r925 = c25768_4;
c25768_5 = 0;
Dispatcher.dispatch({
type: "GPLAY_VERIFICATION_END",
productId: c29708_0.productId
});
throw r925;
} catch (r922) {
r8 = r922;
c25768_4 = r922;
r67 = c25768_5;
if (r67 === 0) {
break;
}
}
} else if (r67 === 2) {
try {
const r847 = c25768_4;
c25768_5 = 1;
c29708_13 = r847;
captureBillingException(c29708_13, {
tags: {
productId: c29708_0.productId
}
});
c4013_22.error(HermesInternal.concat.call(r18, c29708_0.productId, ": ", c29708_13.message));
Dispatcher.dispatch({
type: "GPLAY_PURCHASE_VERIFICATION_FAILED",
productId: c29708_0.productId
});
const r879 = c29708_1;
c25768_1 = r879;
if (r879 == null) {
c25768_1 = {};
}
c29708_10 = c25768_1;
c29708_10.succeededOnlyFields;
c29708_11 = (0, _objectWithoutProperties)(c29708_10, _excluded);
AnalyticsUtils.track(AnalyticEvents.GPLAY_PURCHASE_FAILED, {
...c29708_11,
location: "handlePurchaseUpdated",
product_id: c29708_0.productId,
purchase_token: c29708_0.purchaseToken,
error: c29708_13.message
});
c25768_5 = 0;
Dispatcher.dispatch({
type: "GPLAY_VERIFICATION_END",
productId: c29708_0.productId
});
break L75;
} catch (r844) {
r8 = r844;
c25768_4 = r844;
r67 = c25768_5;
if (r67 === 0) {
break;
}
}
} else {
try {
const r566 = c25768_4;
c25768_5 = 2;
c29708_12 = r566;
captureBillingException(c29708_12, {
tags: {
source: "GPlayManager_handlePurchaseUpdated_sign"
},
extra: {
productId: c29708_0.productId
}
});
c4013_22.error(HermesInternal.concat.call(r17, c29708_12.message));
if (c29708_0.purchaseState === GPlayPurchaseState.PENDING) {
c25768_5 = 0;
Dispatcher.dispatch({
type: "GPLAY_VERIFICATION_END",
productId: c29708_0.productId
});
break L57;
}
const r619 = await verifyPurchase(c29708_0, c29708_2);
r18 = "[handlePurchaseUpdated] Error verifying purchase ";
r17 = "[handlePurchaseUpdated] Failed to find or sign order: ";
const r641 = "[handlePurchaseUpdated] One Time Purchase verified and consumed: ";
c29708_9 = r619;
if (c29708_9 != null && c29708_2 != null) {
Dispatcher.dispatch({
type: "GIFT_PROMOTION_GIFT_OPTIONS_CLEAR_CACHE_ACTION",
key: c29708_3
});
delete c4013_25[c29708_0.productId];
}
if (c29708_9 != null) {
Dispatcher.dispatch({
type: "GPLAY_PURCHASE_VERIFIED",
productId: c29708_0.productId
});
}
L103: {
if (c29708_9 != null) {
if (!SubscriptionProductIds.includes(c29708_0.productId)) {
sendPaymentCompleteAnalytics(c29708_0);
c4013_22.info(HermesInternal.concat.call(r641, c29708_0.productId));
c25768_5 = 1;
break L103;
}
}
if (c29708_9 != null && c29708_9.pendingDowngrade != null) {
Dispatcher.dispatch({
type: "GPLAY_UPDATE_PENDING_DOWNGRADE",
pendingDowngrade: c29708_9.pendingDowngrade
});
await fetchSubscriptions();
r18 = "[handlePurchaseUpdated] Error verifying purchase ";
r17 = "[handlePurchaseUpdated] Failed to find or sign order: ";
c25768_5 = 1;
} else if (c29708_0.isActive) {
await (0, fetchAndAlertActiveSubscription)();
r18 = "[handlePurchaseUpdated] Error verifying purchase ";
r17 = "[handlePurchaseUpdated] Failed to find or sign order: ";
c25768_5 = 1;
} else {
await fetchSubscriptions();
r18 = "[handlePurchaseUpdated] Error verifying purchase ";
r17 = "[handlePurchaseUpdated] Failed to find or sign order: ";
c25768_5 = 1;
}
}
c25768_5 = 0;
Dispatcher.dispatch({
type: "GPLAY_VERIFICATION_END",
productId: c29708_0.productId
});
break L75;
} catch (r563) {
r8 = r563;
c25768_4 = r563;
r67 = c25768_5;
if (r67 === 0) {
break;
}
}
}
}
}
throw r8;
}
}
return void 0;
}
};
handleDowngradeCommand = async function handleDowngradeCommand(c25769_0) {
let c25769_1, c25769_2;
L16: {
let env29709;
const r25 = env4013;
c25769_2 = r25;
const r26 = env29709 = {
$parent: r25
};
c25769_1 = r26;
env29709[0] = void 0;
env29709[0] = c25769_0.downgradeCommand;
await void 0;
const r44 = env29709[0];
if (GPlayDowngradeCommand.EXECUTE === r44) {
await $mk114920(env4013)();
break L16;
}
if (GPlayDowngradeCommand.CLEAR !== r44) {
throw new Error(`Invalid downgrade state ${env29709[0]}`);
}
(0, clearPendingDowngrade)();
return void 0;
}
};
env4013[36] = function _executePendingDowngrade() {
const r8 = async () => {
let c25770_2;
let c25770_3 = 0;
let c29710_0, c29710_1;
L16: {
try {
c29710_0 = void 0;
const pendingDowngrade = IAPStore_android.getPendingDowngrade();
c29710_0 = pendingDowngrade;
if (pendingDowngrade != null) {
c25770_3 = 2;
Dispatcher.dispatch({
type: "GPLAY_UPDATE_IS_DOWNGRADING",
isDowngrading: true
});
await downgradeSubscription(pendingDowngrade);
(0, clearPendingDowngrade)();
await (0, fetchAndAlertActiveSubscription)();
c25770_3 = 1;
c25770_3 = 0;
Dispatcher.dispatch({
type: "GPLAY_UPDATE_IS_DOWNGRADING",
isDowngrading: false
});
break L16;
}
} catch ($e) {
const r32 = $e;
let r7 = r32;
c25770_2 = r32;
let r33 = c25770_3;
if (r33 !== 0) {
while (true) {
if (r33 === 1) {
try {
const r172 = c25770_2;
c25770_3 = 0;
Dispatcher.dispatch({
type: "GPLAY_UPDATE_IS_DOWNGRADING",
isDowngrading: false
});
throw r172;
} catch (r170) {
r7 = r170;
c25770_2 = r170;
r33 = c25770_3;
if (r33 === 0) {
break;
}
}
} else {
try {
const r103 = c25770_2;
c25770_3 = 1;
c29710_1 = r103;
captureBillingException(c29710_1);
AlertActionCreators.show({
title: intl.string(t["U+H+kd"]),
body: intl.string(t.LFFx5G)
});
AnalyticsUtils.track(AnalyticEvents.GPLAY_PURCHASE_FAILED, {
location: "executePendingDowngrade",
product_id: c29710_0?.newSubscriptionSkuId,
purchase_token: c29710_0?.purchaseToken,
error: c29710_1.message
});
c25770_3 = 0;
Dispatcher.dispatch({
type: "GPLAY_UPDATE_IS_DOWNGRADING",
isDowngrading: false
});
break L16;
} catch (r100) {
r7 = r100;
c25770_2 = r100;
r33 = c25770_3;
if (r33 === 0) {
break;
}
}
}
}
}
throw r7;
}
return void 0;
}
};
env4013[36] = r8;
return r8.apply(this, arguments);
};
clearPendingDowngrade = function clearPendingDowngrade() {
Dispatcher.dispatch({
type: "GPLAY_UPDATE_PENDING_DOWNGRADE",
pendingDowngrade: null
});
};
fetchAndAlertActiveSubscription = async function fetchAndAlertActiveSubscription() {
let env29711;
const r24 = env4013;
let c25771_1 = r24;
const r10 = env29711 = {
$parent: r24
};
let c25771_0 = r10;
env29711[0] = void 0;
await fetchSubscriptions();
env29711[0] = SubscriptionStore.getPremiumTypeSubscription();
if (env29711[0] == null) {
throw new Error(intl.string(t.PjfUXe));
}
(0, setPaymentSuccess)();
(0, showOldPaymentFlowSuccess)($mk114921(c25771_0));
};
handleAppStateUpdated = async function handleAppStateUpdated(c25772_0) {
let c25772_4 = 0;
let c29712_0;
L15: {
try {
c29712_0 = void 0;
c29712_0 = c25772_0.state;
await void 0;
if (IAPStore_android.isReady() && AuthenticationStore.isAuthenticated() && c29712_0 === AppStates.ACTIVE) {
c25772_4 = 1;
await BillingManager.loadPurchases();
c25772_4 = 0;
}
} catch ($e) {
let r8 = $e;
if (c25772_4 !== 0) {
while (true) {
try {
c25772_4 = 0;
BillingManager.open();
break L15;
} catch ($e) {
r8 = $e;
if (c25772_4 === 0) {
break;
}
}
}
}
throw r8;
}
}
};
_excluded = ["succeededOnlyFields"];
const { NativeEventEmitter, NativeModules } = _Module17;
c4013_22 = new Logger("GPlayManager.android");
BillingManager = NativeModules.BillingManager;
c4013_24 = new NativeEventEmitter(BillingManager);
c4013_25 = {};
env4013[26] = null;
env4013[27] = null;
env4013[28] = null;
env4013[29] = null;
const r87 = {
giftInfoOptionsCache: c4013_25,
initialize: () => {
BillingManager.open();
env4013[26] = c4013_24.addListener("billing-manager-connection-state-updated", handleConnectionStateUpdated);
env4013[27] = c4013_24.addListener("billing-manager-purchase-state-updated", handlePurchaseStateUpdated);
env4013[28] = c4013_24.addListener("billing-manager-purchase-updated", handlePurchaseUpdated);
env4013[29] = c4013_24.addListener("billing-manager-downgrade-command", handleDowngradeCommand);
Dispatcher.subscribe("APP_STATE_UPDATE", handleAppStateUpdated);
},
terminate: () => {
BillingManager.close();
const r6 = env4013[26];
if (r6 != null) {
r6.remove();
}
const r9 = env4013[27];
if (r9 != null) {
r9.remove();
}
const r12 = env4013[28];
if (r12 != null) {
r12.remove();
}
const r15 = env4013[29];
if (r15 != null) {
r15.remove();
}
Dispatcher.unsubscribe("APP_STATE_UPDATE", handleAppStateUpdated);
}
};
export default r87;