PageSourceSearch

https://www.dotcomsecrets.com/assets/projects/user_pages/checkout-v2-TRNZYJLV.js

js dotcomsecrets.com collected 2026-09-24 20:51:03 UTC 8,220 bytes, 209 lines download raw bytes

1import {
2  initIndividualVariantState,
3  unselectAllProducts,
4  updateCardByProductIdState
5} from "./chunk-5JJNRIKL.js";
6import "./chunk-W3RKY5WP.js";
7import "./chunk-YSVSPNWW.js";
8import "./chunk-372FPXG6.js";
9import "./chunk-BY72GGKB.js";
10import "./chunk-4AIF3XZW.js";
11import "./chunk-Y32E43UA.js";
12import "./chunk-7HBS56XK.js";
13import "./chunk-KIZY5IRN.js";
14import "./chunk-5NUE6T5P.js";
15import {
16  CF2Component,
17  init_runtime,
18  registerComponent
19} from "./chunk-NQUHJ6NR.js";
20import {
21  init_define_process
22} from "./chunk-RFSPGZ3L.js";
23
24// projects/lib/packages/yggdrasil-blueprints/__generated__/packs/checkout-v2.ts
25init_define_process();
26
27// projects/lib/packages/yggdrasil-blueprints/__generated__/blueprints/checkout-v2.ts
28init_define_process();
29init_runtime();
30var CheckoutV2 = class extends CF2Component {
31  constructor(el, runtimeSel) {
32    super(el, runtimeSel);
33  }
34  mount() {
35    if (this.variantDisplay === "individual") {
36      initIndividualVariantState();
37    }
38    const paymentGateway = typeof StripeCheckout === "function" ? "stripe" : "rebilly";
39    const concreteCheckout = paymentGateway === "stripe" ? this.getComponent(StripeCheckout) : this.getComponent(RebillyCheckout);
40    if (concreteCheckout?._lazyInitPending) {
41      this.element.querySelector(".elCheckoutWrapper")?.classList.add("elCheckoutLazyPlaceholder");
42      let triggered = false;
43      const triggerInit = async () => {
44        if (triggered) return;
45        triggered = true;
46        observer?.disconnect();
47        this.element.querySelector(".elCheckoutWrapper")?.classList.remove("elCheckoutLazyPlaceholder");
48        await concreteCheckout._performLazyInit();
49        this.initializeStoreDependentElements(Checkout.store, Checkout.computed);
50      };
51      const observer = new IntersectionObserver((entries) => {
52        if (entries.some((e) => e.isIntersecting)) triggerInit();
53      }, { rootMargin: "200px" });
54      observer.observe(this.element);
55      $(document).on("click", '[href="#submit-oto"]', async (evt) => {
56        evt.preventDefault();
57        evt.stopPropagation();
58        await triggerInit();
59      });
60      return;
61    }
62    const checkoutLoading = this.getComponentGroup(CheckoutLoadingV1);
63    const clearOtoErrors = () => {
64      document.querySelectorAll(".elOtoButtonError").forEach((node) => node.remove());
65    };
66    const renderOtoError = (host, message) => {
67      clearOtoErrors();
68      const node = document.createElement("div");
69      node.className = "elOtoButtonError";
70      node.setAttribute("role", "alert");
71      node.setAttribute("aria-live", "polite");
72      node.textContent = message;
73      node.style.cssText = "margin-top:8px;color:#df1b41;font-size:15px;line-height:1.4;text-align:center;";
74      host.insertAdjacentElement("afterend", node);
75    };
76    $(document).on("click", '[href="#submit-oto"]', async function(evt) {
77      evt.preventDefault();
78      evt.stopPropagation();
79      const clickedButton = evt.currentTarget;
80      const element = clickedButton.closest(`[data-page-element]`);
81      const otoProductVariantPrice = element?.dataset?.selectedProduct;
82      const redirectOverride = element?.dataset?.otoRedirectOverride;
83      if (!otoProductVariantPrice) {
84        console.error("No product selected for this OTO button");
85        return;
86      }
87      clearOtoErrors();
88      const [product_id, variant_id, price_id] = otoProductVariantPrice.split("-");
89      unselectAllProducts();
90      updateCardByProductIdState(product_id, {
91        variantId: variant_id,
92        priceId: price_id,
93        quantity: 1
94      });
95      const closestPaintColor = $(evt.target).closest("[data-paint-colors]").attr("data-paint-colors") ?? "lightest";
96      $(".id-checkout-modal-node-id").find('[data-page-element="Checkout/V2"]').attr("data-paint-colors", closestPaintColor);
97      $(".id-checkout-modal-node-id").css("display", "flex");
98      checkoutLoading.show();
99      $(".elCheckoutCTAHeader").hide();
100      $(".elCheckoutBodyContainer").hide();
101      function cartHasOnlySelectedVariant(cart, v2) {
102        if (cart.items.length != 1 || cart.items[0].quantity != 1) {
103          return false;
104        }
105        const v1 = cart.items[0];
106        return v1.product_id == v2.product_id && v1.variant_id == v2.variant_id && v1.price_id == v2.price_id;
107      }
108      const restoreCheckoutBody = () => {
109        $(".elCheckoutCTAHeader").show();
110        $(".elCheckoutBodyContainer").show();
111        checkoutLoading.hide();
112      };
113      const showModal = restoreCheckoutBody;
114      const showInlineError = (message) => {
115        $(".id-checkout-modal-node-id").css("display", "none");
116        restoreCheckoutBody();
117        renderOtoError(element, message);
118      };
119      const handleFailure = (result) => {
120        if (result && result.actionable === false && result.message) {
121          showInlineError(result.message);
122        } else {
123          showModal();
124        }
125      };
126      const submitOtoSafely = async () => {
127        try {
128          return await concreteCheckout.submitOTO(redirectOverride);
129        } catch (error) {
130          console.error("[OTO] submit failed unexpectedly", error);
131          return { ok: false, actionable: true };
132        }
133      };
134      if (paymentGateway === "stripe") {
135        concreteCheckout.checkout.preventOrderPreview = true;
136        await concreteCheckout.checkout.sendOrderPreview({ skipThrottle: true, forceOrderPreview: true });
137        const summary = globalThis.Checkout.store.summary.get();
138        if (summary.state == globalThis.Checkout.SummaryStates.OK) {
139          const result = await submitOtoSafely();
140          if (!result.ok) {
141            concreteCheckout.checkout.preventOrderPreview = false;
142            handleFailure(result);
143          }
144        } else {
145          concreteCheckout.checkout.preventOrderPreview = false;
146          showModal();
147        }
148      } else {
149        let settled = false;
150        let unsubscribe = null;
151        const teardown = () => {
152          if (!unsubscribe) return;
153          unsubscribe();
154          unsubscribe = null;
155        };
156        const onSummary = async (summary) => {
157          if (settled) return;
158          if (summary.state == globalThis.Checkout.SummaryStates.OK) {
159            if (!cartHasOnlySelectedVariant(concreteCheckout.getCart(), { product_id, variant_id, price_id })) {
160              return;
161            }
162            settled = true;
163            teardown();
164            const result = await submitOtoSafely();
165            if (!result.ok) {
166              handleFailure(result);
167            }
168          } else if (summary.state == globalThis.Checkout.SummaryStates.WAITING) {
169            settled = true;
170            teardown();
171            showModal();
172          } else if (summary.state == globalThis.Checkout.SummaryStates.ERROR) {
173            if (!cartHasOnlySelectedVariant(concreteCheckout.getCart(), { product_id, variant_id, price_id })) {
174              return;
175            }
176            settled = true;
177            teardown();
178            showModal();
179          }
180        };
181        unsubscribe = globalThis.Checkout.store.summary.subscribe(onSummary);
182        if (settled) {
183          teardown();
184        }
185      }
186    });
187  }
188  initializeStoreDependentElements(store, computed) {
189    const checkoutElements = this.getAllComponents();
190    const linkedElements = [...document.querySelectorAll(`[data-linked-checkout-id="${this.id}"]`)].map((el) => el.cf2_instance);
191    const allElements = checkoutElements.concat(linkedElements);
192    allElements.forEach((el) => {
193      el?.initializeWithStore && el.initializeWithStore(store, computed);
194    });
195  }
196  afterMount() {
197    if (!Checkout?.store) return;
198    this.initializeStoreDependentElements(Checkout.store, Checkout.computed);
199    const productVariantWithNoBump = globalThis.globalResourceData.productVariantWithNoBump;
200    if (productVariantWithNoBump) {
201      const variantId = productVariantWithNoBump.id;
202      const productId = productVariantWithNoBump.product_id;
203      updateCardByProductIdState(productId, { variantId });
204    }
205  }
206};
207registerComponent("Checkout/V2", CheckoutV2);
208window["CheckoutV2"] = CheckoutV2;
209//# sourceMappingURL=checkout-v2-TRNZYJLV.js.map

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.