@payment-kit-js/vanilla 0.5.7 → 0.5.9

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.7
2
+ * PaymentKit.js v0.5.9
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.7";
45
+ var version = "0.5.9";
46
46
 
47
47
  // src/analytics/mock-adapter.ts
48
48
  var MockAnalyticsAdapter = class {
@@ -85,7 +85,7 @@ var PaymentKit = (() => {
85
85
  }
86
86
  };
87
87
 
88
- // ../../node_modules/posthog-js/dist/module.js
88
+ // node_modules/posthog-js/dist/module.js
89
89
  var t = "undefined" != typeof window ? window : void 0;
90
90
  var i = "undefined" != typeof globalThis ? globalThis : t;
91
91
  "undefined" == typeof self && (i.self = i), "undefined" == typeof File && (i.File = function() {
@@ -6053,8 +6053,8 @@ var PaymentKit = (() => {
6053
6053
  apiBaseUrl: "https://staging.paymentkit.com"
6054
6054
  },
6055
6055
  production: {
6056
- baseUrl: "https://paymentkit.com/customer",
6057
- apiBaseUrl: "https://paymentkit.com"
6056
+ baseUrl: "https://app.paymentkit.com/customer",
6057
+ apiBaseUrl: "https://app.paymentkit.com"
6058
6058
  }
6059
6059
  };
6060
6060
  function getTunnelUrls() {
@@ -6864,6 +6864,14 @@ var PaymentKit = (() => {
6864
6864
  "box-sizing": "border-box",
6865
6865
  ...containerPadding && containerPadding !== "0px" ? { padding: containerPadding } : {}
6866
6866
  };
6867
+ for (const selector of [mountPoints.pan, mountPoints.exp, mountPoints.cvc]) {
6868
+ const container = document.querySelector(selector);
6869
+ if (!container) continue;
6870
+ const staleIframes = container.querySelectorAll("iframe");
6871
+ for (const iframe of staleIframes) {
6872
+ iframe.remove();
6873
+ }
6874
+ }
6867
6875
  const panField = form.cardNumberField(mountPoints.pan, {
6868
6876
  placeholder: placeholders?.card_pan ?? "Card number",
6869
6877
  validations: ["required", "validCardNumber"],
@@ -6883,9 +6891,12 @@ var PaymentKit = (() => {
6883
6891
  validations: ["required", "validCardSecurityCode"],
6884
6892
  css: fieldCss
6885
6893
  });
6894
+ const observers = [];
6895
+ const containers = [];
6886
6896
  for (const selector of [mountPoints.pan, mountPoints.exp, mountPoints.cvc]) {
6887
6897
  const container = document.querySelector(selector);
6888
6898
  if (!container) continue;
6899
+ containers.push(container);
6889
6900
  const styleIframe = (iframe) => {
6890
6901
  const containerEl = container;
6891
6902
  if (getComputedStyle(containerEl).position === "static") {
@@ -6897,18 +6908,17 @@ var PaymentKit = (() => {
6897
6908
  iframe.style.height = "100%";
6898
6909
  iframe.style.border = "none";
6899
6910
  };
6911
+ const observer = new MutationObserver(() => {
6912
+ const iframe = container.querySelector("iframe");
6913
+ if (iframe && iframe.style.position !== "absolute") {
6914
+ styleIframe(iframe);
6915
+ }
6916
+ });
6917
+ observer.observe(container, { childList: true, subtree: true });
6918
+ observers.push(observer);
6900
6919
  const existing = container.querySelector("iframe");
6901
- if (existing) {
6920
+ if (existing && existing.style.position !== "absolute") {
6902
6921
  styleIframe(existing);
6903
- } else {
6904
- const observer = new MutationObserver((_2, obs) => {
6905
- const iframe = container.querySelector("iframe");
6906
- if (iframe) {
6907
- styleIframe(iframe);
6908
- obs.disconnect();
6909
- }
6910
- });
6911
- observer.observe(container, { childList: true, subtree: true });
6912
6922
  }
6913
6923
  }
6914
6924
  if (onFocusChangeCallbacks) {
@@ -6925,6 +6935,17 @@ var PaymentKit = (() => {
6925
6935
  }
6926
6936
  }
6927
6937
  }
6938
+ return () => {
6939
+ for (const observer of observers) {
6940
+ observer.disconnect();
6941
+ }
6942
+ for (const container of containers) {
6943
+ const iframes = container.querySelectorAll("iframe");
6944
+ for (const iframe of iframes) {
6945
+ iframe.remove();
6946
+ }
6947
+ }
6948
+ };
6928
6949
  }
6929
6950
 
6930
6951
  // src/payment-methods/card.ts
@@ -6941,13 +6962,37 @@ var PaymentKit = (() => {
6941
6962
  };
6942
6963
  var mapFieldsToCustomerInfo = (fields) => {
6943
6964
  const { firstName, lastName } = splitName(fields.customer_name);
6965
+ const hasBillingAddress = fields.customer_country || fields.customer_zip_code || fields.customer_address_line1 || fields.customer_address_line2 || fields.customer_city || fields.customer_state;
6966
+ const hasShippingAddress = fields.shipping_address_line1 || fields.shipping_address_line2 || fields.shipping_city || fields.shipping_state || fields.shipping_zip_code || fields.shipping_country;
6967
+ let taxIds;
6968
+ if (fields.customer_tax_ids) {
6969
+ try {
6970
+ taxIds = JSON.parse(fields.customer_tax_ids);
6971
+ } catch {
6972
+ taxIds = void 0;
6973
+ }
6974
+ }
6944
6975
  return {
6945
6976
  email: fields.customer_email || void 0,
6946
6977
  firstName,
6947
6978
  lastName,
6948
- billingAddress: fields.customer_country || fields.customer_zip_code ? {
6979
+ businessName: fields.customer_business_name || void 0,
6980
+ taxIds: taxIds?.length ? taxIds : void 0,
6981
+ billingAddress: hasBillingAddress ? {
6949
6982
  country: fields.customer_country || void 0,
6950
- zipCode: fields.customer_zip_code || void 0
6983
+ zipCode: fields.customer_zip_code || void 0,
6984
+ line1: fields.customer_address_line1 || void 0,
6985
+ line2: fields.customer_address_line2 || void 0,
6986
+ city: fields.customer_city || void 0,
6987
+ state: fields.customer_state || void 0
6988
+ } : void 0,
6989
+ shippingAddress: hasShippingAddress ? {
6990
+ line1: fields.shipping_address_line1 || void 0,
6991
+ line2: fields.shipping_address_line2 || void 0,
6992
+ city: fields.shipping_city || void 0,
6993
+ state: fields.shipping_state || void 0,
6994
+ zipCode: fields.shipping_zip_code || void 0,
6995
+ country: fields.shipping_country || void 0
6951
6996
  } : void 0
6952
6997
  };
6953
6998
  };
@@ -7013,7 +7058,7 @@ var PaymentKit = (() => {
7013
7058
  console.log(
7014
7059
  `[PaymentKit] Creating VGS card fields \u2014 pan: ${parentSelector}, exp: ${expSelector}, cvc: ${cvcSelector}`
7015
7060
  );
7016
- createVgsCardFields(
7061
+ states.vgsFieldsCleanup = createVgsCardFields(
7017
7062
  form,
7018
7063
  {
7019
7064
  pan: parentSelector,
@@ -7037,6 +7082,8 @@ var PaymentKit = (() => {
7037
7082
  }
7038
7083
  cleanupVgs = () => {
7039
7084
  if (type === "card_pan" && states.vgsForm) {
7085
+ states.vgsFieldsCleanup?.();
7086
+ states.vgsFieldsCleanup = void 0;
7040
7087
  states.vgsForm.unmount();
7041
7088
  states.vgsForm = void 0;
7042
7089
  }
@@ -7105,14 +7152,15 @@ var PaymentKit = (() => {
7105
7152
  };
7106
7153
  };
7107
7154
  var defSubmitPayment = (states) => {
7108
- const submitPayment = async (fields) => {
7155
+ const submitPayment = async (fields, options) => {
7109
7156
  if (states._sessionConfigReady) await states._sessionConfigReady;
7110
7157
  const isVgsMode = states.cardTokenizationMode === "vgs";
7111
7158
  const { timingTracker, checkoutRequestId } = states;
7112
7159
  timingTracker.trackSubmit();
7113
7160
  const requestOptions = withRequestId(checkoutRequestId);
7114
7161
  const tunnelX = await TunnelXManager.createFromPenpalConnection(states.tunnelXConnection);
7115
- const validateFormResult = await validateFormFields(fields);
7162
+ const skipCustomerValidation = options?.skipCustomerValidation === true;
7163
+ const validateFormResult = skipCustomerValidation ? { isSuccess: true } : await validateFormFields(fields);
7116
7164
  if (!isVgsMode) {
7117
7165
  const validateCardResult = await validateCardFields(states);
7118
7166
  if (!(validateCardResult.isSuccess && validateFormResult.isSuccess)) {
@@ -7278,6 +7326,9 @@ var PaymentKit = (() => {
7278
7326
  );
7279
7327
  })
7280
7328
  ]).finally(() => clearTimeout(createCardTimeoutId));
7329
+ if (!cardResult?.data?.attributes) {
7330
+ throw new Error("VGS createCard returned an invalid response");
7331
+ }
7281
7332
  const { pan_alias, cvc_alias, exp_month, exp_year } = cardResult.data.attributes;
7282
7333
  const fullYear = exp_year < 100 ? 2e3 + exp_year : exp_year;
7283
7334
  const formattedExp = `${String(exp_month).padStart(2, "0")}/${fullYear}`;
@@ -7348,6 +7399,8 @@ var PaymentKit = (() => {
7348
7399
  submitPayment: defSubmitPayment(localStates),
7349
7400
  cleanup: () => {
7350
7401
  if (localStates.vgsForm) {
7402
+ localStates.vgsFieldsCleanup?.();
7403
+ localStates.vgsFieldsCleanup = void 0;
7351
7404
  localStates.vgsForm.unmount();
7352
7405
  localStates.vgsForm = void 0;
7353
7406
  }