@payment-kit-js/vanilla 0.5.1 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * PaymentKit.js v0.5.1
2
+ * PaymentKit.js v0.5.3
3
3
  * https://paymentkit.com
4
4
  *
5
5
  * @license MIT
@@ -42,7 +42,7 @@ var PaymentKit = (() => {
42
42
  });
43
43
 
44
44
  // package.json
45
- var version = "0.5.1";
45
+ var version = "0.5.3";
46
46
 
47
47
  // src/analytics/mock-adapter.ts
48
48
  var MockAnalyticsAdapter = class {
@@ -6509,24 +6509,44 @@ var PaymentKit = (() => {
6509
6509
  _sessionConfigReady: void 0
6510
6510
  };
6511
6511
  if (cardTokenizationMode === void 0) {
6512
- paymentKitStates._sessionConfigReady = fetch(`${apiBaseUrl}/api/checkout-sessions/token/${secureToken}`).then((resp) => resp.ok ? resp.json() : null).then((session) => {
6512
+ const sessionConfigUrl = `${apiBaseUrl}/api/checkout-sessions/token/${secureToken}`;
6513
+ console.log(
6514
+ `[PaymentKit] cardTokenizationMode not provided \u2014 auto-detecting from session API: ${sessionConfigUrl}`
6515
+ );
6516
+ paymentKitStates._sessionConfigReady = fetch(sessionConfigUrl).then((resp) => {
6517
+ if (!resp.ok) {
6518
+ console.warn(`[PaymentKit] Session config fetch failed with status ${resp.status}`);
6519
+ return null;
6520
+ }
6521
+ return resp.json();
6522
+ }).then((session) => {
6513
6523
  if (session && typeof session === "object" && typeof session.card_tokenization_mode === "string") {
6514
6524
  paymentKitStates.cardTokenizationMode = session.card_tokenization_mode || "direct";
6525
+ console.log(
6526
+ `[PaymentKit] Session config detected \u2014 cardTokenizationMode: ${paymentKitStates.cardTokenizationMode}`
6527
+ );
6515
6528
  const vaultId = session.vgs_vault_id;
6516
6529
  const vgsEnv = session.vgs_environment;
6517
6530
  if (vaultId && /^tnt[a-z0-9]+$/.test(vaultId) && (vgsEnv === "sandbox" || vgsEnv === "live")) {
6518
6531
  paymentKitStates.vgsVaultId = vaultId;
6519
6532
  paymentKitStates.vgsEnvironment = vgsEnv;
6533
+ console.log(`[PaymentKit] VGS config valid \u2014 vaultId: ${vaultId}, environment: ${vgsEnv}`);
6520
6534
  } else if (paymentKitStates.cardTokenizationMode === "vgs") {
6521
- console.warn("[PaymentKit] Invalid VGS config from session API, falling back to direct mode");
6535
+ console.warn(
6536
+ `[PaymentKit] Invalid VGS config from session API (vaultId: ${vaultId}, env: ${vgsEnv}), falling back to direct mode`
6537
+ );
6522
6538
  paymentKitStates.cardTokenizationMode = "direct";
6523
6539
  }
6524
6540
  } else {
6541
+ console.log("[PaymentKit] Session response missing card_tokenization_mode \u2014 defaulting to direct mode");
6525
6542
  paymentKitStates.cardTokenizationMode = "direct";
6526
6543
  }
6527
- }).catch(() => {
6544
+ }).catch((err) => {
6545
+ console.error("[PaymentKit] Session config fetch error \u2014 falling back to direct mode:", err);
6528
6546
  paymentKitStates.cardTokenizationMode = "direct";
6529
6547
  });
6548
+ } else {
6549
+ console.log(`[PaymentKit] cardTokenizationMode explicitly set: ${cardTokenizationMode}`);
6530
6550
  }
6531
6551
  const pmInstances = paymentMethods.map((paymentMethod) => paymentMethod(paymentKitStates));
6532
6552
  const externalFuncsMapByPm = pmInstances.reduce(
@@ -6796,17 +6816,26 @@ var PaymentKit = (() => {
6796
6816
  var VGS_COLLECT_CDN = "https://js.verygoodvault.com/vgs-collect/3.2.1/vgs-collect.js";
6797
6817
  var loadPromise = null;
6798
6818
  function loadVgsCollectScript() {
6799
- if (loadPromise) return loadPromise;
6819
+ if (loadPromise) {
6820
+ console.log("[PaymentKit] VGS Collect CDN load already in progress \u2014 reusing promise");
6821
+ return loadPromise;
6822
+ }
6800
6823
  loadPromise = new Promise((resolve, reject) => {
6801
6824
  if (typeof window !== "undefined" && window.VGSCollect) {
6825
+ console.log("[PaymentKit] VGS Collect JS already available on window");
6802
6826
  resolve();
6803
6827
  return;
6804
6828
  }
6829
+ console.log(`[PaymentKit] Loading VGS Collect JS from CDN: ${VGS_COLLECT_CDN}`);
6805
6830
  const script = document.createElement("script");
6806
6831
  script.src = VGS_COLLECT_CDN;
6807
6832
  script.async = true;
6808
- script.onload = () => resolve();
6833
+ script.onload = () => {
6834
+ console.log("[PaymentKit] VGS Collect JS loaded successfully from CDN");
6835
+ resolve();
6836
+ };
6809
6837
  script.onerror = () => {
6838
+ console.error(`[PaymentKit] Failed to load VGS Collect JS from CDN: ${VGS_COLLECT_CDN}`);
6810
6839
  loadPromise = null;
6811
6840
  reject(new Error("Failed to load VGS Collect JS"));
6812
6841
  };
@@ -6891,9 +6920,14 @@ var PaymentKit = (() => {
6891
6920
  let cleanupVgs;
6892
6921
  let cleanupDirect;
6893
6922
  let cancelled = false;
6923
+ if (!states.vgsMountSelectors) states.vgsMountSelectors = {};
6924
+ states.vgsMountSelectors[type] = parentSelector;
6894
6925
  const doMount = () => {
6895
6926
  if (cancelled) return;
6896
6927
  const isVgsMode = states.cardTokenizationMode === "vgs";
6928
+ console.log(
6929
+ `[PaymentKit] card.doMount(${type}) \u2014 mode: ${states.cardTokenizationMode}, vgsVaultId: ${states.vgsVaultId ?? "unset"}, vgsEnvironment: ${states.vgsEnvironment ?? "unset"}`
6930
+ );
6897
6931
  if (isVgsMode && states.vgsVaultId && states.vgsEnvironment) {
6898
6932
  if (onFocusChange) {
6899
6933
  if (!states.vgsFocusCallbacks) states.vgsFocusCallbacks = {};
@@ -6902,18 +6936,20 @@ var PaymentKit = (() => {
6902
6936
  if (type === "card_pan") {
6903
6937
  const vaultId = states.vgsVaultId;
6904
6938
  const vgsEnv = states.vgsEnvironment;
6939
+ console.log(`[PaymentKit] VGS mode active \u2014 loading VGS Collect CDN for vault ${vaultId} (${vgsEnv})...`);
6905
6940
  const VGS_CDN_TIMEOUT_MS = 15e3;
6906
6941
  let cdnTimeoutId;
6907
6942
  Promise.race([
6908
6943
  loadVgsCollectScript(),
6909
6944
  new Promise((_2, reject) => {
6910
- cdnTimeoutId = setTimeout(
6911
- () => reject(new Error("VGS Collect CDN load timed out")),
6912
- VGS_CDN_TIMEOUT_MS
6913
- );
6945
+ cdnTimeoutId = setTimeout(() => {
6946
+ console.warn(`[PaymentKit] VGS Collect CDN load timed out after ${VGS_CDN_TIMEOUT_MS / 1e3}s`);
6947
+ reject(new Error("VGS Collect CDN load timed out"));
6948
+ }, VGS_CDN_TIMEOUT_MS);
6914
6949
  })
6915
6950
  ]).finally(() => clearTimeout(cdnTimeoutId)).then(() => {
6916
6951
  if (cancelled) return;
6952
+ console.log("[PaymentKit] VGS Collect CDN loaded \u2014 initializing form...");
6917
6953
  const form = initVgsCollect(vaultId, vgsEnv);
6918
6954
  if (cancelled) {
6919
6955
  form.unmount();
@@ -6923,14 +6959,17 @@ var PaymentKit = (() => {
6923
6959
  const css = style ? Object.fromEntries(
6924
6960
  Object.entries(style).map(([k2, v2]) => [k2.replace(/([A-Z])/g, "-$1").toLowerCase(), v2])
6925
6961
  ) : void 0;
6926
- const expSelector = parentSelector.replace(/card[-_]pan/, (m2) => m2.replace("pan", "exp"));
6927
- const cvcSelector = parentSelector.replace(/card[-_]pan/, (m2) => m2.replace("pan", "cvc"));
6928
- if (expSelector === parentSelector || cvcSelector === parentSelector) {
6929
- const msg = `[PaymentKit] Failed to derive exp/cvc selectors from "${parentSelector}". Expected a selector containing "card-pan" or "card_pan".`;
6962
+ const expSelector = states.vgsMountSelectors?.card_exp;
6963
+ const cvcSelector = states.vgsMountSelectors?.card_cvc;
6964
+ if (!expSelector || !cvcSelector) {
6965
+ const msg = `[PaymentKit] VGS mode requires all three card fields to be mounted. Missing: ${!expSelector ? "card_exp" : ""}${!expSelector && !cvcSelector ? ", " : ""}${!cvcSelector ? "card_cvc" : ""}`;
6930
6966
  console.error(msg);
6931
6967
  onLoaded?.();
6932
6968
  return;
6933
6969
  }
6970
+ console.log(
6971
+ `[PaymentKit] Creating VGS card fields \u2014 pan: ${parentSelector}, exp: ${expSelector}, cvc: ${cvcSelector}`
6972
+ );
6934
6973
  createVgsCardFields(
6935
6974
  form,
6936
6975
  {
@@ -6941,6 +6980,7 @@ var PaymentKit = (() => {
6941
6980
  css,
6942
6981
  states.vgsFocusCallbacks
6943
6982
  );
6983
+ console.log("[PaymentKit] VGS card fields created successfully");
6944
6984
  timingTracker.trackInputReady();
6945
6985
  onLoaded?.();
6946
6986
  }).catch((err) => {
@@ -6959,6 +6999,11 @@ var PaymentKit = (() => {
6959
6999
  };
6960
7000
  return;
6961
7001
  }
7002
+ if (isVgsMode) {
7003
+ console.warn(
7004
+ `[PaymentKit] VGS mode requested but config incomplete (vgsVaultId: ${states.vgsVaultId ?? "unset"}, vgsEnvironment: ${states.vgsEnvironment ?? "unset"}) \u2014 using direct mode`
7005
+ );
7006
+ }
6962
7007
  const parent = $(parentSelector);
6963
7008
  const params = {
6964
7009
  checkout_token: secureToken,
@@ -7030,6 +7075,7 @@ var PaymentKit = (() => {
7030
7075
  states.cardSetupIntentId = res.cardSetupIntentId;
7031
7076
  }
7032
7077
  if (isVgsMode) {
7078
+ console.log("[PaymentKit] Submitting card via VGS CMP...");
7033
7079
  const vgsSubmitResult = await submitVgsCardFields(states, tunnelX);
7034
7080
  if (!vgsSubmitResult.isSuccess) {
7035
7081
  timingTracker.trackFail(null, "card_submit_error", "VGS card submission failed");