Files
discord-decomp/modules/billing/actions/BillingSharedActionCreators.tsx
T
2026-11-01 12:12:55 +02:00

242 lines
6.7 KiB
TypeScript

// Metro module 4510 (f4511).
import PaymentSourceRecord from "../../../records/PaymentSourceRecord";
import { StripeErrorTypes } from "../Constants";
import { AnalyticEvents, Endpoints } from "../../../Constants";
import { HTTP } from "../../../_bundle/sendRequest";
import { parseV8BillingAddressSkemaErrorToBillingError, ErrorCodes } from "../../../errors/BillingError";
import Dispatcher from "../../../Dispatcher";
import { intl, t } from "../../../intl/index.native";
import AnalyticsUtils from "../../../utils/AnalyticsUtils";
import { BillingError } from "../../../errors/index";
import { captureBillingException } from "../../../utils/BillingUtils";
export async function validatePaymentSourceBillingAddress(c25195_0) {
let token;
let c25195_3;
let c25195_4 = 0;
let c29358_0, c29358_1;
try {
c29358_0 = void 0;
c25195_4 = 1;
token = (await HTTP.post({
url: Endpoints.BILLING_PAYMENT_SOURCES_VALIDATE_BILLING_ADDRESS,
body: {
billing_address: {
name: c25195_0.name,
line_1: c25195_0.line1,
line_2: c25195_0.line2,
city: c25195_0.city,
state: c25195_0.state,
postal_code: c25195_0.postalCode,
country: c25195_0.country,
email: c25195_0.email
}
},
rejectWithError: false
})).body.token;
c25195_4 = 0;
} catch ($e) {
const r26 = $e;
let r8 = r26;
c25195_3 = r26;
if (c25195_4 !== 0) {
while (true) {
try {
const r69 = c25195_3;
c25195_4 = 0;
c29358_1 = r69;
c29358_0 = parseV8BillingAddressSkemaErrorToBillingError(c29358_1);
Dispatcher.dispatch({
type: "BILLING_PAYMENT_SOURCE_CREATE_FAIL",
error: c29358_0
});
throw c29358_0;
} catch (r65) {
r8 = r65;
c25195_3 = r65;
if (c25195_4 === 0) {
break;
}
}
}
}
throw r8;
}
return token;
}
export function dispatchConfirmationError(a0, r13 = true, r16 = intl.string(t.khEaRI), r8 = {}) {
let r9, r43, error;
let r10 = a0;
if (StripeErrorTypes.includes(a0.type)) {
const failure_message = a0.message != null ? `${r16}: ${a0.message}` : r16;
const r57 = {
failure_message,
error_type: a0.type,
failure_code: a0.code,
failure_sub_code: a0.decline_code,
payment_source_type: a0.payment_method?.type
};
if (a0.type === "card_error") {
AnalyticsUtils.track(AnalyticEvents.PAYMENT_SOURCE_CREATION_FAILED, {
...r57,
stacktrace: new Error().stack
});
r13 = false;
}
error = new BillingError(failure_message);
r43 = r13;
r9 = r57;
} else {
const billingError = new BillingError(typeof a0 === "string" ? r16 : a0);
const r15 = {
failure_message: billingError.message,
status_code: billingError.code
};
const code = billingError.code;
r9 = r15;
error = billingError;
r43 = r13;
if (code === 429) {
r43 = false;
r9 = r15;
error = billingError;
}
}
Dispatcher.dispatch({
type: "BILLING_PAYMENT_SOURCE_CREATE_FAIL",
error
});
const r99 = Error;
if (typeof a0 !== "string") {
r10 = error.message;
}
const r104 = new r99(r10);
if (r43) {
captureBillingException(r104, {
...r8,
extra: {
...r9,
...r8.extra
}
});
}
return r104;
}
export async function popupBridgeState(c25196_0) {
let c25196_2;
c25196_2 = void 0;
let c29359_0 = c25196_0;
let c29359_1 = (await HTTP.post({
url: Endpoints.BILLING_POPUP_BRIDGE(c25196_0),
oldFormErrors: true,
rejectWithError: true
})).body.state;
Dispatcher.dispatch({
type: "BILLING_POPUP_BRIDGE_STATE_UPDATE",
state: c29359_1,
paymentSourceType: c29359_0
});
return c29359_1;
}
export async function createPaymentSource(c25197_0, c25197_1, c25197_2, c25197_3, c25197_4) {
let r142;
let c25197_5, c25197_6, c25197_7;
let c25197_8 = 0;
const r11 = void 0;
try {
let env29360;
c25197_6 = r11;
const r33 = env29360 = {};
c25197_5 = r33;
env29360[4] = void 0;
env29360[0] = c25197_0;
env29360[1] = c25197_1;
env29360[2] = c25197_2;
env29360[3] = c25197_3;
if (c25197_4 !== void 0) {
env29360[4] = c25197_4;
env29360[5] = void 0;
env29360[6] = void 0;
env29360[7] = void 0;
} else {
env29360[4] = false;
env29360[5] = void 0;
env29360[6] = void 0;
env29360[7] = void 0;
}
await void 0;
Dispatcher.dispatch({
type: "BILLING_PAYMENT_SOURCE_CREATE_START"
});
c25197_8 = 1;
env29360[5] = await HTTP.post({
url: Endpoints.BILLING_PAYMENT_SOURCES,
query: {
location: env29360[3].analyticsLocation
},
body: {
payment_gateway: env29360[0],
token: env29360[1],
billing_address: {
name: env29360[2].name,
line_1: env29360[2].line1,
line_2: env29360[2].line2,
city: env29360[2].city,
state: env29360[2].state,
postal_code: env29360[2].postalCode,
country: env29360[2].country,
email: env29360[2].email
},
billing_address_token: env29360[3].billingAddressToken,
bank: env29360[3].bank,
pix: env29360[3].pix != null ? {
tax_id: env29360[3].pix.taxId
} : void 0,
return_url: env29360[3].returnUrl,
default: env29360[4]
},
rejectWithError: false
});
env29360[6] = PaymentSourceRecord.createFromServer(env29360[5].body);
Dispatcher.dispatch({
type: "BILLING_PAYMENT_SOURCE_CREATE_SUCCESS",
paymentSource: env29360[6]
});
r142 = env29360[6];
c25197_8 = 0;
} catch ($e) {
const r31 = $e;
let r8 = r31;
c25197_7 = r31;
if (c25197_8 !== 0) {
while (true) {
try {
const r151 = c25197_7;
c25197_8 = 0;
env29360[8] = r151;
env29360[7] = parseV8BillingAddressSkemaErrorToBillingError(env29360[8]);
(function addFieldsToBillingError(a0, a1) {
if (a1 == null ? void 0 : a1.body?.adyen_redirect_url) {
a0.fields.adyen_redirect_url = a1 == null ? void 0 : a1.body?.adyen_redirect_url;
}
})(env29360[7], env29360[8]);
if (env29360[7].code !== ErrorCodes.CONFIRMATION_REQUIRED) {
Dispatcher.dispatch({
type: "BILLING_PAYMENT_SOURCE_CREATE_FAIL",
error: env29360[7]
});
}
throw env29360[7];
} catch (r147) {
r8 = r147;
c25197_7 = r147;
if (c25197_8 === 0) {
break;
}
}
}
}
throw r8;
}
return r142;
}