// Metro module 4512 (f4513). import { Endpoints, VAULTABLE_PAYMENT_SOURCES, PaymentGateways } from "../../../Constants"; import { PaymentSourceTypes, ADYEN_PAYMENT_SOURCES, STRIPE_PAYMENT_SOURCES } from "../../../_bundle/Module505"; import Logger from "../../debug/Logger"; import { HTTP, getAPIBaseURL } from "../../../_bundle/sendRequest"; import { intl, t } from "../../../intl/index.native"; import { dispatchConfirmationError, validatePaymentSourceBillingAddress, createPaymentSource, popupBridgeState } from "./BillingSharedActionCreators"; import { CardNumberElement } from "../../../_bundle/Module4513"; import Dispatcher from "../../../Dispatcher"; import Module38 from "../../../_bundle/Module38"; import { createStripeSetupIntent } from "./StripeActionCreators"; import { getStripe, parseBillingAddressInfoToStripeBillingDetails, parseStripePaymentMethod } from "../../../utils/StripeUtils"; import { ErrorCodes } from "../../../errors/BillingError"; import { BillingError } from "../../../errors/index"; import { HermesBuiltin } from "../../../_hermes/prelude"; function $mk114561($env) { return (a0) => dispatchConfirmationError(a0, true, intl.string(t.khEaRI), { tags: { source: "payment_elements" } }); } function $mk114562($env) { return (a0) => dispatchConfirmationError(a0); } function $mk114564($env) { return function getClientSecret() { return $env[12].apply(this, arguments); }; } let dispatchPaymentElementsConfirmationError, validateSetupIntentResponse, submitElementsForPaymentElement, createStripePaymentMethodWithElements, createStripePaymentSourceToken, c2722_11, c2722_21, c2722_25; let env2722 = {}; env2722[12] = function _getClientSecret() { const r8 = async (c25198_0) => (await HTTP.get({ url: Endpoints.BILLING_STRIPE_PAYMENT_INTENTS(c25198_0), oldFormErrors: true, rejectWithError: true })).body.stripe_payment_intent_client_secret; env2722[12] = r8; return r8.apply(this, arguments); }; dispatchPaymentElementsConfirmationError = function dispatchPaymentElementsConfirmationError(a0, r7 = true, r6 = intl.string(t.khEaRI)) { return dispatchConfirmationError(a0, r7, r6, { tags: { source: "payment_elements" } }); }; validateSetupIntentResponse = function validateSetupIntentResponse(a0, a1, a2) { if (a1 != null) { throw a2(a1); } if (a0 == null) { throw a2("SetupIntent not created"); } if (a0.payment_method == null) { throw a2("setupIntent.payment_method not available with successful stripe call"); } Module38(typeof a0.payment_method === "string", "setupIntent.payment_method expanded not supported"); return { setupIntent: a0, error: a1 }; }; submitElementsForPaymentElement = async function submitElementsForPaymentElement(c25203_0) { if (c25203_0 == null) { throw dispatchPaymentElementsConfirmationError("Stripe Elements not loaded", true); } let c29365_0 = await c25203_0.submit(); c2722_11.info("Stripe Elements submit response: ", c29365_0); if (c29365_0.error != null) { c2722_11.error("Stripe Elements submit error: ", c29365_0.error); throw (0, dispatchPaymentElementsConfirmationError)(c29365_0.error, true); } return c29365_0; }; createStripePaymentMethodWithElements = async function createStripePaymentMethodWithElements(c25204_0, elements) { let c29366_0 = await c25204_0.createPaymentMethod({ elements }); let c29366_1 = c29366_0.paymentMethod; let c29366_2 = c29366_0.error; if (c29366_2 != null) { c2722_11.error("Stripe createPaymentMethod error: ", c29366_2); throw (0, dispatchPaymentElementsConfirmationError)(c29366_2, true); } if (c29366_1 == null) { c2722_11.warn("Stripe createPaymentMethod failed to return payment method: ", { paymentMethod: c29366_1, error: c29366_2 }); throw (0, dispatchPaymentElementsConfirmationError)("paymentMethod not available with successful stripe call", true); } c2722_21.hasCreatedPaymentMethod = true; return { paymentMethod: c29366_1, error: c29366_2 }; }; createStripePaymentSourceToken = async function createStripePaymentSourceToken(c25211_0) { let id; let country; let c29373_0, c29373_1, c29373_2, c29373_3, c29373_4, c29373_5, c29373_6, c29373_7, c29373_8, c29373_9, c29373_10, c29373_11, c29373_12, c29373_13, c29373_14; L45: { L34: { c29373_0 = c25211_0; c29373_1 = void 0; c29373_2 = void 0; c29373_3 = void 0; c29373_4 = void 0; c29373_5 = void 0; c29373_6 = void 0; c29373_7 = void 0; c29373_8 = void 0; c29373_9 = void 0; c29373_10 = void 0; c29373_11 = void 0; c29373_12 = void 0; c29373_13 = void 0; c29373_14 = void 0; if (VAULTABLE_PAYMENT_SOURCES.has(c25211_0.type)) { break L45; } c29373_1 = await getStripe(); if (c29373_1 == null) { throw new BillingError("Stripe not loaded", BillingError.ErrorCodes.UNKNOWN); } c29373_2 = c29373_0.billingAddress; c29373_3 = c29373_2.email; c29373_4 = c29373_2.name; c29373_5 = c29373_2.line1; c29373_6 = c29373_2.line2; c29373_7 = c29373_2.city; c29373_8 = c29373_2.state; c29373_9 = c29373_2.postalCode; c29373_10 = c29373_2.country; c29373_11 = { billing_details: { address: { line1: c29373_5, line2: c29373_6, city: c29373_7, state: c29373_8, postal_code: c29373_9, country: c29373_10 }, name: c29373_4 } }; const type = c29373_0.type; if (PaymentSourceTypes.GIROPAY === type) { c29373_11.type = "giropay"; } else if (PaymentSourceTypes.SOFORT === type) { c29373_11.type = "sofort"; const r115 = c29373_11; country = c29373_10; if (country == null) { country = ""; } r115.sofort = { country }; c29373_11.billing_details.email = c29373_3; } else if (PaymentSourceTypes.BANCONTACT === type) { c29373_11.type = "bancontact"; } else if (PaymentSourceTypes.IDEAL === type) { c29373_11.type = "ideal"; c29373_11.ideal = { bank: c29373_0.bank }; } else if (PaymentSourceTypes.PRZELEWY24 === type) { if (c29373_0.bank == null) { throw new BillingError("p24 missing bank information", BillingError.ErrorCodes.UNKNOWN_PAYMENT_SOURCE); } c29373_11.type = "p24"; c29373_11.p24 = { bank: c29373_0.bank }; c29373_11.billing_details.email = c29373_0.email; } else if (PaymentSourceTypes.EPS === type) { if (c29373_0.bank == null) { throw new BillingError("EPS missing bank information", BillingError.ErrorCodes.UNKNOWN_PAYMENT_SOURCE); } c29373_11.type = "eps"; c29373_11.eps = { bank: c29373_0.bank }; } else if (PaymentSourceTypes.PIX === type) { c29373_11.type = "pix"; c29373_11.billing_details.email = c29373_0.email; c29373_11.billing_details.tax_id = c29373_0.pixMetadata?.taxId; } Module38(c29373_11.type != null, "unsupported payment method type"); c29373_12 = await c29373_1.createPaymentMethod(c29373_11); c29373_13 = c29373_12.paymentMethod; c29373_14 = c29373_12.error; if (c29373_14 == null && c29373_13 != null) { id = c29373_13.id; break L34; } throw new BillingError(`Unable to create payment source token: code: ${c29373_14?.code} message: ${c29373_14?.message}`, BillingError.ErrorCodes.UNKNOWN); } return id; } return null; }; const PaymentSourceTypes2 = PaymentSourceTypes; c2722_11 = new Logger("BillingPaymentGatewayActionCreators.tsx"); c2722_21 = { hasCreatedPaymentMethod: false }; c2722_25 = new Set([PaymentSourceTypes2.CARD, PaymentSourceTypes2.PAYMENT_REQUEST]); export function createAdyenPaymentSourceToken(a0) { const r7 = VAULTABLE_PAYMENT_SOURCES.has(a0.type); let r8 = null; if (!r7) { const r10 = JSON; let type = ADYEN_PAYMENT_SOURCES.get(a0.type); if (type == null) { type = null; } r8 = r10.stringify({ type }); } return r8; } export { dispatchPaymentElementsConfirmationError }; export async function createCardToken(c25199_0, c25199_1) { let id; let c29361_0, c29361_1, c29361_2; L18: { c29361_0 = void 0; c29361_1 = void 0; c29361_2 = void 0; if (c25199_0 != null && c25199_1 != null) { const element = c25199_1.getElement(CardNumberElement); if (element == null) { throw dispatchConfirmationError("Unable to load card elements from Stripe"); } c29361_0 = await c25199_0.createToken(element); c29361_1 = c29361_0.token; c29361_2 = c29361_0.error; if (c29361_2 != null) { throw dispatchConfirmationError(c29361_2); } if (c29361_1 == null) { throw dispatchConfirmationError("token not available with successful stripe call"); } id = c29361_1.id; break L18; } throw dispatchConfirmationError("Stripe or elements not loaded"); } return id; } export async function confirmEPS(c25200_0, c25200_1, c25200_2, c25200_3) { let c29362_0 = c25200_0; let c29362_1 = c25200_1; let c29362_2 = c25200_2; let c29362_3 = c25200_3; if (c25200_0 == null) { throw dispatchConfirmationError("Stripe not loaded"); } if (c25200_1 == null) { throw dispatchConfirmationError("Bank required for EPS"); } let c29362_4 = c25200_2.email; const name = c25200_2.name; let c29362_5 = name; let c29362_6 = c25200_2.line1; let c29362_7 = c25200_2.line2; let c29362_8 = c25200_2.city; let c29362_9 = c25200_2.state; let c29362_10 = c25200_2.postalCode; let c29362_11 = c25200_2.country; if (name == null) { throw dispatchConfirmationError("Name required for EPS"); } Dispatcher.dispatch({ type: "BILLING_PAYMENT_SOURCE_CREATE_START" }); let c29362_12 = await validatePaymentSourceBillingAddress(c25200_2); let c29362_13 = await c29362_0.createPaymentMethod({ type: "eps", eps: { bank: c29362_1 }, billing_details: { address: { line1: c29362_6, line2: c29362_7, city: c29362_8, state: c29362_9, postal_code: c29362_10, country: c29362_11 }, name: c29362_5, email: c29362_4 } }); let c29362_14 = c29362_13.paymentMethod; let c29362_15 = c29362_13.error; if (c29362_15 != null) { throw dispatchConfirmationError(c29362_15); } if (c29362_14 == null) { throw dispatchConfirmationError("paymentMethod not available with successful stripe call"); } return createPaymentSource(PaymentGateways.STRIPE, c29362_14.id, c29362_2, { billingAddressToken: c29362_12, analyticsLocation: c29362_3, bank: c29362_1 }); } export async function confirmIdeal(c25201_0, c25201_1, c25201_2) { let c29363_0 = c25201_0; let c29363_1 = c25201_1; let c29363_2 = c25201_2; if (c25201_0 == null) { throw dispatchConfirmationError("Stripe not loaded"); } let c29363_3 = c25201_1.email; const name = c25201_1.name; let c29363_4 = name; let c29363_5 = c25201_1.line1; let c29363_6 = c25201_1.line2; let c29363_7 = c25201_1.city; let c29363_8 = c25201_1.state; let c29363_9 = c25201_1.postalCode; let c29363_10 = c25201_1.country; if (name == null) { throw dispatchConfirmationError("Name required for iDEAL"); } Dispatcher.dispatch({ type: "BILLING_PAYMENT_SOURCE_CREATE_START" }); let c29363_11 = await validatePaymentSourceBillingAddress(c25201_1); let c29363_12 = await c29363_0.createPaymentMethod({ type: "ideal", ideal: {}, billing_details: { address: { line1: c29363_5, line2: c29363_6, city: c29363_7, state: c29363_8, postal_code: c29363_9, country: c29363_10 }, name: c29363_4, email: c29363_3 } }); let c29363_13 = c29363_12.paymentMethod; let c29363_14 = c29363_12.error; if (c29363_14 != null) { throw dispatchConfirmationError(c29363_14); } if (c29363_13 == null) { throw dispatchConfirmationError("paymentMethod not available with successful stripe call"); } return createPaymentSource(PaymentGateways.STRIPE, c29363_13.id, c29363_1, { billingAddressToken: c29363_11, analyticsLocation: c29363_2 }); } export async function confirmPrzelewy24(c25202_0, c25202_1, c25202_2, c25202_3) { let c29364_0 = c25202_0; let c29364_1 = c25202_1; let c29364_2 = c25202_2; let c29364_3 = c25202_3; if (c25202_0 == null) { throw dispatchConfirmationError("Stripe not loaded"); } const email = c25202_2.email; let c29364_4 = email; let c29364_5 = c25202_2.name; let c29364_6 = c25202_2.line1; let c29364_7 = c25202_2.line2; let c29364_8 = c25202_2.city; let c29364_9 = c25202_2.state; let c29364_10 = c25202_2.postalCode; let c29364_11 = c25202_2.country; if (email == null) { throw dispatchConfirmationError("Email required for Przelewy24"); } Dispatcher.dispatch({ type: "BILLING_PAYMENT_SOURCE_CREATE_START" }); let c29364_12 = await validatePaymentSourceBillingAddress(c25202_2); let c29364_13 = c29364_1.p24Bank; let c29364_14 = await c29364_0.createPaymentMethod({ type: "p24", p24: { bank: c29364_13 }, billing_details: { address: { line1: c29364_6, line2: c29364_7, city: c29364_8, state: c29364_9, postal_code: c29364_10, country: c29364_11 }, name: c29364_5, email: c29364_4 } }); let c29364_15 = c29364_14.paymentMethod; let c29364_16 = c29364_14.error; if (c29364_16 != null) { throw dispatchConfirmationError(c29364_16); } if (c29364_15 == null) { throw dispatchConfirmationError("paymentMethod not available with successful stripe call"); } return createPaymentSource(PaymentGateways.STRIPE, c29364_15.id, c29364_2, { billingAddressToken: c29364_12, analyticsLocation: c29364_3, bank: c29364_13 }); } export { submitElementsForPaymentElement }; export async function submitElementsAndCreateStripePaymentMethod(c25205_0, c25205_1) { let c29367_0 = c25205_0; let c29367_1 = c25205_1; if (c25205_0 == null) { throw dispatchPaymentElementsConfirmationError("Stripe not loaded", true); } if (c25205_1 == null) { throw dispatchPaymentElementsConfirmationError("Stripe Elements not loaded", true); } await submitElementsForPaymentElement(c25205_1); let c29367_2 = await (0, createStripePaymentMethodWithElements)(c29367_0, c29367_1); return { paymentMethod: c29367_2.paymentMethod, error: c29367_2.error }; } export async function confirmPaymentElementSource(...c25206_0) { let r48, r49, r50, r51, r204, r296, r439, paymentSource; let c25206_1, c25206_2, c25206_3, c25206_4, c25206_5, current, setupIntent, c25206_8, c25206_9, c25206_10; let c25206_11 = 0; const r24 = env2722; try { let env29368; c25206_9 = r24; const r75 = env29368 = { $parent: r24 }; c25206_8 = r75; env29368[0] = void 0; env29368[1] = void 0; env29368[2] = void 0; env29368[3] = void 0; env29368[4] = void 0; env29368[5] = void 0; env29368[6] = void 0; c25206_2 = c25206_0; const r30 = c25206_0[Symbol.iterator](); const next = r30.next; c25206_2 = next; c25206_1 = r30; c25206_3 = void 0; c25206_4 = void 0; let r78 = r30; const r79 = r78 === void 0 ? void 0 : (r48 = next.call(r78)).done ? r78 = void 0 : r48.value; const r32 = r78; c25206_1 = r32; let r80 = r32 === void 0; c25206_3 = r80; if (!r80) { c25206_4 = r79; } env29368[0] = c25206_4; c25206_4 = void 0; let r82 = r32; if (!r80) { const r31 = c25206_2; let r84 = r32; const r85 = r84 === void 0 ? void 0 : (r49 = r31.call(r84)).done ? r84 = void 0 : r49.value; c25206_1 = r84; const r86 = r84 === void 0; c25206_3 = r86; r80 = r86; r82 = r84; if (!r86) { c25206_4 = r85; r80 = r86; r82 = r84; } } env29368[1] = c25206_4; c25206_11 = 0; c25206_4 = void 0; if (!r80) { const r93 = c25206_2; let r94 = r82; const r95 = r94 === void 0 ? void 0 : (r50 = r93.call(r94)).done ? r94 = void 0 : r50.value; c25206_1 = r94; const r96 = r94 === void 0; c25206_3 = r96; if (!r96) { c25206_4 = r95; } } c25206_11 = 2; const r87 = c25206_4; env29368[2] = r87.billingAddress; env29368[3] = r87.paymentSourceType; env29368[4] = r87.lastConfirmedSetupIntentRef; env29368[5] = r87.createSetupIntent; c25206_11 = 0; c25206_4 = void 0; let r92 = c25206_3; if (!r92) { const r98 = c25206_2; let r99 = c25206_1; const r100 = r99 === void 0 ? void 0 : (r51 = r98.call(r99)).done ? r99 = void 0 : r51.value; c25206_1 = r99; const r101 = r99 === void 0; c25206_3 = r101; r92 = r101; if (!r101) { c25206_4 = r100; r92 = r101; } } env29368[6] = c25206_4; if (!r92) { const r103 = c25206_1; if (r103 !== void 0 && typeof r103.return === "function") { r103.return(); } } env29368[7] = void 0; env29368[8] = void 0; env29368[9] = void 0; env29368[10] = void 0; env29368[11] = void 0; env29368[12] = void 0; env29368[13] = void 0; env29368[14] = void 0; env29368[15] = void 0; await void 0; if (env29368[0] == null) { throw (0, dispatchPaymentElementsConfirmationError)("Stripe not loaded", true); } if (env29368[1] == null) { throw (0, dispatchPaymentElementsConfirmationError)("Stripe Elements not loaded", true); } Dispatcher.dispatch({ type: "BILLING_PAYMENT_SOURCE_CREATE_START" }); const r163 = await validatePaymentSourceBillingAddress(env29368[2]); L43: { L36: { env29368[7] = r163; if (env29368[3] !== PaymentSourceTypes.PAYMENT_REQUEST) { await (0, submitElementsForPaymentElement)(env29368[1]); env29368[9] = null; const r536 = c2722_25.has(env29368[3]); r204 = c25206_8; if (r536) { break L36; } } else { env29368[9] = null; const r203 = c2722_25.has(env29368[3]); r204 = c25206_8; if (r203) { break L36; } } env29368[14] = (await (0, createStripePaymentMethodWithElements)(env29368[0], env29368[1])).paymentMethod; env29368[9] = env29368[14].id; if (env29368[3] !== PaymentSourceTypes.PIX) { break L43; } env29368[15] = env29368[14].billing_details; if (env29368[15]?.tax_id != null && env29368[15].tax_id !== "") { env29368[8] = { taxId: env29368[15].tax_id }; break L43; } throw (0, dispatchPaymentElementsConfirmationError)("Missing PIX tax_id from Payment Element", true); } current = env29368[4].current; if (current == null) { current = void 0; } env29368[11] = current; if (env29368[11] != null && env29368[3] === PaymentSourceTypes.PAYMENT_REQUEST) { setupIntent = env29368[11]; if (setupIntent == null) { setupIntent = void 0; } const r293 = c25206_8; env29368[10] = { setupIntent, error: void 0 }; r296 = r293; } else { if (env29368[3] === PaymentSourceTypes.CARD && c2722_21.hasCreatedPaymentMethod) { await (0, createStripePaymentMethodWithElements)(env29368[0], env29368[1]); r439 = env29368[0].confirmSetup({ redirect: "if_required", elements: env29368[1] }); } else { r439 = env29368[0].confirmSetup({ redirect: "if_required", elements: env29368[1] }); } const r445 = await r439; r296 = c25206_8; env29368[10] = r445; } if ((function shouldRecreateSetupIntentForPaymentElement(a0) { return a0 != null && a0.code === "setup_intent_unexpected_state" && a0.setup_intent != null && (a0.setup_intent.status === "succeeded" || a0.setup_intent.status === "canceled"); })(env29368[10].error) && env29368[3] !== PaymentSourceTypes.PAYMENT_REQUEST) { env29368[12] = (await (0, env29368[5])()).client_secret; await (0, submitElementsForPaymentElement)(env29368[1]); env29368[10] = await env29368[0].confirmSetup({ redirect: "if_required", clientSecret: env29368[12], elements: env29368[1] }); } env29368[13] = validateSetupIntentResponse(env29368[10].setupIntent, env29368[10].error, $mk114561(env2722)).setupIntent; env29368[4].current = env29368[13]; env29368[9] = env29368[13].payment_method; } paymentSource = createPaymentSource(PaymentGateways.STRIPE, env29368[9], env29368[2], { billingAddressToken: env29368[7], analyticsLocation: env29368[6], pix: env29368[8] }); } catch ($e) { const r73 = $e; let r8 = r73; c25206_10 = r73; let r74 = c25206_11; if (r74 !== 0) { while (true) { if (r74 === 1) { try { const r549 = c25206_10; c25206_11 = 0; c25206_5 = r549; if (!c25206_3) { const r553 = c25206_1; if (r553 !== void 0 && typeof r553.return === "function") { try { r553.return(); } catch {} } } throw c25206_5; } catch (r548) { r8 = r548; c25206_10 = r548; r74 = c25206_11; if (r74 === 0) { break; } } } else { try { const r541 = c25206_10; c25206_11 = 0; c25206_5 = r541; if (!c25206_3) { const r545 = c25206_1; if (r545 !== void 0 && typeof r545.return === "function") { try { r545.return(); } catch {} } } throw c25206_5; } catch (r540) { r8 = r540; c25206_10 = r540; r74 = c25206_11; if (r74 === 0) { break; } } } } } throw r8; } return paymentSource; } export async function confirmCardPaymentSource(c25207_0, c25207_1, c25207_2, c25207_3) { let paymentSource; let c25207_4, c25207_5, c25207_6; let c25207_7 = 0; const r11 = env2722; L16: { try { let env29369; c25207_5 = r11; const r40 = env29369 = { $parent: r11 }; c25207_4 = r40; env29369[0] = c25207_0; env29369[1] = c25207_1; env29369[2] = c25207_2; env29369[3] = c25207_3; env29369[4] = void 0; env29369[5] = void 0; env29369[6] = void 0; env29369[7] = void 0; env29369[8] = void 0; if (c25207_0 != null && c25207_1 != null) { Dispatcher.dispatch({ type: "BILLING_PAYMENT_SOURCE_CREATE_START" }); env29369[4] = null; c25207_7 = 1; env29369[4] = (await createStripeSetupIntent()).client_secret; c25207_7 = 0; env29369[5] = await validatePaymentSourceBillingAddress(env29369[2]); env29369[6] = parseBillingAddressInfoToStripeBillingDetails(env29369[2]); env29369[7] = await env29369[0].confirmCardSetup(env29369[4], { payment_method: { card: { token: env29369[1] }, billing_details: env29369[6] } }); env29369[8] = validateSetupIntentResponse(env29369[7].setupIntent, env29369[7].error, $mk114562(env2722)).setupIntent; paymentSource = createPaymentSource(PaymentGateways.STRIPE, env29369[8].payment_method, env29369[2], { billingAddressToken: env29369[5], analyticsLocation: env29369[3] }); break L16; } throw dispatchConfirmationError("Stripe or token not loaded"); } catch ($e) { const r38 = $e; let r8 = r38; c25207_6 = r38; if (c25207_7 !== 0) { while (true) { try { const r170 = c25207_6; c25207_7 = 0; env29369[9] = r170; throw dispatchConfirmationError(env29369[9]); } catch (r166) { r8 = r166; c25207_6 = r166; if (c25207_7 === 0) { break; } } } } throw r8; } } return paymentSource; } export function createPaymentRequestPaymentSource(a0, a1, a2) { let r6 = a1; const r15 = parseStripePaymentMethod(a0); const { token, billingAddressInfo } = r15; const STRIPE = PaymentGateways.STRIPE; if (a1 == null) { r6 = billingAddressInfo; } return createPaymentSource(STRIPE, token, r6, { analyticsLocation: a2 }); } export function createBraintreePaymentSource(a0, a1, a2) { return createPaymentSource(PaymentGateways.BRAINTREE, a0, a1, { analyticsLocation: a2 }); } export async function createStripePaymentSource(c25208_0, c25208_1, c25208_2, c25208_3) { let c29370_0 = c25208_0; let c29370_1 = c25208_1; let c29370_2 = c25208_2; let c29370_3 = c25208_3; if (c25208_0 == null) { throw dispatchConfirmationError("Stripe not loaded"); } let c29370_4 = await validatePaymentSourceBillingAddress(c25208_1); let c29370_5 = c29370_1.name; let c29370_6 = c29370_1.line1; let c29370_7 = c29370_1.line2; let c29370_8 = c29370_1.city; let c29370_9 = c29370_1.state; let c29370_10 = c29370_1.postalCode; let c29370_11 = c29370_1.country; let c29370_12 = STRIPE_PAYMENT_SOURCES.get(c29370_2); Module38(c29370_12 != null, "unsupported payment method type"); let c29370_13 = await c29370_0.createPaymentMethod({ type: c29370_12, billing_details: { address: { line1: c29370_6, line2: c29370_7, city: c29370_8, state: c29370_9, postal_code: c29370_10, country: c29370_11 }, name: c29370_5 } }); let c29370_14 = c29370_13.paymentMethod; let c29370_15 = c29370_13.error; if (c29370_15 != null) { throw dispatchConfirmationError(c29370_15); } if (c29370_14 == null) { throw dispatchConfirmationError("stripePaymentMethod not available with successful stripe call"); } return createPaymentSource(PaymentGateways.STRIPE, c29370_14.id, c29370_1, { billingAddressToken: c29370_4, analyticsLocation: c29370_3 }); } export async function createAdyenPrepaidPaymentSource(c25209_0, c25209_1, c25209_2) { let c29371_0 = c25209_0; let c29371_1 = c25209_1; let c29371_2 = c25209_2; let c29371_3 = await validatePaymentSourceBillingAddress(c25209_0); let c29371_4 = { type: ADYEN_PAYMENT_SOURCES.get(c29371_1) }; return createPaymentSource(PaymentGateways.ADYEN, JSON.stringify(c29371_4), c29371_0, { billingAddressToken: c29371_3, analyticsLocation: c29371_2 }); } export async function createAdyenVaultablePaymentSource(c25210_0, c25210_1, c25210_2, c25210_3, c25210_4) { let paymentMethod, c25210_6, value, c25210_8, c25210_9, c25210_11; let c25210_10 = 0; const r18 = env2722; let r10 = "redirect url cannot be null on a redirect for adyen."; try { let env29372; c25210_9 = r18; const r51 = env29372 = {}; c25210_8 = r51; env29372[4] = void 0; env29372[0] = c25210_0; env29372[1] = c25210_1; env29372[2] = c25210_2; env29372[3] = c25210_3; if (c25210_4 !== void 0) { env29372[4] = c25210_4; env29372[5] = void 0; env29372[6] = void 0; env29372[7] = void 0; env29372[8] = void 0; env29372[9] = void 0; } else { env29372[4] = false; env29372[5] = void 0; env29372[6] = void 0; env29372[7] = void 0; env29372[8] = void 0; env29372[9] = void 0; } await void 0; r10 = "redirect url cannot be null on a redirect for adyen."; const r41 = await validatePaymentSourceBillingAddress(env29372[0]); r10 = "redirect url cannot be null on a redirect for adyen."; env29372[5] = r41; const r118 = { type: ADYEN_PAYMENT_SOURCES.get(env29372[1]) }; const paymentMethod2 = env29372[3]?.paymentMethod; paymentMethod = paymentMethod2; if (paymentMethod2 == null) { paymentMethod = {}; } HermesBuiltin.copyDataProperties(r118, paymentMethod); env29372[6] = r118; const r43 = await popupBridgeState(env29372[1]); r10 = "redirect url cannot be null on a redirect for adyen."; env29372[7] = r43; const aPIBaseURL = getAPIBaseURL(); const r166 = env29372[1]; const r167 = env29372[7]; c25210_6 = r167; if (r167 == null) { c25210_6 = ""; } env29372[8] = aPIBaseURL + Endpoints.BILLING_POPUP_BRIDGE_CALLBACK_REDIRECT_PREFIX(r166, c25210_6, "success"); c25210_10 = 1; value = {}; const paymentSource = await createPaymentSource(PaymentGateways.ADYEN, JSON.stringify(env29372[6]), env29372[0], { billingAddressToken: env29372[5], analyticsLocation: env29372[2], returnUrl: env29372[8] }, env29372[4]); r10 = "redirect url cannot be null on a redirect for adyen."; value.paymentSource = paymentSource; value.redirectConfirmation = false; c25210_10 = 0; } catch ($e) { const r49 = $e; let r8 = r49; c25210_11 = r49; if (c25210_10 !== 0) { while (true) { try { const r224 = c25210_11; c25210_10 = 0; env29372[10] = r224; if (env29372[10].code !== ErrorCodes.CONFIRMATION_REQUIRED) { Dispatcher.dispatch({ type: "BILLING_PAYMENT_SOURCE_CREATE_FAIL", error: new BillingError(`Unable to create payment source token: code: ${env29372[10]?.code} message: ${env29372[10]?.message}`, BillingError.ErrorCodes.UNKNOWN) }); throw env29372[10]; } env29372[9] = env29372[10].fields.adyen_redirect_url; if (env29372[9] == null) { throw dispatchConfirmationError(r10); } (function performRedirect(a0) { window.open(a0); })(env29372[9]); } catch (r220) { r8 = r220; c25210_11 = r220; if (c25210_10 === 0) { break; } continue; } return { redirectConfirmation: true }; } } throw r8; } return value; } export { createStripePaymentSourceToken }; export function createPaymentSourceToken(a0) { let r15; const r10 = VAULTABLE_PAYMENT_SOURCES.has(a0.type); let r11 = null; if (!r10) { if (ADYEN_PAYMENT_SOURCES.has(a0.type)) { const r18 = VAULTABLE_PAYMENT_SOURCES.has(a0.type); let r19 = null; if (!r18) { const r21 = JSON; let type = ADYEN_PAYMENT_SOURCES.get(a0.type); if (type == null) { type = null; } r19 = r21.stringify({ type }); } r15 = r19; } else { r15 = createStripePaymentSourceToken(a0); } r11 = r15; } return r11; } export async function paymentIntentSucceeded(c25212_0) { let env29374; const r27 = env2722; let c25212_2 = r27; const r10 = env29374 = { $parent: r27 }; let c25212_1 = r10; env29374[0] = c25212_0; env29374[1] = void 0; env29374[2] = void 0; env29374[3] = void 0; env29374[4] = void 0; env29374[5] = void 0; env29374[1] = await getStripe(); if (env29374[1] == null) { throw dispatchConfirmationError("Stripe has not loaded."); } if (env29374[0] == null) { throw dispatchConfirmationError("payment intent id cannot be null."); } const r72 = env29374[0]; env29374[2] = await $mk114564(env2722)(r72); env29374[3] = await env29374[1].retrievePaymentIntent(env29374[2]); env29374[4] = env29374[3].paymentIntent; env29374[5] = env29374[3].error; if (env29374[5] != null) { throw dispatchConfirmationError(env29374[5]); } if (env29374[4] == null) { throw dispatchConfirmationError("paymentIntent not available with successful stripe call"); } if (env29374[4].last_payment_error != null) { throw dispatchConfirmationError(`unable to retrieve payment intent ${env29374[4].last_payment_error}`); } return true; }