UNPKG

@getopenpay/openpay-js-react

Version:

Accept payments through OpenPay, right on your site

1,774 lines 1.25 MB
import { connectToChild as co } from "penpal"; import { z as n } from "zod"; import je from "chalk"; import { v4 as Ke } from "uuid"; import { jsx as Ee, Fragment as Ar } from "react/jsx-runtime"; import { createContext as Qa, useContext as Xa, useState as fe, useRef as ei, useMemo as Ir, useEffect as Or } from "react"; function ti(e, t) { var r = Object.setPrototypeOf; r ? r(e, t) : e.__proto__ = t; } function ri(e, t) { t === void 0 && (t = e.constructor); var r = Error.captureStackTrace; r && r(e, t); } var ni = /* @__PURE__ */ (function() { var e = function(r, o) { return e = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(a, i) { a.__proto__ = i; } || function(a, i) { for (var s in i) Object.prototype.hasOwnProperty.call(i, s) && (a[s] = i[s]); }, e(r, o); }; return function(t, r) { if (typeof r != "function" && r !== null) throw new TypeError("Class extends value " + String(r) + " is not a constructor or null"); e(t, r); function o() { this.constructor = t; } t.prototype = r === null ? Object.create(r) : (o.prototype = r.prototype, new o()); }; })(); (function(e) { ni(t, e); function t(r, o) { var a = this.constructor, i = e.call(this, r, o) || this; return Object.defineProperty(i, "name", { value: a.name, enumerable: !1, configurable: !0 }), ti(i, a.prototype), ri(i), i; } return t; })(Error); const N = n.string().trim().min(1, { message: "Please fill in this field" }), E = n.string().trim().optional(), G = (e) => n.nullable(e.optional()); var F = /* @__PURE__ */ ((e) => (e.FIRST_NAME = "firstName", e.LAST_NAME = "lastName", e.PHONE = "phone", e.EMAIL = "email", e.LINE1 = "line1", e.LINE2 = "line2", e.LINE3 = "line3", e.CITY = "city", e.STATE = "state", e.COUNTRY = "country", e.ZIP_CODE = "zipCode", e.SHIPPING_LINE1 = "shippingAddressLine1", e.SHIPPING_LINE2 = "shippingAddressLine2", e.SHIPPING_LINE3 = "shippingAddressLine3", e.SHIPPING_CITY = "shippingAddressCity", e.SHIPPING_STATE = "shippingAddressState", e.SHIPPING_COUNTRY = "shippingAddressCountry", e.SHIPPING_ZIP_CODE = "shippingAddressZipCode", e.IS_SHIPPING_SAME_AS_BILLING = "isShippingSameAsBilling", e.PROMOTION_CODE = "promotionCode", e.IS_BUSINESS_PURCHASE = "isBusinessPurchase", e.BUSINESS_NAME = "businessName", e.TAX_ID = "taxId", e.TAX_ID_TYPE = "taxIdType", e))(F || {}); const lo = n.nativeEnum(F); var uo = /* @__PURE__ */ ((e) => (e.CARD_NUMBER = "cardNumber", e.CARD_EXPIRY = "cardExpiry", e.CARD_CVC = "cardCvc", e))(uo || {}); const po = n.nativeEnum(uo), oi = n.union([lo, po]); var Rt = /* @__PURE__ */ ((e) => (e.CARD = "card", e.CARD_NUMBER = "card-number", e.CARD_EXPIRY = "card-expiry", e.CARD_CVC = "card-cvc", e.CDE_BRIDGE = "cde-bridge", e))(Rt || {}); n.enum(["card", "card-number", "card-expiry", "card-cvc", "cde-bridge"]); const ur = n.object({ provider: n.string(), processor_name: G(n.string()), metadata: G(n.record(n.string(), n.any())) }), ai = n.object({ id: n.string() }), dr = n.object({ backgroundColor: E, color: E, fontFamily: E, fontSize: E, fontWeight: E, margin: E, padding: E, letterSpacing: E, lineHeight: E, hideIcon: E, placeholderStyle: n.object({ color: E, fontSize: E, fontWeight: E, fontFamily: E, letterSpacing: E, lineHeight: E }).optional() }); dr.extend({ disableAutoFill: E, placeholder: n.object({ cardNumber: E, expiry: E, cvc: E }).optional() }); dr.extend({ disableAutoFill: E, placeholder: n.string().optional(), /** * The card icon at the start of the card number input field * It won't affect after the icon changed to card brand after the user input the card number */ icon: n.object({ color: n.string().optional() }).optional() }); dr.extend({ disableAutoFill: E, placeholder: n.string().optional() }); dr.extend({ disableAutoFill: E, placeholder: n.string().optional() }); const Pe = n.enum([ // Element -> Form "LAYOUT", "LOADED", "BLUR", "FOCUS", "CHANGE", "TOKENIZE_STARTED", "CHECKOUT_STARTED", "PAYMENT_FLOW_STARTED", "TOKENIZE_SUCCESS", "CHECKOUT_SUCCESS", "LOAD_ERROR", "VALIDATION_ERROR", "TOKENIZE_ERROR", "CHECKOUT_ERROR", "SETUP_PAYMENT_METHOD_SUCCESS", // Form -> Element "TOKENIZE", "CHECKOUT", "START_PAYMENT_FLOW" ]), ii = Pe.extract(["TOKENIZE_STARTED", "CHECKOUT_STARTED"]), si = n.object({ type: ii }), ci = Pe.extract(["BLUR", "FOCUS", "CHANGE"]), li = n.object({ type: ci, elementType: po, errors: n.array(n.string()).optional(), obfuscatedValue: n.string().optional() }), ui = Pe.extract(["LOAD_ERROR", "TOKENIZE_ERROR", "CHECKOUT_ERROR"]), di = n.object({ type: ui, message: N, headers: n.record(n.string(), n.string()).optional() }), pi = Pe.extract(["VALIDATION_ERROR"]), mi = n.object({ type: pi, elementType: oi, errors: n.array(n.string()) }), fi = n.object({ type: n.literal(Pe.enum.LAYOUT), height: N }), hi = n.object({ type: n.literal(Pe.enum.LOADED), sessionId: N, totalAmountAtoms: n.number(), currency: E, checkoutPaymentMethods: n.array(ur) }), _i = n.object({ type: n.literal(Pe.enum.PAYMENT_FLOW_STARTED), nextActionMetadata: n.record(n.string(), n.any()), paymentFlowMetadata: n.any().optional(), startPFMetadata: n.optional(n.record(n.string(), n.any())) }), yi = n.object({ type: n.literal(Pe.enum.SETUP_PAYMENT_METHOD_SUCCESS), paymentMethodId: n.string() }), rt = n.object({ email: N.email({ message: "Please enter a valid email address" }), firstName: N, lastName: N, phone: E, promotionCode: E, line1: E, line2: E, line3: E, city: E, state: E, country: N, zipCode: E, isShippingSameAsBilling: n.custom().optional().default(!0), shippingAddressLine1: E, shippingAddressLine2: E, shippingAddressLine3: E, shippingAddressCity: E, shippingAddressState: E, shippingAddressCountry: E, shippingAddressZipCode: E, businessName: E, taxId: E, taxIdType: E }), gi = n.object({ email: N.email({ message: "Please enter a valid email address" }), firstName: E, lastName: E, phone: E, promotionCode: E, line1: E, line2: E, line3: E, city: E, state: E, country: N, zipCode: E, isShippingSameAsBilling: n.custom().optional().default(!0), shippingAddressLine1: E, shippingAddressLine2: E, shippingAddressLine3: E, shippingAddressCity: E, shippingAddressState: E, shippingAddressCountry: E, shippingAddressZipCode: E, businessName: E, taxId: E, taxIdType: E }); n.object({ line1: N, city: N, state: N, country: N }); n.object({ shippingAddressCountry: N, shippingAddressZipCode: N }); n.object({ shippingAddressLine1: N, shippingAddressCity: N, shippingAddressState: N, shippingAddressCountry: N, shippingAddressZipCode: N }); const wi = Pe.extract(["TOKENIZE", "CHECKOUT", "START_PAYMENT_FLOW"]), bi = n.object({ type: wi, sessionId: N, checkoutPaymentMethod: ur, paymentFlowMetadata: n.any().optional(), doNotUseLegacyCCFlow: n.boolean().optional(), existingCCPMId: E, paymentRouteId: E }).extend(rt.shape), vi = n.object({ type: n.literal(Pe.enum.TOKENIZE_SUCCESS), isReadyForCheckout: n.boolean() }), Ei = n.object({ type: n.literal(Pe.enum.CHECKOUT_SUCCESS), invoiceUrls: n.array(n.string()), subscriptionIds: n.array(n.string()), customerId: n.string(), paymentMethodId: E }), Pi = n.discriminatedUnion("type", [ si, li, di, mi, fi, hi, bi, vi, Ei, _i, yi ]); n.object({ payload: Pi, nonce: N, formId: N, elementId: N }); n.object({ amountAtom: n.number(), /** * The three-letter ISO 4217 currency code for the payment. */ currency: N }); n.enum(["apple_pay", "google_pay"]); n.object({ secure_token: n.string(), promotion_code: n.string().optional() }); n.object({ secure_token: n.string(), existing_cc_pm_id: G(n.string()), their_pm_id: G(n.string()), checkout_attempt_id: G(n.string()), processor_specific_metadata: G(n.record(n.string(), n.any())) }); const Dr = n.object({ invoice_urls: n.array(n.string()), subscription_ids: n.array(n.string()), customer_id: n.string(), payment_method_id: G(n.string()), processors_used: G(n.array(n.string())) }), ki = n.object({ elementType: n.string(), errors: n.array(n.string()) }); n.object({ session_id: n.string() }); const Si = n.object({ success: n.literal(!1), error_type: n.literal("validation_error"), errors: n.array(ki) }); n.discriminatedUnion("success", [ n.object({ success: n.literal(!0) }), Si ]); n.object({ session_id: n.string(), checkout_payment_method: ur, non_cde_form_fields: rt, do_not_use_legacy_cc_flow: n.boolean().optional(), existing_cc_pm_id: G(n.string()), extra_metadata: n.record(n.string(), n.any()), payment_route_id: G(n.string()), customer_language: G(n.string()) }); n.object({ session_id: n.string(), checkout_payment_method: ur, non_cde_form_fields: rt, extra_metadata: n.record(n.string(), n.any()).optional(), payment_route_id: G(n.string()), customer_language: G(n.string()) }); n.object({ status: n.enum([ "success", "failure", "cancelled" /* CANCELLED */ ]), href: n.string().optional().nullable() }); n.object({ href: n.string().optional().nullable() }); n.object({ type: n.string(), redirect_url: n.string(), initial_intent_id: n.string(), consent_id: n.string(), their_pm_id: n.string().optional() }); const Ci = n.object({ bank_name: n.string(), display_name: n.string(), resources: n.object({ logo_url: n.string().optional() }) }), Ai = n.object({ type: n.string(), redirect_url: G(n.string()), initial_intent_id: G(n.string()), consent_id: G(n.string()), their_pm_id: G(n.string()), payment_session: G(n.record(n.string(), n.any())), available_banks: G(n.array(Ci)) }); n.discriminatedUnion("present", [ n.object({ present: n.literal(!0), href: n.string() }), n.object({ present: n.literal(!1) }) ]); n.object({ payment_methods: n.array(ai), pay_first_success_response: G(Dr), required_user_actions: G(n.array(Ai)), post_checkout_redirect_to: G(n.string()), checkout_success_response: G(Dr) }); const Ii = n.object({ institutionNumber: n.string(), transitNumber: n.string(), accountNumber: n.string(), accountType: n.enum(["personal", "business"]) }); n.object({ status: n.enum(["success", "failure"]), payload: Ii.optional() }); const xi = n.object({ sortCode: n.string(), accountNumber: n.string(), accountType: n.enum(["personal", "business"]) }); n.object({ status: n.enum(["success", "failure"]), payload: xi.optional() }); const Ti = n.object({ iban: n.string(), accountType: n.enum(["personal", "business"]) }); n.object({ status: n.enum(["success", "failure"]), payload: Ti.optional() }); const Ri = n.object({ account_number: n.string(), aba_routing_number: n.string() }), Li = n.object({ institution_number: n.string(), transit_number: n.string(), account_number: n.string() }), Ni = n.object({ account_number: n.string(), sort_code: n.string() }), Mi = n.object({ iban: n.string() }); n.object({ status: n.enum(["success", "failure"]), payload: n.union([ Ri, Li, Ni, Mi, n.object({ error: n.string() }) ]).optional() }); const k = (e) => n.nullable(e.optional()); n.string().trim().min(1, { message: "Cannot be blank" }); n.object({ cde_response_type: n.literal("error"), message: n.string(), headers: n.record(n.string(), n.string()).optional() }); n.enum(["usd", "brl"]); const mo = n.object({ name: n.string(), amount_atom_off: k(n.number()), percent_off: k(n.number()), currency: k(n.string()), duration: n.string(), duration_in_months: k(n.number()) }), fo = n.object({ amount_subtotal_atom: n.number().int(), amount_total_atom: n.number().int(), currency: n.string(), description: k(n.string()), price_id: n.string(), billing_interval: k(n.string()), billing_interval_count: k(n.number().int()), quantity: n.number().int() }), ji = n.record(n.string(), n.any()), Fi = n.object({ name: n.string(), settings: k(ji) }), ct = n.object({ provider: n.string(), processor_name: k(n.string()), metadata: k(n.record(n.string(), n.any())) }), Oi = n.object({ quantity: n.number() }), Di = n.object({ id: k(n.string()), billing_interval: k(n.string()), billing_interval_count: k(n.number().int()), subscription_items: n.array(Oi), trial_start: k(n.string()), trial_end: k(n.string()) }), ho = n.object({ amount_atom: n.number() }), Ui = n.object({ amount_atom: n.number(), amount_atom_considering_discount_applied: n.number(), currency: n.string(), discount_amount_atoms: n.array(ho), subscription_item_id: n.string() }), Gi = n.object({ coupon: mo }), qi = n.object({ currency: n.string(), discounts: n.array(Gi), hosted_invoice_url: k(n.string()), lines: n.array(Ui), remaining_amount_atom: n.number(), tax_amount_atom: n.number(), total_amount_atom: n.number(), total_discount_amount_atoms: n.array(ho) }), gn = n.object({ created: n.array(Di), invoices: n.array(qi), processors_used: k(n.array(n.string())), payment_method_id: k(n.string()) }), Vi = n.object({ preview: gn, preview_post_trial: k(gn), coupons: n.array(mo) }), wn = n.object({ status: n.literal("open"), locale: k(n.string()), token: n.string(), email: k(n.string()), checkout_settings: n.record(n.string(), n.any()), line_items: n.array(fo), amount_subtotal_atom: n.number().int(), amount_total_atom: n.number().int(), brand: Fi, subs_preview: k(Vi), // Null in setup mode methods_available: n.array(ct), return_url: k(n.string()), success_url: k(n.string()), final_feature_rollout_settings: k(n.record(n.string(), n.any())) }), $i = n.discriminatedUnion("mode", [ n.object({ mode: n.literal("setup"), currency: n.nullable(n.undefined()) }).extend(wn.shape), n.object({ mode: n.enum(["payment", "subscription"]), currency: n.string() }).extend(wn.shape) ]), Hi = n.object({ status: n.literal("complete") }), Bi = n.object({ status: n.literal("expired") }); n.union([$i, Hi, Bi]); n.object({ logo: n.string(), icon: n.string(), primary_color: n.string(), secondary_color: n.string() }); n.object({ secure_token: n.string(), pm_id: n.string() }); const Jt = n.object({ line1: n.string().optional(), line2: n.string().optional(), line3: n.string().optional(), city: n.string().optional(), state: n.string().optional(), country: n.string(), zip_code: n.string().optional() }); n.object({ secure_token: n.string(), payment_input: n.any(), // Should follow AnyPaymentInput from CDE customer_email: n.string(), customer_last_name: n.string().optional(), customer_first_name: n.string().optional(), customer_address: Jt, customer_shipping_address: Jt.optional(), line_items: n.array(fo), total_amount_atom: n.number().int(), cancel_at_end: n.boolean(), checkout_payment_method: ct, promotion_code: n.string().optional(), do_not_use_legacy_cc_flow: n.boolean().optional(), use_confirmed_pm_id: k(n.string()), payment_route_id: k(n.string()) }); n.object({ payment_method_id: n.string() }); n.object({ id: n.string(), return_url: n.string() }); const zi = n.object({ type: n.string(), loc: n.array(n.string()), msg: n.string(), url: n.string() }); n.array(zi); const Ki = n.object({ new_customer_email: n.string().optional(), new_customer_last_name: n.string().optional(), new_customer_first_name: n.string().optional(), customer_business_name: n.string().optional(), customer_tax_id: n.string().optional(), customer_tax_id_type: n.string().optional(), new_customer_address: Jt, new_customer_shipping_address: Jt.optional(), customer_language: n.string().optional(), new_customer_phone: n.string().optional() }), Yi = n.object({ price_id: n.string(), quantity: n.number().int() }), _o = n.object({ line_items: n.array(Yi), promotion_code: n.string().optional(), displayed_total_amount_atom: n.number().int() }), Zi = n.object({ processor_specific_metadata: k(n.record(n.string(), n.any())) }); n.object({ payment_provider: n.string(), checkout_payment_method: ct, existing_cc_pm_id: n.string().optional(), their_existing_pm_id: n.string().optional(), use_pay_first_flow: n.boolean().optional(), pay_first_flow_cart_info: _o.optional(), customer_language: n.string().optional() }).extend(Ki.shape).extend(Zi.shape); n.object({ required_user_actions: n.array(n.record(n.string(), n.any())), checkout_attempt_id: k(n.string()) }); n.object({ fields: gi, checkoutPaymentMethod: ct, payment_route_id: k(n.string()) }); n.object({ session_id: n.string(), non_cde_form_fields: rt, checkout_payment_method: ct, extra_metadata: n.record(n.string(), n.any()), // This is optional in CDE, but not in OJS moving forward use_unified_cc_flow: k(n.boolean()), pay_first_flow_cart_info: _o.optional(), payment_route_id: k(n.string()), customer_language: n.string().optional(), existing_cc_pm_id: k(n.string()) }); n.object({ required_user_actions: n.array(n.record(n.string(), n.any())), cc_pm_id: n.string(), checkout_success_response: k(Dr), checkout_attempt_id: k(n.string()) }); n.record(n.any()); n.object({ first_name: k(n.string()), last_name: k(n.string()), line1: k(n.string()), line2: k(n.string()), line3: k(n.string()), city: k(n.string()), state: k(n.string()), country: k(n.string()), zip_code: k(n.string()), email: k(n.string()), billing_email: k(n.string()), phone_number: k(n.string()), business_name: k(n.string()), tax_id: k(n.string()), tax_id_type: k(n.string()), update_processor_customer: k(n.boolean()) }); n.object({ id: n.string(), email: k(n.string()), first_name: k(n.string()), last_name: k(n.string()), phone_number: k(n.string()), billing_email: k(n.string()), address: k(n.record(n.string(), n.any())) }); n.object({ message: n.string() }); n.object({ error_code: n.string() }); n.object({ checkout_payment_method: ct, processor_specific_metadata: n.record(n.any()).optional(), payment_route_id: k(n.string()) }); n.object({ next_action_metadata: k(n.record(n.any())) }); n.object({ events: n.array( n.object({ event_name: n.string(), device_token: n.string(), properties: n.record(n.any()).optional(), context_properties: n.record(n.any()).optional() }) ) }); n.any().optional(); n.object({ device_token: n.string() }); n.object({}); n.object({ _unified_cc_action_name: n.string(), _unified_cc_pccs_id: n.string() }).catchall(n.any()); const Wi = n.object({ type: n.string(), loc: n.array(n.string()), msg: n.string(), url: n.string() }); n.array(Wi); const Ji = n.object({ code: n.string(), message: n.string(), path: n.array(n.string()) }); n.array(Ji); const Qi = (e, t, r) => ((...o) => { try { return t(...o); } catch (a) { r(`[form] Error running callback (${e}):`, a); return; } }), Wr = (e) => { const t = (...o) => { window.console.log(`${je.green.bold("ojs/")}${je.bold.gray(`${e}`)} `, ...o); }, r = (...o) => { window.console.warn(`${je.red.bold("ojs/")}${je.bold.gray(`${e}`)} `, ...o); }; return { log: t, err: r, log__: t, err__: r }; }; var Ur = function(e, t) { return Ur = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(r, o) { r.__proto__ = o; } || function(r, o) { for (var a in o) Object.prototype.hasOwnProperty.call(o, a) && (r[a] = o[a]); }, Ur(e, t); }; function Oe(e, t) { if (typeof t != "function" && t !== null) throw new TypeError("Class extends value " + String(t) + " is not a constructor or null"); Ur(e, t); function r() { this.constructor = e; } e.prototype = t === null ? Object.create(t) : (r.prototype = t.prototype, new r()); } function Xi(e, t, r, o) { function a(i) { return i instanceof r ? i : new r(function(s) { s(i); }); } return new (r || (r = Promise))(function(i, s) { function c(d) { try { u(o.next(d)); } catch (h) { s(h); } } function l(d) { try { u(o.throw(d)); } catch (h) { s(h); } } function u(d) { d.done ? i(d.value) : a(d.value).then(c, l); } u((o = o.apply(e, t || [])).next()); }); } function yo(e, t) { var r = { label: 0, sent: function() { if (i[0] & 1) throw i[1]; return i[1]; }, trys: [], ops: [] }, o, a, i, s = Object.create((typeof Iterator == "function" ? Iterator : Object).prototype); return s.next = c(0), s.throw = c(1), s.return = c(2), typeof Symbol == "function" && (s[Symbol.iterator] = function() { return this; }), s; function c(u) { return function(d) { return l([u, d]); }; } function l(u) { if (o) throw new TypeError("Generator is already executing."); for (; s && (s = 0, u[0] && (r = 0)), r; ) try { if (o = 1, a && (i = u[0] & 2 ? a.return : u[0] ? a.throw || ((i = a.return) && i.call(a), 0) : a.next) && !(i = i.call(a, u[1])).done) return i; switch (a = 0, i && (u = [u[0] & 2, i.value]), u[0]) { case 0: case 1: i = u; break; case 4: return r.label++, { value: u[1], done: !1 }; case 5: r.label++, a = u[1], u = [0]; continue; case 7: u = r.ops.pop(), r.trys.pop(); continue; default: if (i = r.trys, !(i = i.length > 0 && i[i.length - 1]) && (u[0] === 6 || u[0] === 2)) { r = 0; continue; } if (u[0] === 3 && (!i || u[1] > i[0] && u[1] < i[3])) { r.label = u[1]; break; } if (u[0] === 6 && r.label < i[1]) { r.label = i[1], i = u; break; } if (i && r.label < i[2]) { r.label = i[2], r.ops.push(u); break; } i[2] && r.ops.pop(), r.trys.pop(); continue; } u = t.call(e, r); } catch (d) { u = [6, d], a = 0; } finally { o = i = 0; } if (u[0] & 5) throw u[1]; return { value: u[0] ? u[1] : void 0, done: !0 }; } } function nt(e) { var t = typeof Symbol == "function" && Symbol.iterator, r = t && e[t], o = 0; if (r) return r.call(e); if (e && typeof e.length == "number") return { next: function() { return e && o >= e.length && (e = void 0), { value: e && e[o++], done: !e }; } }; throw new TypeError(t ? "Object is not iterable." : "Symbol.iterator is not defined."); } function Qt(e, t) { var r = typeof Symbol == "function" && e[Symbol.iterator]; if (!r) return e; var o = r.call(e), a, i = [], s; try { for (; (t === void 0 || t-- > 0) && !(a = o.next()).done; ) i.push(a.value); } catch (c) { s = { error: c }; } finally { try { a && !a.done && (r = o.return) && r.call(o); } finally { if (s) throw s.error; } } return i; } function Xt(e, t, r) { if (r || arguments.length === 2) for (var o = 0, a = t.length, i; o < a; o++) (i || !(o in t)) && (i || (i = Array.prototype.slice.call(t, 0, o)), i[o] = t[o]); return e.concat(i || Array.prototype.slice.call(t)); } function Qe(e) { return this instanceof Qe ? (this.v = e, this) : new Qe(e); } function es(e, t, r) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var o = r.apply(e, t || []), a, i = []; return a = Object.create((typeof AsyncIterator == "function" ? AsyncIterator : Object).prototype), c("next"), c("throw"), c("return", s), a[Symbol.asyncIterator] = function() { return this; }, a; function s(p) { return function(f) { return Promise.resolve(f).then(p, h); }; } function c(p, f) { o[p] && (a[p] = function(y) { return new Promise(function(w, g) { i.push([p, y, w, g]) > 1 || l(p, y); }); }, f && (a[p] = f(a[p]))); } function l(p, f) { try { u(o[p](f)); } catch (y) { _(i[0][3], y); } } function u(p) { p.value instanceof Qe ? Promise.resolve(p.value.v).then(d, h) : _(i[0][2], p); } function d(p) { l("next", p); } function h(p) { l("throw", p); } function _(p, f) { p(f), i.shift(), i.length && l(i[0][0], i[0][1]); } } function ts(e) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var t = e[Symbol.asyncIterator], r; return t ? t.call(e) : (e = typeof nt == "function" ? nt(e) : e[Symbol.iterator](), r = {}, o("next"), o("throw"), o("return"), r[Symbol.asyncIterator] = function() { return this; }, r); function o(i) { r[i] = e[i] && function(s) { return new Promise(function(c, l) { s = e[i](s), a(c, l, s.done, s.value); }); }; } function a(i, s, c, l) { Promise.resolve(l).then(function(u) { i({ value: u, done: c }); }, s); } } function X(e) { return typeof e == "function"; } function pr(e) { var t = function(o) { Error.call(o), o.stack = new Error().stack; }, r = e(t); return r.prototype = Object.create(Error.prototype), r.prototype.constructor = r, r; } var xr = pr(function(e) { return function(r) { e(this), this.message = r ? r.length + ` errors occurred during unsubscription: ` + r.map(function(o, a) { return a + 1 + ") " + o.toString(); }).join(` `) : "", this.name = "UnsubscriptionError", this.errors = r; }; }); function er(e, t) { if (e) { var r = e.indexOf(t); 0 <= r && e.splice(r, 1); } } var Lt = (function() { function e(t) { this.initialTeardown = t, this.closed = !1, this._parentage = null, this._finalizers = null; } return e.prototype.unsubscribe = function() { var t, r, o, a, i; if (!this.closed) { this.closed = !0; var s = this._parentage; if (s) if (this._parentage = null, Array.isArray(s)) try { for (var c = nt(s), l = c.next(); !l.done; l = c.next()) { var u = l.value; u.remove(this); } } catch (y) { t = { error: y }; } finally { try { l && !l.done && (r = c.return) && r.call(c); } finally { if (t) throw t.error; } } else s.remove(this); var d = this.initialTeardown; if (X(d)) try { d(); } catch (y) { i = y instanceof xr ? y.errors : [y]; } var h = this._finalizers; if (h) { this._finalizers = null; try { for (var _ = nt(h), p = _.next(); !p.done; p = _.next()) { var f = p.value; try { bn(f); } catch (y) { i = i ?? [], y instanceof xr ? i = Xt(Xt([], Qt(i)), Qt(y.errors)) : i.push(y); } } } catch (y) { o = { error: y }; } finally { try { p && !p.done && (a = _.return) && a.call(_); } finally { if (o) throw o.error; } } } if (i) throw new xr(i); } }, e.prototype.add = function(t) { var r; if (t && t !== this) if (this.closed) bn(t); else { if (t instanceof e) { if (t.closed || t._hasParent(this)) return; t._addParent(this); } (this._finalizers = (r = this._finalizers) !== null && r !== void 0 ? r : []).push(t); } }, e.prototype._hasParent = function(t) { var r = this._parentage; return r === t || Array.isArray(r) && r.includes(t); }, e.prototype._addParent = function(t) { var r = this._parentage; this._parentage = Array.isArray(r) ? (r.push(t), r) : r ? [r, t] : t; }, e.prototype._removeParent = function(t) { var r = this._parentage; r === t ? this._parentage = null : Array.isArray(r) && er(r, t); }, e.prototype.remove = function(t) { var r = this._finalizers; r && er(r, t), t instanceof e && t._removeParent(this); }, e.EMPTY = (function() { var t = new e(); return t.closed = !0, t; })(), e; })(), go = Lt.EMPTY; function wo(e) { return e instanceof Lt || e && "closed" in e && X(e.remove) && X(e.add) && X(e.unsubscribe); } function bn(e) { X(e) ? e() : e.unsubscribe(); } var rs = { Promise: void 0 }, ns = { setTimeout: function(e, t) { for (var r = [], o = 2; o < arguments.length; o++) r[o - 2] = arguments[o]; return setTimeout.apply(void 0, Xt([e, t], Qt(r))); }, clearTimeout: function(e) { return clearTimeout(e); }, delegate: void 0 }; function bo(e) { ns.setTimeout(function() { throw e; }); } function vn() { } function Ht(e) { e(); } var Jr = (function(e) { Oe(t, e); function t(r) { var o = e.call(this) || this; return o.isStopped = !1, r ? (o.destination = r, wo(r) && r.add(o)) : o.destination = is, o; } return t.create = function(r, o, a) { return new Gr(r, o, a); }, t.prototype.next = function(r) { this.isStopped || this._next(r); }, t.prototype.error = function(r) { this.isStopped || (this.isStopped = !0, this._error(r)); }, t.prototype.complete = function() { this.isStopped || (this.isStopped = !0, this._complete()); }, t.prototype.unsubscribe = function() { this.closed || (this.isStopped = !0, e.prototype.unsubscribe.call(this), this.destination = null); }, t.prototype._next = function(r) { this.destination.next(r); }, t.prototype._error = function(r) { try { this.destination.error(r); } finally { this.unsubscribe(); } }, t.prototype._complete = function() { try { this.destination.complete(); } finally { this.unsubscribe(); } }, t; })(Lt), os = (function() { function e(t) { this.partialObserver = t; } return e.prototype.next = function(t) { var r = this.partialObserver; if (r.next) try { r.next(t); } catch (o) { Ft(o); } }, e.prototype.error = function(t) { var r = this.partialObserver; if (r.error) try { r.error(t); } catch (o) { Ft(o); } else Ft(t); }, e.prototype.complete = function() { var t = this.partialObserver; if (t.complete) try { t.complete(); } catch (r) { Ft(r); } }, e; })(), Gr = (function(e) { Oe(t, e); function t(r, o, a) { var i = e.call(this) || this, s; return X(r) || !r ? s = { next: r ?? void 0, error: o ?? void 0, complete: a ?? void 0 } : s = r, i.destination = new os(s), i; } return t; })(Jr); function Ft(e) { bo(e); } function as(e) { throw e; } var is = { closed: !0, next: vn, error: as, complete: vn }, Qr = (function() { return typeof Symbol == "function" && Symbol.observable || "@@observable"; })(); function ss(e) { return e; } function cs(e) { return e.length === 0 ? ss : e.length === 1 ? e[0] : function(r) { return e.reduce(function(o, a) { return a(o); }, r); }; } var Te = (function() { function e(t) { t && (this._subscribe = t); } return e.prototype.lift = function(t) { var r = new e(); return r.source = this, r.operator = t, r; }, e.prototype.subscribe = function(t, r, o) { var a = this, i = us(t) ? t : new Gr(t, r, o); return Ht(function() { var s = a, c = s.operator, l = s.source; i.add(c ? c.call(i, l) : l ? a._subscribe(i) : a._trySubscribe(i)); }), i; }, e.prototype._trySubscribe = function(t) { try { return this._subscribe(t); } catch (r) { t.error(r); } }, e.prototype.forEach = function(t, r) { var o = this; return r = En(r), new r(function(a, i) { var s = new Gr({ next: function(c) { try { t(c); } catch (l) { i(l), s.unsubscribe(); } }, error: i, complete: a }); o.subscribe(s); }); }, e.prototype._subscribe = function(t) { var r; return (r = this.source) === null || r === void 0 ? void 0 : r.subscribe(t); }, e.prototype[Qr] = function() { return this; }, e.prototype.pipe = function() { for (var t = [], r = 0; r < arguments.length; r++) t[r] = arguments[r]; return cs(t)(this); }, e.prototype.toPromise = function(t) { var r = this; return t = En(t), new t(function(o, a) { var i; r.subscribe(function(s) { return i = s; }, function(s) { return a(s); }, function() { return o(i); }); }); }, e.create = function(t) { return new e(t); }, e; })(); function En(e) { var t; return (t = e ?? rs.Promise) !== null && t !== void 0 ? t : Promise; } function ls(e) { return e && X(e.next) && X(e.error) && X(e.complete); } function us(e) { return e && e instanceof Jr || ls(e) && wo(e); } function ds(e) { return X(e?.lift); } function ps(e) { return function(t) { if (ds(t)) return t.lift(function(r) { try { return e(r, this); } catch (o) { this.error(o); } }); throw new TypeError("Unable to lift unknown Observable type"); }; } function ms(e, t, r, o, a) { return new fs(e, t, r, o, a); } var fs = (function(e) { Oe(t, e); function t(r, o, a, i, s, c) { var l = e.call(this, r) || this; return l.onFinalize = s, l.shouldUnsubscribe = c, l._next = o ? function(u) { try { o(u); } catch (d) { r.error(d); } } : e.prototype._next, l._error = i ? function(u) { try { i(u); } catch (d) { r.error(d); } finally { this.unsubscribe(); } } : e.prototype._error, l._complete = a ? function() { try { a(); } catch (u) { r.error(u); } finally { this.unsubscribe(); } } : e.prototype._complete, l; } return t.prototype.unsubscribe = function() { var r; if (!this.shouldUnsubscribe || this.shouldUnsubscribe()) { var o = this.closed; e.prototype.unsubscribe.call(this), !o && ((r = this.onFinalize) === null || r === void 0 || r.call(this)); } }, t; })(Jr), hs = pr(function(e) { return function() { e(this), this.name = "ObjectUnsubscribedError", this.message = "object unsubscribed"; }; }), vo = (function(e) { Oe(t, e); function t() { var r = e.call(this) || this; return r.closed = !1, r.currentObservers = null, r.observers = [], r.isStopped = !1, r.hasError = !1, r.thrownError = null, r; } return t.prototype.lift = function(r) { var o = new Pn(this, this); return o.operator = r, o; }, t.prototype._throwIfClosed = function() { if (this.closed) throw new hs(); }, t.prototype.next = function(r) { var o = this; Ht(function() { var a, i; if (o._throwIfClosed(), !o.isStopped) { o.currentObservers || (o.currentObservers = Array.from(o.observers)); try { for (var s = nt(o.currentObservers), c = s.next(); !c.done; c = s.next()) { var l = c.value; l.next(r); } } catch (u) { a = { error: u }; } finally { try { c && !c.done && (i = s.return) && i.call(s); } finally { if (a) throw a.error; } } } }); }, t.prototype.error = function(r) { var o = this; Ht(function() { if (o._throwIfClosed(), !o.isStopped) { o.hasError = o.isStopped = !0, o.thrownError = r; for (var a = o.observers; a.length; ) a.shift().error(r); } }); }, t.prototype.complete = function() { var r = this; Ht(function() { if (r._throwIfClosed(), !r.isStopped) { r.isStopped = !0; for (var o = r.observers; o.length; ) o.shift().complete(); } }); }, t.prototype.unsubscribe = function() { this.isStopped = this.closed = !0, this.observers = this.currentObservers = null; }, Object.defineProperty(t.prototype, "observed", { get: function() { var r; return ((r = this.observers) === null || r === void 0 ? void 0 : r.length) > 0; }, enumerable: !1, configurable: !0 }), t.prototype._trySubscribe = function(r) { return this._throwIfClosed(), e.prototype._trySubscribe.call(this, r); }, t.prototype._subscribe = function(r) { return this._throwIfClosed(), this._checkFinalizedStatuses(r), this._innerSubscribe(r); }, t.prototype._innerSubscribe = function(r) { var o = this, a = this, i = a.hasError, s = a.isStopped, c = a.observers; return i || s ? go : (this.currentObservers = null, c.push(r), new Lt(function() { o.currentObservers = null, er(c, r); })); }, t.prototype._checkFinalizedStatuses = function(r) { var o = this, a = o.hasError, i = o.thrownError, s = o.isStopped; a ? r.error(i) : s && r.complete(); }, t.prototype.asObservable = function() { var r = new Te(); return r.source = this, r; }, t.create = function(r, o) { return new Pn(r, o); }, t; })(Te), Pn = (function(e) { Oe(t, e); function t(r, o) { var a = e.call(this) || this; return a.destination = r, a.source = o, a; } return t.prototype.next = function(r) { var o, a; (a = (o = this.destination) === null || o === void 0 ? void 0 : o.next) === null || a === void 0 || a.call(o, r); }, t.prototype.error = function(r) { var o, a; (a = (o = this.destination) === null || o === void 0 ? void 0 : o.error) === null || a === void 0 || a.call(o, r); }, t.prototype.complete = function() { var r, o; (o = (r = this.destination) === null || r === void 0 ? void 0 : r.complete) === null || o === void 0 || o.call(r); }, t.prototype._subscribe = function(r) { var o, a; return (a = (o = this.source) === null || o === void 0 ? void 0 : o.subscribe(r)) !== null && a !== void 0 ? a : go; }, t; })(vo), _s = { now: function() { return Date.now(); } }, ys = (function(e) { Oe(t, e); function t(r, o) { return e.call(this) || this; } return t.prototype.schedule = function(r, o) { return this; }, t; })(Lt), kn = { setInterval: function(e, t) { for (var r = [], o = 2; o < arguments.length; o++) r[o - 2] = arguments[o]; return setInterval.apply(void 0, Xt([e, t], Qt(r))); }, clearInterval: function(e) { return clearInterval(e); }, delegate: void 0 }, gs = (function(e) { Oe(t, e); function t(r, o) { var a = e.call(this, r, o) || this; return a.scheduler = r, a.work = o, a.pending = !1, a; } return t.prototype.schedule = function(r, o) { var a; if (o === void 0 && (o = 0), this.closed) return this; this.state = r; var i = this.id, s = this.scheduler; return i != null && (this.id = this.recycleAsyncId(s, i, o)), this.pending = !0, this.delay = o, this.id = (a = this.id) !== null && a !== void 0 ? a : this.requestAsyncId(s, this.id, o), this; }, t.prototype.requestAsyncId = function(r, o, a) { return a === void 0 && (a = 0), kn.setInterval(r.flush.bind(r, this), a); }, t.prototype.recycleAsyncId = function(r, o, a) { if (a === void 0 && (a = 0), a != null && this.delay === a && this.pending === !1) return o; o != null && kn.clearInterval(o); }, t.prototype.execute = function(r, o) { if (this.closed) return new Error("executing a cancelled action"); this.pending = !1; var a = this._execute(r, o); if (a) return a; this.pending === !1 && this.id != null && (this.id = this.recycleAsyncId(this.scheduler, this.id, null)); }, t.prototype._execute = function(r, o) { var a = !1, i; try { this.work(r); } catch (s) { a = !0, i = s || new Error("Scheduled action threw falsy error"); } if (a) return this.unsubscribe(), i; }, t.prototype.unsubscribe = function() { if (!this.closed) { var r = this, o = r.id, a = r.scheduler, i = a.actions; this.work = this.state = this.scheduler = null, this.pending = !1, er(i, this), o != null && (this.id = this.recycleAsyncId(a, o, null)), this.delay = null, e.prototype.unsubscribe.call(this); } }, t; })(ys), Sn = (function() { function e(t, r) { r === void 0 && (r = e.now), this.schedulerActionCtor = t, this.now = r; } return e.prototype.schedule = function(t, r, o) { return r === void 0 && (r = 0), new this.schedulerActionCtor(this, t).schedule(o, r); }, e.now = _s.now, e; })(), ws = (function(e) { Oe(t, e); function t(r, o) { o === void 0 && (o = Sn.now); var a = e.call(this, r, o) || this; return a.actions = [], a._active = !1, a; } return t.prototype.flush = function(r) { var o = this.actions; if (this._active) { o.push(r); return; } var a; this._active = !0; do if (a = r.execute(r.state, r.delay)) break; while (r = o.shift()); if (this._active = !1, a) { for (; r = o.shift(); ) r.unsubscribe(); throw a; } }, t; })(Sn), bs = new ws(gs), vs = (function(e) { return e && typeof e.length == "number" && typeof e != "function"; }); function Es(e) { return X(e?.then); } function Ps(e) { return X(e[Qr]); } function ks(e) { return Symbol.asyncIterator && X(e?.[Symbol.asyncIterator]); } function Ss(e) { return new TypeError("You provided " + (e !== null && typeof e == "object" ? "an invalid object" : "'" + e + "'") + " where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable."); } function Cs() { return typeof Symbol != "function" || !Symbol.iterator ? "@@iterator" : Symbol.iterator; } var As = Cs(); function Is(e) { return X(e?.[As]); } function xs(e) { return es(this, arguments, function() { var r, o, a, i; return yo(this, function(s) { switch (s.label) { case 0: r = e.getReader(), s.label = 1; case 1: s.trys.push([1, , 9, 10]), s.label = 2; case 2: return [4, Qe(r.read())]; case 3: return o = s.sent(), a = o.value, i = o.done, i ? [4, Qe(void 0)] : [3, 5]; case 4: return [2, s.sent()]; case 5: return [4, Qe(a)]; case 6: return [4, s.sent()]; case 7: return s.sent(), [3, 2]; case 8: return [3, 10]; case 9: return r.releaseLock(), [7]; case 10: return [2]; } }); }); } function Ts(e) { return X(e?.getReader); } function Rs(e) { if (e instanceof Te) return e; if (e != null) { if (Ps(e)) return Ls(e); if (vs(e)) return Ns(e); if (Es(e)) return Ms(e); if (ks(e)) return Eo(e); if (Is(e)) return js(e); if (Ts(e)) return Fs(e); } throw Ss(e); } function Ls(e) { return new Te(function(t) { var r = e[Qr](); if (X(r.subscribe)) return r.subscribe(t); throw new TypeError("Provided object does not correctly implement Symbol.observable"); }); } function Ns(e) { return new Te(function(t) { for (var r = 0; r < e.length && !t.closed; r++) t.next(e[r]); t.complete(); }); } function Ms(e) { return new Te(function(t) { e.then(function(r) { t.closed || (t.next(r), t.complete()); }, function(r) { return t.error(r); }).then(null, bo); }); } function js(e) { return new Te(function(t) { var r, o; try { for (var a = nt(e), i = a.next(); !i.done; i = a.next()) { var s = i.value; if (t.next(s), t.closed) return; } } catch (c) { r = { error: c }; } finally { try { i && !i.done && (o = a.return) && o.call(a); } finally { if (r) throw r.error; } } t.complete(); }); } function Eo(e) { return new Te(function(t) { Os(e, t).catch(function(r) { return t.error(r); }); }); } function Fs(e) { return Eo(xs(e)); } function Os(e, t) { var r, o, a, i; return Xi(this, void 0, void 0, function() { var s, c; return yo(this, function(l) { switch (l.label) { case 0: l.trys.push([0, 5, 6, 11]), r = ts(e), l.label = 1; case 1: return [4, r.next()]; case 2: if (o = l.sent(), !!o.done) return [3, 4]; if (s = o.value, t.next(s), t.closed) return [2]; l.label = 3; case 3: return [3, 1]; case 4: return [3, 11]; case 5: return c = l.sent(), a = { error: c }, [3, 11]; case 6: return l.trys.push([6, , 9, 10]), o && !o.done && (i = r.return) ? [4, i.call(r)] : [3, 8]; case 7: l.sent(), l.label = 8; case 8: return [3, 10]; case 9: if (a) throw a.error; return [7]; case 10: return [7]; case 11: return t.complete(), [2]; } }); }); } function Ds(e, t, r, o, a) { o === void 0 && (o = 0), a === void 0 && (a = !1); var i = t.schedule(function() { r(), a ? e.add(this.schedule(null, o)) : this.unsubscribe(); }, o); if (e.add(i), !a) return i; } function Us(e, t) { var r = X(e) ? e : function() { return e; }, o = function(a) { return a.error(r()); }; return new Te(o); } var Gs = pr(function(e) { return function() { e(this), this.name = "EmptyError", this.message = "no elements in sequence"; }; }); function qs(e, t) { return new Promise(function(r, o) { var a = !1, i; e.subscribe({ next: function(s) { i = s, a = !0; }, error: o, complete: function() { a ? r(i) : o(new Gs()); } }); }); } function Vs(e) { return e instanceof Date && !isNaN(e); } var $s = pr(function(e) { return function(r) { r === void 0 && (r = null), e(this), this.message = "Timeout has occurred", this.name = "TimeoutError", this.info = r; }; }); function Hs(e, t) { var r = Vs(e) ? { first: e } : typeof e == "number" ? { each: e } : e, o = r.first, a = r.each, i = r.with, s = i === void 0 ? Bs : i, c = r.scheduler, l = c === void 0 ? bs : c, u = r.meta, d = u === void 0 ? null : u; if (o == null && a == null) throw new TypeError("No timeout provided."); return ps(function(h, _) { var p, f, y = null, w = 0, g = function(v) { f = Ds(_, l, function() { try { p.unsubscribe(), Rs(s({ meta: d, lastValue: y, seen: w })).subscribe(_); } catch (C) { _.error(C); } }, v); }; p = h.subscribe(ms(_, function(v) { f?.unsubscribe(), w++, _.next(y = v), a > 0 && g(a); }, void 0, void 0, function() { f?.closed || f?.unsubscribe(), y = null; })), !w && g(o != null ? typeof o == "number" ? o : +o - l.now() : a); }); } function Bs(e) { throw new $s(e); } class zs { constructor() { this.set = (t) => { if (this._current.status === "success") throw new Error("LoadedOnce is already in success state"); this._current = { status: "success", isSuccess: !0, loadedValue: t }, this._subject.next(t), this._subject.complete(); }, this.throw = (t, r) => { if (this._current.status === "success") throw new Error("LoadedOnce is already in success state"); this._current = { status: "error", isSuccess: !1, error: t, errMsg: r }, this._subject.error(t); }, this.getValueIfLoadedElse = (t) => this._current.status === "success" ? this._current.loadedValue : t, this.subscribe = (t) => { if (this._current.status === "success") { t(this._current); return; } this._current.status === "error" && t(this._current); const r = this._subject.subscribe({ next: () => { if (this._current.status !== "success") throw new Error("Invalid state (next): please make sure to update _current before the subject"); t(this._current), r.unsubscribe(); }, error: () => { if (this._current.status !== "error") throw new Error("Invalid state (error): please make sure to update _current before the subject"); t(this._current); } }); }, this.waitForLoad = (t) => { if (this._current.status === "success") return Promise.resolve(this._current.loadedValue); if (this._current.status === "error") return Promise.reject(this._current.error); this._current.status !== "initial" && Zs(this._current); const r = { first: t.timeoutSec * 1e3, with: () => Us(() => new Error(t.timeoutErrMsg)) }; return qs(this._subject.pipe(Hs(r))); }, this._current = { status: "initial", isSuccess: !1 }, this._subject = new vo(); } get current() { return this._current; } } n.enum(["dev", "stg", "prod"]); const Ks = { prod: "https://connto.getopenpay.com", stg: "https://connto.openpaystaging.com", dev: "http://localhost:8000" }, Ys = (e) => Ks[e]; function Zs(e) { throw new Error(`Unhandled case: ${e}`); } const Le = () => { if (!(typeof window > "u")) return window; }, Ws = new zs(), Cn = "op_metrics_queue", Js = 3, Qs = 3, Xs = 1e3, { log__: Ot } = Wr("op-metrics"); class ec { constructor() { this.queue = [], this.processingQueue = !1, this.batchTimeout = null, this.lastEventTimestamp = 0, this.offlineListener = () => { Ot("Network offline, metrics will be queued"), this.cancelBatchProcessing(); }, this.onlineListener = () => { Ot("Network online, processing metrics queue"), this.processQueue(); }, this.loadQueue