@payment-kit-js/vanilla 0.5.1 → 0.5.2

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.2
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.2";
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
  };
@@ -6894,6 +6923,9 @@ var PaymentKit = (() => {
6894
6923
  const doMount = () => {
6895
6924
  if (cancelled) return;
6896
6925
  const isVgsMode = states.cardTokenizationMode === "vgs";
6926
+ console.log(
6927
+ `[PaymentKit] card.doMount(${type}) \u2014 mode: ${states.cardTokenizationMode}, vgsVaultId: ${states.vgsVaultId ?? "unset"}, vgsEnvironment: ${states.vgsEnvironment ?? "unset"}`
6928
+ );
6897
6929
  if (isVgsMode && states.vgsVaultId && states.vgsEnvironment) {
6898
6930
  if (onFocusChange) {
6899
6931
  if (!states.vgsFocusCallbacks) states.vgsFocusCallbacks = {};
@@ -6902,18 +6934,20 @@ var PaymentKit = (() => {
6902
6934
  if (type === "card_pan") {
6903
6935
  const vaultId = states.vgsVaultId;
6904
6936
  const vgsEnv = states.vgsEnvironment;
6937
+ console.log(`[PaymentKit] VGS mode active \u2014 loading VGS Collect CDN for vault ${vaultId} (${vgsEnv})...`);
6905
6938
  const VGS_CDN_TIMEOUT_MS = 15e3;
6906
6939
  let cdnTimeoutId;
6907
6940
  Promise.race([
6908
6941
  loadVgsCollectScript(),
6909
6942
  new Promise((_2, reject) => {
6910
- cdnTimeoutId = setTimeout(
6911
- () => reject(new Error("VGS Collect CDN load timed out")),
6912
- VGS_CDN_TIMEOUT_MS
6913
- );
6943
+ cdnTimeoutId = setTimeout(() => {
6944
+ console.warn(`[PaymentKit] VGS Collect CDN load timed out after ${VGS_CDN_TIMEOUT_MS / 1e3}s`);
6945
+ reject(new Error("VGS Collect CDN load timed out"));
6946
+ }, VGS_CDN_TIMEOUT_MS);
6914
6947
  })
6915
6948
  ]).finally(() => clearTimeout(cdnTimeoutId)).then(() => {
6916
6949
  if (cancelled) return;
6950
+ console.log("[PaymentKit] VGS Collect CDN loaded \u2014 initializing form...");
6917
6951
  const form = initVgsCollect(vaultId, vgsEnv);
6918
6952
  if (cancelled) {
6919
6953
  form.unmount();
@@ -6931,6 +6965,9 @@ var PaymentKit = (() => {
6931
6965
  onLoaded?.();
6932
6966
  return;
6933
6967
  }
6968
+ console.log(
6969
+ `[PaymentKit] Creating VGS card fields \u2014 pan: ${parentSelector}, exp: ${expSelector}, cvc: ${cvcSelector}`
6970
+ );
6934
6971
  createVgsCardFields(
6935
6972
  form,
6936
6973
  {
@@ -6941,6 +6978,7 @@ var PaymentKit = (() => {
6941
6978
  css,
6942
6979
  states.vgsFocusCallbacks
6943
6980
  );
6981
+ console.log("[PaymentKit] VGS card fields created successfully");
6944
6982
  timingTracker.trackInputReady();
6945
6983
  onLoaded?.();
6946
6984
  }).catch((err) => {
@@ -6959,6 +6997,11 @@ var PaymentKit = (() => {
6959
6997
  };
6960
6998
  return;
6961
6999
  }
7000
+ if (isVgsMode) {
7001
+ console.warn(
7002
+ `[PaymentKit] VGS mode requested but config incomplete (vgsVaultId: ${states.vgsVaultId ?? "unset"}, vgsEnvironment: ${states.vgsEnvironment ?? "unset"}) \u2014 using direct mode`
7003
+ );
7004
+ }
6962
7005
  const parent = $(parentSelector);
6963
7006
  const params = {
6964
7007
  checkout_token: secureToken,
@@ -7030,6 +7073,7 @@ var PaymentKit = (() => {
7030
7073
  states.cardSetupIntentId = res.cardSetupIntentId;
7031
7074
  }
7032
7075
  if (isVgsMode) {
7076
+ console.log("[PaymentKit] Submitting card via VGS CMP...");
7033
7077
  const vgsSubmitResult = await submitVgsCardFields(states, tunnelX);
7034
7078
  if (!vgsSubmitResult.isSuccess) {
7035
7079
  timingTracker.trackFail(null, "card_submit_error", "VGS card submission failed");