308 lines
9.3 KiB
TypeScript
308 lines
9.3 KiB
TypeScript
// Metro module 6504 (f6505).
|
|
import UserDiscountOfferRecord from "../user_offers/records/UserDiscountOfferRecord";
|
|
import { PREMIUM_TIER_2_HFU_TWO_WEEK_TRIAL_ID } from "./PremiumConstants";
|
|
import { PaymentGateways, AnalyticEvents, Endpoints } from "../../Constants";
|
|
import { isAndroid, isIOS } from "../../utils/PlatformUtils";
|
|
import Dispatcher from "../../Dispatcher";
|
|
import AnalyticsUtils from "../../utils/AnalyticsUtils";
|
|
import { HTTP } from "../../_bundle/sendRequest";
|
|
import { isAndroidTwoWeekTrialsExperimentEnabled } from "./experiments/AndroidTwoWeekTrialsExperiment";
|
|
import SentryUtils_native from "../../utils/SentryUtils.native";
|
|
import { UNSAFE_isDismissibleContentDismissed } from "../dismissible_content/DismissibleContentUnsafeUtils";
|
|
import { DismissibleContent } from "../../_bundle/Module1358";
|
|
import { removeDismissedContent } from "../user_settings/UserSettingsProtoActionCreators";
|
|
function $mk114999($env) {
|
|
return function getPaymentGateway() {
|
|
return isAndroid() ? PaymentGateways.GOOGLE : isIOS() ? PaymentGateways.APPLE : null;
|
|
};
|
|
}
|
|
let env4196 = {};
|
|
export async function fetchUserOffer(c25907_0, c25907_1, c25907_2, c25907_3, c25907_4) {
|
|
let r38;
|
|
let user_trial_offer, user_discount_offer, c25907_7, c25907_8, c25907_9;
|
|
let c25907_10 = 0;
|
|
const r13 = env4196;
|
|
L50: {
|
|
try {
|
|
let env29792;
|
|
L10: {
|
|
c25907_8 = r13;
|
|
const r36 = env29792 = {
|
|
$parent: r13
|
|
};
|
|
c25907_7 = r36;
|
|
env29792[1] = void 0;
|
|
env29792[2] = void 0;
|
|
env29792[3] = void 0;
|
|
env29792[4] = void 0;
|
|
env29792[0] = c25907_0;
|
|
if (c25907_1 !== void 0) {
|
|
env29792[1] = c25907_1;
|
|
r38 = c25907_2;
|
|
if (r38 !== void 0) {
|
|
break L10;
|
|
}
|
|
} else {
|
|
env29792[1] = true;
|
|
r38 = c25907_2;
|
|
if (r38 !== void 0) {
|
|
break L10;
|
|
}
|
|
}
|
|
r38 = {
|
|
offerId: void 0,
|
|
paymentGatewayOverride: void 0
|
|
};
|
|
}
|
|
env29792[2] = r38;
|
|
env29792[3] = c25907_3;
|
|
env29792[4] = c25907_4;
|
|
env29792[5] = void 0;
|
|
env29792[6] = void 0;
|
|
env29792[7] = void 0;
|
|
env29792[8] = void 0;
|
|
env29792[9] = void 0;
|
|
env29792[10] = void 0;
|
|
env29792[11] = void 0;
|
|
env29792[12] = void 0;
|
|
env29792[13] = void 0;
|
|
await void 0;
|
|
if (env29792[1]) {
|
|
Dispatcher.dispatch({
|
|
type: "BILLING_USER_OFFER_FETCH_START"
|
|
});
|
|
c25907_10 = 1;
|
|
if (env29792[0] != null) {
|
|
AnalyticsUtils.track(AnalyticEvents.FETCH_USER_OFFER_STARTED, {
|
|
call_location: env29792[0]
|
|
});
|
|
}
|
|
env29792[5] = env29792[2].offerId;
|
|
env29792[6] = env29792[2].paymentGatewayOverride;
|
|
env29792[7] = env29792[6] !== void 0 ? env29792[6] : $mk114999(env4196)();
|
|
env29792[8] = env29792[7] == null && env29792[5] == null ? {} : {
|
|
payment_gateway: env29792[7],
|
|
offer_id: env29792[5]
|
|
};
|
|
const r125 = await HTTP.post({
|
|
url: Endpoints.USER_OFFER,
|
|
body: env29792[8],
|
|
rejectWithError: true,
|
|
retries: env29792[3] != null ? env29792[3].retries : void 0
|
|
});
|
|
const r135 = "Returned user discount offer does not match offer ID request parameter";
|
|
env29792[9] = r125;
|
|
const user_trial_offer2 = env29792[9].body.user_trial_offer;
|
|
user_trial_offer = user_trial_offer2;
|
|
if (user_trial_offer2 == null) {
|
|
user_trial_offer = null;
|
|
}
|
|
env29792[10] = user_trial_offer;
|
|
const user_discount_offer2 = env29792[9].body.user_discount_offer;
|
|
user_discount_offer = user_discount_offer2;
|
|
if (user_discount_offer2 == null) {
|
|
user_discount_offer = null;
|
|
}
|
|
env29792[11] = user_discount_offer;
|
|
env29792[12] = env29792[10]?.trial_id === PREMIUM_TIER_2_HFU_TWO_WEEK_TRIAL_ID && !isAndroidTwoWeekTrialsExperimentEnabled({
|
|
location: "user_offer_action_creators"
|
|
});
|
|
if (env29792[5] != null && env29792[11] != null) {
|
|
if (env29792[11].discount_id !== env29792[5]) {
|
|
env29792[13] = new Error(r135);
|
|
SentryUtils_native.captureException(env29792[13], {
|
|
extra: {
|
|
offer_id: env29792[5],
|
|
user_discount_offer: env29792[11]
|
|
},
|
|
...env29792[4]
|
|
});
|
|
throw env29792[13];
|
|
}
|
|
}
|
|
if (env29792[10] == null && UNSAFE_isDismissibleContentDismissed(DismissibleContent.NAGBAR_NOTICE_PREMIUM_TIER_TWO_TRIAL_ENDING)) {
|
|
removeDismissedContent(DismissibleContent.NAGBAR_NOTICE_PREMIUM_TIER_TWO_TRIAL_ENDING);
|
|
}
|
|
Dispatcher.dispatch({
|
|
type: "BILLING_USER_OFFER_FETCH_SUCCESS",
|
|
userTrialOffer: env29792[12] ? null : env29792[10],
|
|
userDiscountOffer: env29792[11] != null ? UserDiscountOfferRecord.createFromServer(env29792[11]) : null
|
|
});
|
|
c25907_10 = 0;
|
|
break L50;
|
|
}
|
|
} catch ($e) {
|
|
const r34 = $e;
|
|
let r8 = r34;
|
|
c25907_9 = r34;
|
|
if (c25907_10 !== 0) {
|
|
while (true) {
|
|
try {
|
|
c25907_10 = 0;
|
|
Dispatcher.dispatch({
|
|
type: "BILLING_USER_OFFER_FETCH_FAIL"
|
|
});
|
|
} catch (r241) {
|
|
r8 = r241;
|
|
c25907_9 = r241;
|
|
if (c25907_10 === 0) {
|
|
break;
|
|
}
|
|
continue;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
throw r8;
|
|
}
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
export async function fetchExistingChurnDiscountOffer() {
|
|
let r75;
|
|
let offer;
|
|
let c25908_4 = 0;
|
|
let c29793_0, c29793_1;
|
|
try {
|
|
c29793_0 = void 0;
|
|
c29793_1 = void 0;
|
|
Dispatcher.dispatch({
|
|
type: "BILLING_USER_OFFER_FETCH_START"
|
|
});
|
|
c25908_4 = 1;
|
|
const offer3 = (await HTTP.get({
|
|
url: Endpoints.CHURN_USER_OFFER,
|
|
rejectWithError: true
|
|
})).body.offer;
|
|
offer = offer3;
|
|
if (offer3 == null) {
|
|
offer = null;
|
|
}
|
|
c29793_0 = offer;
|
|
c29793_1 = c29793_0 != null ? UserDiscountOfferRecord.createFromServer(c29793_0) : null;
|
|
Dispatcher.dispatch({
|
|
type: "BILLING_USER_OFFER_FETCH_SUCCESS",
|
|
userDiscountOffer: c29793_1
|
|
});
|
|
r75 = {
|
|
userDiscountOffer: c29793_1
|
|
};
|
|
c25908_4 = 0;
|
|
} catch ($e) {
|
|
let r8 = $e;
|
|
if (c25908_4 !== 0) {
|
|
while (true) {
|
|
try {
|
|
c25908_4 = 0;
|
|
Dispatcher.dispatch({
|
|
type: "BILLING_USER_OFFER_FETCH_FAIL"
|
|
});
|
|
} catch ($e) {
|
|
r8 = $e;
|
|
if (c25908_4 === 0) {
|
|
break;
|
|
}
|
|
continue;
|
|
}
|
|
return void 0;
|
|
}
|
|
}
|
|
throw r8;
|
|
}
|
|
return r75;
|
|
}
|
|
export async function fetchChurnDiscountOffer() {
|
|
let r70;
|
|
let offer2;
|
|
let c25909_4 = 0;
|
|
let c29794_1, c29794_0;
|
|
L14: {
|
|
try {
|
|
c29794_1 = void 0;
|
|
c29794_0 = null;
|
|
c25909_4 = 1;
|
|
const offer3 = (await HTTP.post({
|
|
url: Endpoints.CHURN_USER_OFFER,
|
|
rejectWithError: true
|
|
})).body.offer;
|
|
offer2 = offer3;
|
|
if (offer3 == null) {
|
|
offer2 = null;
|
|
}
|
|
c29794_1 = offer2;
|
|
if (c29794_1 != null) {
|
|
c29794_0 = UserDiscountOfferRecord.createFromServer(c29794_1);
|
|
Dispatcher.dispatch({
|
|
type: "BILLING_USER_OFFER_FETCH_SUCCESS",
|
|
userDiscountOffer: c29794_0
|
|
});
|
|
}
|
|
c25909_4 = 0;
|
|
r70 = c29794_0;
|
|
} catch ($e) {
|
|
let r8 = $e;
|
|
if (c25909_4 !== 0) {
|
|
while (true) {
|
|
try {
|
|
c25909_4 = 0;
|
|
r70 = c29794_0;
|
|
break L14;
|
|
} catch ($e) {
|
|
r8 = $e;
|
|
if (c25909_4 === 0) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
throw r8;
|
|
}
|
|
}
|
|
return r70;
|
|
}
|
|
export function acknowledgeUserOffer(a0, a1) {
|
|
const user_trial_offer_id = a0 != null ? a0.expires_at == null ? a0.id : void 0 : void 0;
|
|
const user_discount_offer_id = a1 == null ? void 0 : a1.hasAcknowledged() ? void 0 : a1.id;
|
|
if (user_trial_offer_id === void 0 && user_discount_offer_id === void 0) {
|
|
return void 0;
|
|
}
|
|
return HTTP.post({
|
|
url: Endpoints.USER_OFFER_ACKNOWLEDGED,
|
|
body: {
|
|
user_trial_offer_id,
|
|
user_discount_offer_id
|
|
},
|
|
oldFormErrors: true,
|
|
rejectWithError: false
|
|
}).then((result) => {
|
|
let user_discount = result.body.user_discount;
|
|
if (user_discount == null) {
|
|
user_discount = null;
|
|
}
|
|
let user_discount_offer2 = result.body.user_discount_offer;
|
|
if (user_discount_offer2 == null) {
|
|
user_discount_offer2 = null;
|
|
}
|
|
let user_trial_offer2 = result.body.user_trial_offer;
|
|
if (user_trial_offer2 == null) {
|
|
user_trial_offer2 = null;
|
|
}
|
|
Dispatcher.dispatch({
|
|
type: "BILLING_USER_OFFER_ACKNOWLEDGED_SUCCESS",
|
|
userTrialOffer: user_trial_offer2,
|
|
userDiscount: user_discount != null ? UserDiscountOfferRecord.createFromServer(user_discount) : null,
|
|
userDiscountOffer: user_discount_offer2 != null ? UserDiscountOfferRecord.createFromServer(user_discount_offer2) : null
|
|
});
|
|
}).catch((error) => {
|
|
if (error.status === 404) {
|
|
Dispatcher.dispatch({
|
|
type: "BILLING_USER_OFFER_ACKNOWLEDGED_SUCCESS",
|
|
userTrialOffer: null,
|
|
userDiscount: null,
|
|
userDiscountOffer: null
|
|
});
|
|
}
|
|
});
|
|
}
|