decord/source/modules/premium/PremiumSubscriptionInvoice.tsx

379 lines
13 KiB
TypeScript
Raw Normal View History

2026-07-25 08:10:48 +00:00
// Module ID: 6490
2026-07-27 11:26:19 +00:00
// Function ID: 58016
2026-07-20 16:05:17 +00:00
// Name: createSubscriptionInvoicePreview
2026-07-25 08:10:48 +00:00
// Dependencies: [29, 57, 5, 31, 3786, 653, 3777, 507, 686, 4030, 44, 4370, 2]
2026-07-20 16:05:17 +00:00
// Exports: getItemUnitPriceWithDiscount, useFetchSubscriptionGiftInvoicePreview, useFetchSubscriptionInvoicePreview, useGetSubscriptionInvoice
2026-07-25 08:10:48 +00:00
// Module 6490 (createSubscriptionInvoicePreview)
2026-07-23 10:11:24 +00:00
import _objectWithoutProperties from "_objectWithoutProperties";
import _slicedToArray from "_slicedToArray";
import ME from "ME";
import result from "result";
import _callSuper from "_callSuper";
import { Endpoints } from "ME";
let closure_10;
let closure_7;
let closure_8;
let closure_9;
const require = arg1;
2026-07-20 16:05:17 +00:00
function createSubscriptionInvoicePreview() {
return _createSubscriptionInvoicePreview(...arguments);
}
async function _createSubscriptionInvoicePreview(arg0, arg1) {
2026-07-23 10:11:24 +00:00
let iter = (function*(arg0) {
2026-07-20 16:05:17 +00:00
let applyEntitlements;
let code;
let currency;
let items;
let loadId;
let metadata;
let paymentSourceId;
let renewal;
let trialId;
({ items, paymentSourceId, applyEntitlements, trialId, code } = arg0);
if (applyEntitlements === undefined) {
applyEntitlements = false;
}
({ currency, renewal, metadata, loadId } = arg0);
yield undefined;
let obj = {};
2026-07-23 10:11:24 +00:00
const result = outer2_0(outer2_2[6]).coerceExistingItemsToNewItemInterval(items);
2026-07-20 16:05:17 +00:00
obj.items = result.map((planId) => {
let obj = Object.create(null);
obj.planId = 0;
obj = {};
const merged = Object.assign(Object.assign(planId, obj));
obj["plan_id"] = planId.planId;
return obj;
});
obj.payment_source_id = paymentSourceId;
obj.trial_id = trialId;
obj.code = code;
obj.apply_entitlements = applyEntitlements;
obj.currency = currency;
obj.renewal = renewal;
obj.metadata = metadata;
obj.load_id = loadId;
2026-07-23 10:11:24 +00:00
const HTTP = outer2_0(outer2_2[7]).HTTP;
obj = { url: outer2_12.BILLING_SUBSCRIPTIONS_PREVIEW, body: obj, oldFormErrors: true, rejectWithError: false };
const invoiceFromServer = outer2_11.createInvoiceFromServer(yield HTTP.post(obj).body);
2026-07-20 16:05:17 +00:00
const checkoutContext = invoiceFromServer.checkoutContext;
let payment_sources;
if (null != checkoutContext) {
payment_sources = checkoutContext.payment_sources;
}
if (null != payment_sources) {
obj = { type: "SUBSCRIPTION_PREVIEW_CHECKOUT_CONTEXT_UPDATE", checkoutContext: invoiceFromServer.checkoutContext, paymentSourceId };
2026-07-23 10:11:24 +00:00
outer2_1(outer2_2[8]).dispatch(obj);
const obj4 = outer2_1(outer2_2[8]);
2026-07-20 16:05:17 +00:00
}
return invoiceFromServer;
2026-07-23 10:11:24 +00:00
})();
iter.next();
return iter;
2026-07-20 16:05:17 +00:00
}
function updateSubscriptionInvoicePreview() {
return _updateSubscriptionInvoicePreview(...arguments);
}
async function _updateSubscriptionInvoicePreview(arg0, arg1) {
2026-07-23 10:11:24 +00:00
let iter = (function*(arg0) {
2026-07-20 16:05:17 +00:00
let analyticsLocation;
let analyticsLocations;
let applyEntitlements;
let currency;
let items;
let paymentSourceId;
let renewal;
let subscriptionId;
let userDiscountOfferId;
({ items, paymentSourceId, applyEntitlements, subscriptionId, renewal, currency } = arg0);
if (applyEntitlements === undefined) {
applyEntitlements = false;
}
({ analyticsLocations, analyticsLocation, userDiscountOfferId } = arg0);
yield undefined;
let result = items;
if (null != items) {
2026-07-23 10:11:24 +00:00
let obj = outer2_0(outer2_2[6]);
2026-07-20 16:05:17 +00:00
result = obj.coerceExistingItemsToNewItemInterval(items);
}
obj = {};
let mapped;
if (null != result) {
mapped = result.map((planId) => {
let obj = Object.create(null);
obj.planId = 0;
obj = {};
const merged = Object.assign(Object.assign(planId, obj));
obj["plan_id"] = planId.planId;
return obj;
});
}
obj.items = mapped;
obj.payment_source_id = paymentSourceId;
obj.renewal = renewal;
obj.apply_entitlements = applyEntitlements;
obj.currency = currency;
obj.user_discount_offer_id = userDiscountOfferId;
2026-07-23 10:11:24 +00:00
const HTTP = outer2_0(outer2_2[7]).HTTP;
obj = { url: outer2_12.BILLING_SUBSCRIPTION_PREVIEW(subscriptionId), query: { location: analyticsLocation, location_stack: analyticsLocations }, body: obj, oldFormErrors: true, rejectWithError: false };
const invoiceFromServer = outer2_11.createInvoiceFromServer(yield HTTP.patch(obj).body);
2026-07-20 16:05:17 +00:00
let tmp7 = tmp6;
if (null != paymentSourceId) {
const checkoutContext = invoiceFromServer.checkoutContext;
let payment_sources;
if (null != checkoutContext) {
payment_sources = checkoutContext.payment_sources;
}
tmp7 = null != payment_sources;
}
if (tmp7) {
const obj1 = { type: "SUBSCRIPTION_PREVIEW_CHECKOUT_CONTEXT_UPDATE", checkoutContext: invoiceFromServer.checkoutContext, paymentSourceId };
2026-07-23 10:11:24 +00:00
outer2_1(outer2_2[8]).dispatch(obj1);
const obj4 = outer2_1(outer2_2[8]);
2026-07-20 16:05:17 +00:00
}
return invoiceFromServer;
2026-07-23 10:11:24 +00:00
})();
iter.next();
return iter;
2026-07-20 16:05:17 +00:00
}
function createOneTimePurchaseInvoicePreview() {
return _createOneTimePurchaseInvoicePreview(...arguments);
}
async function _createOneTimePurchaseInvoicePreview(arg0, arg1) {
2026-07-23 10:11:24 +00:00
let iter = (function*(arg0) {
2026-07-20 16:05:17 +00:00
let currency;
let loadId;
let paymentSourceId;
let quantity;
let skuId;
let subscriptionPlanId;
({ skuId, quantity } = arg0);
({ paymentSourceId, subscriptionPlanId, currency, loadId } = arg0);
yield undefined;
2026-07-23 10:11:24 +00:00
outer2_1(outer2_2[10])(skuId, "SKU ID is missing for one time purchase gift invoice preview");
2026-07-20 16:05:17 +00:00
let obj = { gift: true, payment_source_id: paymentSourceId, sku_subscription_plan_id: subscriptionPlanId, currency, load_id: loadId };
if (null != quantity) {
tmp3.quantity = quantity;
}
2026-07-23 10:11:24 +00:00
obj = { url: outer2_12.STORE_SKU_PURCHASE(skuId), query: obj, oldFormErrors: true, rejectWithError: false };
return outer2_11.createInvoiceFromServer(yield outer2_0(outer2_2[11]).httpGetWithCountryCodeQuery(obj).body);
})();
iter.next();
return iter;
2026-07-20 16:05:17 +00:00
}
function getSubscriptionInvoice() {
return _getSubscriptionInvoice(...arguments);
}
async function _getSubscriptionInvoice(arg0, arg1) {
2026-07-23 10:11:24 +00:00
let iter = (function*(arg0) {
2026-07-20 16:05:17 +00:00
let preventFetch;
let subscriptionId;
({ subscriptionId, preventFetch } = arg0);
yield undefined;
if (preventFetch) {
return null;
} else {
2026-07-23 10:11:24 +00:00
const HTTP = outer2_0(outer2_2[7]).HTTP;
const obj = { url: outer2_12.BILLING_SUBSCRIPTION_INVOICE(subscriptionId), oldFormErrors: true, rejectWithError: false };
return outer2_11.createInvoiceFromServer(yield HTTP.get(obj).body);
2026-07-20 16:05:17 +00:00
}
2026-07-23 10:11:24 +00:00
})();
iter.next();
return iter;
2026-07-20 16:05:17 +00:00
}
function useFetchGenericInvoicePreview(preventFetch, arg1, arg2) {
let flag = preventFetch.preventFetch;
if (flag === undefined) {
flag = false;
}
2026-07-23 10:11:24 +00:00
let closure_1 = arg1;
2026-07-20 16:05:17 +00:00
let closure_2;
let closure_3;
2026-07-23 10:11:24 +00:00
const tmp = callback(callback5(null), 2);
2026-07-20 16:05:17 +00:00
closure_2 = tmp[1];
2026-07-23 10:11:24 +00:00
const tmp2 = callback(callback5(null), 2);
2026-07-20 16:05:17 +00:00
closure_3 = tmp2[1];
const items = [flag, arg1, arg2];
2026-07-23 10:11:24 +00:00
callback4(() => {
2026-07-20 16:05:17 +00:00
async function _loadPreview() {
2026-07-23 10:11:24 +00:00
outer3_3(null);
if (!outer2_0) {
outer3_2(tmp2);
2026-07-20 16:05:17 +00:00
}
}
2026-07-23 10:11:24 +00:00
let c0 = false;
if (!c0) {
(function loadPreview() {
2026-07-20 16:05:17 +00:00
return _loadPreview(...arguments);
2026-07-23 10:11:24 +00:00
})();
2026-07-20 16:05:17 +00:00
}
return () => {
2026-07-23 10:11:24 +00:00
let c0 = true;
2026-07-20 16:05:17 +00:00
};
}, items);
const items1 = [tmp[0], tmp2[0]];
return items1;
}
function getPaymentSourceIdFromInvoiceRecord(checkoutContext) {
checkoutContext = checkoutContext.checkoutContext;
let payment_sources;
if (null != checkoutContext) {
payment_sources = checkoutContext.payment_sources;
}
let tmp2 = null;
if (null != payment_sources) {
const found = payment_sources.find((enabled) => enabled.enabled);
let id;
if (null != found) {
id = found.id;
}
let tmp5 = null;
if (null != id) {
tmp5 = id;
}
tmp2 = tmp5;
}
return tmp2;
}
2026-07-23 10:11:24 +00:00
let closure_3 = ["subscriptionId"];
({ useCallback: closure_7, useEffect: closure_8, useState: closure_9, useRef: closure_10 } = result);
result = require("asyncGeneratorStep").fileFinishedImporting("modules/premium/PremiumSubscriptionInvoice.tsx");
2026-07-20 16:05:17 +00:00
export { createSubscriptionInvoicePreview };
export { updateSubscriptionInvoicePreview };
export { createOneTimePurchaseInvoicePreview };
export { getSubscriptionInvoice };
export { useFetchGenericInvoicePreview };
export const useFetchSubscriptionGiftInvoicePreview = function useFetchSubscriptionGiftInvoicePreview(preventFetch) {
2026-07-23 10:11:24 +00:00
let closure_0 = preventFetch;
let closure_1 = callback6(preventFetch);
let closure_2 = callback6(false);
callback4(() => {
closure_1.current = closure_0;
2026-07-20 16:05:17 +00:00
});
const items = [JSON.stringify(preventFetch)];
2026-07-23 10:11:24 +00:00
return useFetchGenericInvoicePreview(preventFetch, callback3(() => {
2026-07-20 16:05:17 +00:00
const current = ref.current;
let tmp = current;
if (!ref2.current) {
const obj = {};
const merged = Object.assign(current);
obj["paymentSourceId"] = null;
tmp = obj;
}
ref2.current = true;
2026-07-23 10:11:24 +00:00
return outer1_17(tmp);
2026-07-20 16:05:17 +00:00
}, items), arg1);
};
export const useFetchSubscriptionInvoicePreview = function useFetchSubscriptionInvoicePreview(subscriptionId) {
2026-07-23 10:11:24 +00:00
let closure_0 = subscriptionId;
2026-07-20 16:05:17 +00:00
let tmp = subscriptionId;
if ("subscriptionId" in subscriptionId) {
tmp = subscriptionId;
if (null == subscriptionId.subscriptionId) {
subscriptionId = subscriptionId.subscriptionId;
2026-07-23 10:11:24 +00:00
const tmp5 = shouldReturnInvoiceCache(subscriptionId, serverPricedPreviewRef);
closure_0 = tmp5;
2026-07-20 16:05:17 +00:00
tmp = tmp5;
}
}
2026-07-23 10:11:24 +00:00
let closure_1 = callback6(tmp);
let closure_2 = callback6(false);
const tmp6 = (function useServerProvidedInvoiceCache(arg0) {
let tmp = outer1_10(null);
let closure_0 = tmp;
2026-07-20 16:05:17 +00:00
const items = [arg0];
2026-07-23 10:11:24 +00:00
outer1_8(() => {
closure_0.current = null;
2026-07-20 16:05:17 +00:00
}, items);
2026-07-23 10:11:24 +00:00
const tmp3 = outer1_7((paymentSourceId) => {
2026-07-20 16:05:17 +00:00
const current = tmp.current;
2026-07-23 10:11:24 +00:00
tmp = null != current && null != paymentSourceId.paymentSourceId && paymentSourceId.paymentSourceId === current.serverSelectedPaymentSourceId;
2026-07-20 16:05:17 +00:00
if (tmp) {
tmp = arg1 === current.dedupeKey;
}
return tmp;
}, []);
return {
serverPricedPreviewRef: tmp,
2026-07-23 10:11:24 +00:00
shouldReturnInvoiceCache: outer1_7((paymentSourceId) => {
2026-07-20 16:05:17 +00:00
const current = tmp.current;
2026-07-23 10:11:24 +00:00
tmp = null != current && null != paymentSourceId.paymentSourceId && paymentSourceId.paymentSourceId === current.serverSelectedPaymentSourceId;
2026-07-20 16:05:17 +00:00
if (tmp) {
tmp = arg1 === current.dedupeKey;
}
return tmp;
}, []),
2026-07-23 10:11:24 +00:00
updateServerPricedPreviewRef: outer1_7((record, dedupeKey) => {
2026-07-20 16:05:17 +00:00
let tmp2 = null;
if (null == arg2) {
2026-07-23 10:11:24 +00:00
const obj = { record, dedupeKey, serverSelectedPaymentSourceId: outer2_22(record) };
2026-07-20 16:05:17 +00:00
tmp2 = obj;
}
2026-07-23 10:11:24 +00:00
closure_0.current = tmp2;
2026-07-20 16:05:17 +00:00
}, [])
};
2026-07-23 10:11:24 +00:00
})(arg1);
serverPricedPreviewRef = tmp6.serverPricedPreviewRef;
shouldReturnInvoiceCache = tmp6.shouldReturnInvoiceCache;
2026-07-20 16:05:17 +00:00
const updateServerPricedPreviewRef = tmp6.updateServerPricedPreviewRef;
2026-07-23 10:11:24 +00:00
callback4(() => {
closure_1.current = closure_0;
2026-07-20 16:05:17 +00:00
});
2026-07-23 10:11:24 +00:00
let items = [JSON.stringify(tmp), serverPricedPreviewRef, shouldReturnInvoiceCache, updateServerPricedPreviewRef];
return useFetchGenericInvoicePreview(tmp, callback3(() => {
const current = json.current;
2026-07-20 16:05:17 +00:00
let tmp = current;
2026-07-23 10:11:24 +00:00
if (!ref.current) {
2026-07-20 16:05:17 +00:00
let obj = {};
const merged = Object.assign(current);
obj["paymentSourceId"] = null;
tmp = obj;
}
2026-07-23 10:11:24 +00:00
let closure_0 = tmp;
2026-07-20 16:05:17 +00:00
if ("subscriptionId" in tmp) {
2026-07-23 10:11:24 +00:00
ref.current = true;
return outer1_15(tmp);
2026-07-20 16:05:17 +00:00
} else if ("items" in tmp) {
2026-07-23 10:11:24 +00:00
ref.current = true;
2026-07-20 16:05:17 +00:00
const _JSON = JSON;
obj = {};
const merged1 = Object.assign(tmp);
obj["paymentSourceId"] = "exclude_from_dedupe";
2026-07-23 10:11:24 +00:00
json = JSON.stringify(obj);
2026-07-20 16:05:17 +00:00
const current2 = serverPricedPreviewRef.current;
if (null != current2) {
if (shouldReturnInvoiceCache(tmp, json)) {
let resolved = Promise.resolve(current2.record);
}
return resolved;
}
2026-07-23 10:11:24 +00:00
resolved = outer1_13(tmp).then((arg0) => arg0);
const promise = outer1_13(tmp);
2026-07-20 16:05:17 +00:00
} else {
return null;
}
}, items), arg1);
};
export const useGetSubscriptionInvoice = function useGetSubscriptionInvoice(preventFetch) {
2026-07-23 10:11:24 +00:00
let closure_0 = preventFetch;
let closure_1 = callback6(preventFetch);
callback4(() => {
closure_1.current = closure_0;
2026-07-20 16:05:17 +00:00
});
const items = [JSON.stringify(preventFetch)];
2026-07-23 10:11:24 +00:00
return useFetchGenericInvoicePreview(preventFetch, callback3(() => outer1_19(ref.current), items), arg1);
2026-07-20 16:05:17 +00:00
};
export const getItemUnitPriceWithDiscount = function getItemUnitPriceWithDiscount(arg0) {
let discounts;
2026-07-23 10:11:24 +00:00
let importDefault;
let closure_0 = arg0;
({ subscriptionPlanPrice: importDefault, discounts } = arg0);
2026-07-20 16:05:17 +00:00
const item = discounts.forEach((amount) => {
2026-07-23 10:11:24 +00:00
closure_1 = closure_1 - amount.amount / quantity.quantity;
2026-07-20 16:05:17 +00:00
});
return importDefault;
};