// Metro module 4515 (f4516). import LocaleStore from "../modules/user_settings/LocaleStore"; import { Endpoints, PaymentSettings } from "../Constants"; import Logger from "../modules/debug/Logger"; import { loadStripe } from "../_bundle/Module4516"; import { HTTP } from "../_bundle/sendRequest"; import { useStateFromStores } from "../_bundle/Module589"; let c2724_2, c2724_8, c2724_9, c2724_12; const getStripe = function getStripe() { return c2724_2 != null ? Promise.resolve(c2724_2) : loadStripe(PaymentSettings.STRIPE.KEY).then((result) => { c2724_2 = result; return result; }); }; c2724_8 = new Logger("StripeUtils"); c2724_9 = { REQUIRES_PAYMENT_METHOD: "requires_payment_method", REQUIRES_CONFIRMATION: "requires_confirmation", REQUIRES_ACTION: "requires_action", PROCESSING: "processing", CANCELED: "canceled", SUCCEEDED: "succeeded" }; c2724_12 = { "en-US": "en", "zh-CN": "zh", "sv-SE": "sv" }; export function validateExpiry(a0) { let r14, r15; try { [r14, r15] = (function parseExpString(a0) { const r10 = a0.split(/[.\-/\s]+/g); let c25233_1 = r10; if (r10.length !== 2) { `You passed an invalid expiration date ${a0}Please pass a string containing a numeric month and year such as \`01-17\` or \`2015 / 05\``; } const r18 = r10.map((item) => { const r10 = parseInt(item); if (isNaN(r10)) { let r15 = `${c25233_1} is not a number.`; if (r15 == null) { r15 = ""; } `You passed an invalid expiration date ${a0}${r15}Please pass a string containing a numeric month and year such as \`01-17\` or \`2015 / 05\``; } if (r10 < 1) { const r26 = `${r10} is less than one.`; let r29 = r26; if (r29 == null) { r29 = ""; } `You passed an invalid expiration date ${a0}${r29}Please pass a string containing a numeric month and year such as \`01-17\` or \`2015 / 05\``; } return r10; }); const [r29, r30] = r18[0] > 12 ? [r18[1], r18[0]] : [r18[0], r18[1]]; if (r29 > 12) { let r36 = `Month must be a number 1-12, not ${r29}.`; if (r36 == null) { r36 = ""; } `You passed an invalid expiration date ${a0}${r36}Please pass a string containing a numeric month and year such as \`01-17\` or \`2015 / 05\``; } let r44 = r30; if (r44 < 100) { r44 = r30 + 2000; } return [r29, r44]; })(a0); } catch ($e) { return false; } const date = new Date(r15, r14); const date2 = new Date(); date.setMonth(date.getMonth() - 1); date.setMonth(date.getMonth() + 1, 1); return date > date2; } export { getStripe }; export function getStripeClientMode() { let r13; if (PaymentSettings.STRIPE.KEY == null) { c2724_8.warn("getStripeClientMode() called before PaymentSettings.STRIPE.KEY initialized: ", PaymentSettings.STRIPE.KEY); r13 = "unknown"; } else { const r12 = PaymentSettings.STRIPE.KEY.startsWith("pk_live"); r13 = "live"; if (!r12) { const r17 = PaymentSettings.STRIPE.KEY.startsWith("pk_test"); let r18 = "test"; if (!r17) { c2724_8.warn("Unexpected value for Stripe public key: ", PaymentSettings.STRIPE.KEY); r18 = "unknown"; } r13 = r18; } } return r13; } export function parseStripePaymentMethod(a0) { const billing_details = a0.billing_details; let address = billing_details.address; if (address == null) { address = {}; } let name = billing_details.name; if (name == null) { name = ""; } let line1 = address.line1; if (line1 == null) { line1 = ""; } let line2 = address.line2; if (line2 == null) { line2 = ""; } let city = address.city; if (city == null) { city = ""; } let state = address.state; if (state == null) { state = ""; } let country = address.country; if (country == null) { country = ""; } let postal_code = address.postal_code; if (postal_code == null) { postal_code = ""; } return { token: a0.id, billingAddressInfo: { name, line1, line2, city, state, country, postalCode: postal_code } }; } export function parseBillingAddressInfoToStripeBillingDetails(a0) { return { name: a0.name, address: { line1: a0.line1, line2: a0.line2, city: a0.city, state: a0.state, postal_code: a0.postalCode, country: a0.country } }; } export async function authenticatePaymentIntentForPaymentId(c25232_0) { let r130, r191, r220, r232; let c25232_3; let c25232_4 = 0; let c29399_0, c29399_1, c29399_2, c29399_3, c29399_4, c29399_5, c29399_6; L42: { L41: { L40: { L39: { L33: { L32: { try { c29399_0 = void 0; c29399_1 = void 0; c29399_2 = void 0; c29399_3 = void 0; c29399_4 = void 0; c29399_5 = void 0; c29399_6 = void 0; c25232_4 = 1; c29399_0 = (await HTTP.get({ url: Endpoints.BILLING_STRIPE_PAYMENT_INTENTS(c25232_0), oldFormErrors: true, rejectWithError: false })).body.stripe_payment_intent_client_secret; c29399_1 = await (0, getStripe)(); if (c29399_1 == null) { c25232_4 = 0; break L42; } c29399_2 = await c29399_1.retrievePaymentIntent(c29399_0); c29399_3 = c29399_2.error; c29399_4 = c29399_2.paymentIntent; if (c29399_3 != null) { r130 = { error: c29399_3.message }; c25232_4 = 0; break L41; } if (c29399_4 == null) { c25232_4 = 0; break L40; } c29399_5 = {}; if (c29399_4.status === c2724_9.REQUIRES_PAYMENT_METHOD && c29399_4.last_payment_error != null && c29399_4.last_payment_error.payment_method != null) { c29399_5.payment_method = c29399_4.last_payment_error.payment_method.id; } const status = c29399_4.status; if (c2724_9.REQUIRES_PAYMENT_METHOD !== status && c2724_9.REQUIRES_CONFIRMATION !== status && c2724_9.REQUIRES_ACTION !== status) { if (c2724_9.SUCCEEDED !== status && c2724_9.PROCESSING !== status) { c2724_9.CANCELED; r191 = { error: `Invalid Payment Intent status: ${c29399_4.status}` }; c25232_4 = 0; break L32; } c25232_4 = 0; break L33; } c29399_6 = (await c29399_1.confirmCardPayment(c29399_0, c29399_5)).error; r220 = c29399_6 != null ? { error: c29399_6.message } : {}; c25232_4 = 0; break L39; } catch ($e) { const r37 = $e; let r8 = r37; c25232_3 = r37; if (c25232_4 !== 0) { while (true) { try { const r229 = c25232_3; c25232_4 = 0; r232 = { error: r229.message }; } catch (r227) { r8 = r227; c25232_3 = r227; if (c25232_4 === 0) { break; } continue; } return r232; } } throw r8; } } return r191; } return {}; } return r220; } return { error: "payment intent does not exist" }; } return r130; } return { error: "unable to load stripe" }; } export function getStripeElementLocale(a0) { let r4 = c2724_12[a0]; if (r4 == null) { r4 = a0; } return r4; } export function useStripeLocale() { return useStateFromStores([LocaleStore], () => { let r5 = c2724_12[LocaleStore.locale]; if (r5 == null) { r5 = LocaleStore.locale; } return r5; }); }