Files
discord-decomp/modules/payments/native/utils/createOrReuseGiftOrder.tsx
T
2026-11-01 12:12:55 +02:00

105 lines
3.3 KiB
TypeScript

// Metro module 9703 (f9704).
import { useCallback } from "react";
import { ItemPurchaseType } from "../../PaymentConstants";
import { SubscriptionPlanInfo } from "../../../premium/PremiumConstants";
import { PaymentGateways } from "../../../../_bundle/Module505";
import Logger from "../../../debug/Logger";
import { useAndroidShopOrdersEnabled } from "../../../billing/experiments/AndroidShopOrdersExperiment";
import { getOrCreateOrder, DRAFT_ORDER_LOOKBACK_DAYS } from "../OrderActionCreators";
import { isAndroid } from "../../../../utils/PlatformUtils";
import Module3771 from "../../../../_bundle/Module3771";
import { captureBillingException } from "../../../../utils/BillingUtils";
let env6420 = {};
const c6420_8 = new Logger("createOrReuseGiftOrder");
export function useCreateOrReuseGiftOrder(a0) {
let env17418 = {
$parent: env6420
};
env17418[0] = a0;
const androidShopOrdersEnabled = useAndroidShopOrdersEnabled({
location: a0
});
env17418[1] = androidShopOrdersEnabled;
let c17419_0 = async (c30137_0) => {
let orCreateOrder;
let c30137_2, c30137_3;
let c30137_4 = 0;
let c31512_0, c31512_1, c31512_2, c31512_3, c31512_4, c31512_5, c31512_6;
const r17 = void 0;
try {
c30137_2 = r17;
c31512_0 = void 0;
c31512_1 = void 0;
c31512_2 = void 0;
c31512_0 = c30137_0.planId;
c31512_1 = c30137_0.recipientUserId;
c31512_2 = c30137_0.productId;
c31512_3 = void 0;
c31512_4 = void 0;
c31512_5 = void 0;
await void 0;
c31512_3 = SubscriptionPlanInfo[c31512_0];
if (c31512_3 == null) {
throw new Error(`Invalid plan id: ${c31512_0}`);
}
const r80 = c30137_2;
c31512_4 = c31512_3.skuId;
c31512_5 = r80.$parent[1] ? {
line_items: [{
external_product_id: c31512_2
}]
} : void 0;
c30137_4 = 1;
orCreateOrder = await getOrCreateOrder({
skuId: c31512_4,
paymentGateway: isAndroid() ? PaymentGateways.GOOGLE : PaymentGateways.APPLE,
recipientUserId: c31512_1,
purchaseType: ItemPurchaseType.ONE_TIME,
isGift: true,
createdAfter: Module3771().utc().subtract(DRAFT_ORDER_LOOKBACK_DAYS, "days").toISOString(),
subscriptionPlanId: c31512_0,
externalGatewayFacet: c31512_5
});
c30137_4 = 0;
} catch ($e) {
const r37 = $e;
let r7 = r37;
c30137_3 = r37;
if (c30137_4 !== 0) {
while (true) {
try {
const r160 = c30137_2;
const r161 = c30137_3;
c30137_4 = 0;
c31512_6 = r161;
const location2 = r160.$parent[0];
c6420_8.error("Failed to create order for gift purchase", {
error: c31512_6,
skuId: c31512_4,
location: location2
});
captureBillingException(c31512_6, {
tags: {
skuId: c31512_4,
source: `${location2}_createOrder`
}
});
throw c31512_6;
} catch (r157) {
r7 = r157;
c30137_3 = r157;
if (c30137_4 === 0) {
break;
}
}
}
}
throw r7;
}
return orCreateOrder;
};
return useCallback(function() {
return c17419_0.apply(this, arguments);
}, [a0, androidShopOrdersEnabled]);
}