@pelcro/react-pelcro-js 3.49.0 → 3.51.0

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.
package/dist/index.cjs.js CHANGED
@@ -11682,6 +11682,101 @@ function getFourDigitYear(lastTwoDigits) {
11682
11682
  return fourDigitYear;
11683
11683
  }
11684
11684
 
11685
+ /**
11686
+ * Loads Braintree Drop-in UI script
11687
+ * @returns {Promise} Promise that resolves when script is loaded
11688
+ */
11689
+ function loadBraintreeScript() {
11690
+ return new Promise((resolve, reject) => {
11691
+ // Check if script is already loaded
11692
+ if (window.braintree) {
11693
+ console.log("Braintree script already loaded");
11694
+ resolve(window.braintree);
11695
+ return;
11696
+ }
11697
+ console.log("Loading Braintree script...");
11698
+ const script = document.createElement("script");
11699
+ script.src = "https://js.braintreegateway.com/web/dropin/1.45.1/js/dropin.js";
11700
+ script.onload = () => {
11701
+ console.log("Braintree script loaded successfully");
11702
+ resolve(window.braintree);
11703
+ };
11704
+ script.onerror = error => {
11705
+ console.error("Failed to load Braintree script:", error);
11706
+ reject(new Error("Failed to load Braintree script"));
11707
+ };
11708
+ document.head.appendChild(script);
11709
+ });
11710
+ }
11711
+
11712
+ /**
11713
+ * Creates Braintree Drop-in UI instance
11714
+ * @param {string} authorization - Braintree authorization token
11715
+ * @param {string} selector - CSS selector for the container
11716
+ * @param {Object} options - Additional options for dropin creation
11717
+ * @returns {Promise} Promise that resolves with the dropin instance
11718
+ */
11719
+ function createBraintreeDropin(authorization, selector) {
11720
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
11721
+ console.log("Creating Braintree Drop-in with:", {
11722
+ authorization: authorization ? "present" : "missing",
11723
+ selector,
11724
+ options
11725
+ });
11726
+ return loadBraintreeScript().then(() => {
11727
+ console.log("Braintree script loaded, creating dropin...");
11728
+ return new Promise((resolve, reject) => {
11729
+ window.braintree.dropin.create({
11730
+ authorization,
11731
+ selector,
11732
+ ...options
11733
+ }, (err, instance) => {
11734
+ if (err) {
11735
+ console.error("Braintree dropin creation failed:", err);
11736
+ reject(err);
11737
+ } else {
11738
+ console.log("Braintree dropin created successfully:", instance);
11739
+ resolve(instance);
11740
+ }
11741
+ });
11742
+ });
11743
+ });
11744
+ }
11745
+
11746
+ /**
11747
+ * Requests payment method from Braintree Drop-in UI
11748
+ * @param {Object} instance - Braintree dropin instance
11749
+ * @returns {Promise} Promise that resolves with payment method payload
11750
+ */
11751
+ function requestBraintreePaymentMethod(instance) {
11752
+ return new Promise((resolve, reject) => {
11753
+ instance.requestPaymentMethod((err, payload) => {
11754
+ if (err) {
11755
+ reject(err);
11756
+ } else {
11757
+ resolve(payload);
11758
+ }
11759
+ });
11760
+ });
11761
+ }
11762
+
11763
+ /**
11764
+ * Requests payment method from Braintree Hosted Fields
11765
+ * @param {Object} hostedFieldsInstance - Braintree hosted fields instance
11766
+ * @returns {Promise} Promise that resolves with payment method payload
11767
+ */
11768
+ function requestBraintreeHostedFieldsPaymentMethod(hostedFieldsInstance) {
11769
+ return new Promise((resolve, reject) => {
11770
+ hostedFieldsInstance.tokenize((err, payload) => {
11771
+ if (err) {
11772
+ reject(err);
11773
+ } else {
11774
+ resolve(payload);
11775
+ }
11776
+ });
11777
+ });
11778
+ }
11779
+
11685
11780
  /**
11686
11781
  * @typedef {Object} OptionsType
11687
11782
  * @property {boolean} loadPaymentSDKs
@@ -11792,6 +11887,7 @@ const loadPaymentSDKs = () => {
11792
11887
  // "braintree-3D-secure-sdk"
11793
11888
  // );
11794
11889
  window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.99.0/js/hosted-fields.min.js", "braintree-hosted-fields-sdk");
11890
+ window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/dropin/1.45.1/js/dropin.js", "braintree-dropin-sdk");
11795
11891
  }
11796
11892
 
11797
11893
  // Load Vantiv SDKs
@@ -11836,16 +11932,16 @@ const initSecuritySdk = () => {
11836
11932
  });
11837
11933
  };
11838
11934
  const initGATracking = () => {
11839
- var _window, _window$Pelcro, _window$Pelcro$uiSett;
11935
+ var _window, _window$Pelcro, _window$Pelcro$uiSett, _window2, _window2$Pelcro, _window2$Pelcro$uiSet;
11840
11936
  const enableReactGA4 = (_window = window) === null || _window === void 0 ? void 0 : (_window$Pelcro = _window.Pelcro) === null || _window$Pelcro === void 0 ? void 0 : (_window$Pelcro$uiSett = _window$Pelcro.uiSettings) === null || _window$Pelcro$uiSett === void 0 ? void 0 : _window$Pelcro$uiSett.enableReactGA4;
11937
+ // Respect disablePageViewEvents flag from uiSettings
11938
+ const disablePageViewEvents = ((_window2 = window) === null || _window2 === void 0 ? void 0 : (_window2$Pelcro = _window2.Pelcro) === null || _window2$Pelcro === void 0 ? void 0 : (_window2$Pelcro$uiSet = _window2$Pelcro.uiSettings) === null || _window2$Pelcro$uiSet === void 0 ? void 0 : _window2$Pelcro$uiSet.disablePageViewEvents) || false;
11841
11939
  if (window.Pelcro.site.read().google_analytics_id) {
11842
11940
  if (enableReactGA4) {
11843
- // Initialize ReactGA4 with your tracking ID
11844
- ReactGA4.initialize(window.Pelcro.site.read().google_analytics_id);
11845
- // Enable e-commerce tracking
11941
+ // Initialize ReactGA4 with your tracking ID and options, only once
11846
11942
  ReactGA4.initialize(window.Pelcro.site.read().google_analytics_id, {
11847
11943
  gaOptions: {
11848
- send_page_view: true,
11944
+ send_page_view: disablePageViewEvents ? false : true,
11849
11945
  ecommerce: {
11850
11946
  enabled: true
11851
11947
  }
@@ -11859,8 +11955,8 @@ const initGATracking = () => {
11859
11955
  }
11860
11956
  };
11861
11957
  const dispatchModalDisplayEvents = modalName => {
11862
- var _window2, _window2$Pelcro, _window2$Pelcro$uiSet, _modalName$replace, _modalName$replace2;
11863
- const enableReactGA4 = (_window2 = window) === null || _window2 === void 0 ? void 0 : (_window2$Pelcro = _window2.Pelcro) === null || _window2$Pelcro === void 0 ? void 0 : (_window2$Pelcro$uiSet = _window2$Pelcro.uiSettings) === null || _window2$Pelcro$uiSet === void 0 ? void 0 : _window2$Pelcro$uiSet.enableReactGA4;
11958
+ var _window3, _window3$Pelcro, _window3$Pelcro$uiSet, _modalName$replace, _modalName$replace2;
11959
+ const enableReactGA4 = (_window3 = window) === null || _window3 === void 0 ? void 0 : (_window3$Pelcro = _window3.Pelcro) === null || _window3$Pelcro === void 0 ? void 0 : (_window3$Pelcro$uiSet = _window3$Pelcro.uiSettings) === null || _window3$Pelcro$uiSet === void 0 ? void 0 : _window3$Pelcro$uiSet.enableReactGA4;
11864
11960
  const formattedAction = modalName === null || modalName === void 0 ? void 0 : (_modalName$replace = modalName.replace("pelcro-", "")) === null || _modalName$replace === void 0 ? void 0 : _modalName$replace.replaceAll("-", " ");
11865
11961
  if (enableReactGA4) {
11866
11962
  ReactGA4.event(`${formattedAction} viewed`, {
@@ -16454,10 +16550,6 @@ var es_13 = es.StripeProvider;
16454
16550
 
16455
16551
  function _classPrivateFieldInitSpec$1(obj, privateMap, value) { _checkPrivateRedeclaration$1(obj, privateMap); privateMap.set(obj, value); }
16456
16552
  function _checkPrivateRedeclaration$1(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
16457
- /**
16458
- * @TODO: All payment related business logic should end up moving
16459
- * to this service, and out of react components.
16460
- */
16461
16553
 
16462
16554
  /**
16463
16555
  * Enum for payment types
@@ -16593,6 +16685,16 @@ class StripeGateway {
16593
16685
  console.error("Unsupported payment method: Stripe Gateway");
16594
16686
  }
16595
16687
  });
16688
+ _defineProperty$3(this, "createDropin", function (authorization, selector) {
16689
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
16690
+ return createBraintreeDropin(authorization, selector, options);
16691
+ });
16692
+ _defineProperty$3(this, "requestPaymentMethod", instance => {
16693
+ return requestBraintreePaymentMethod(instance);
16694
+ });
16695
+ _defineProperty$3(this, "loadScript", () => {
16696
+ return loadBraintreeScript();
16697
+ });
16596
16698
  _classPrivateFieldInitSpec$1(this, _createSubscription, {
16597
16699
  writable: true,
16598
16700
  value: (options, callback) => {
@@ -17273,6 +17375,9 @@ class TapGateway {
17273
17375
  }
17274
17376
  }
17275
17377
 
17378
+ /**
17379
+ * Cybersource gateway strategy
17380
+ */
17276
17381
  /**
17277
17382
  * Cybersource gateway strategy
17278
17383
  */
@@ -17319,7 +17424,9 @@ class CybersourceGateway {
17319
17424
  quantity = 1,
17320
17425
  addressId,
17321
17426
  isExistingSource,
17322
- fingerprint_session_id
17427
+ fingerprint_session_id,
17428
+ cardExpirationMonth,
17429
+ cardExpirationYear
17323
17430
  } = options;
17324
17431
  const params = isExistingSource ? {
17325
17432
  source_id: token
@@ -17335,6 +17442,8 @@ class CybersourceGateway {
17335
17442
  coupon_code: couponCode,
17336
17443
  address_id: product.address_required ? addressId : null,
17337
17444
  fingerprint_session_id: fingerprint_session_id,
17445
+ card_expiration_month: cardExpirationMonth,
17446
+ card_expiration_year: cardExpirationYear,
17338
17447
  ...params
17339
17448
  }, (err, res) => {
17340
17449
  callback(err, res);
@@ -17351,7 +17460,9 @@ class CybersourceGateway {
17351
17460
  couponCode,
17352
17461
  product,
17353
17462
  addressId,
17354
- isExistingSource
17463
+ isExistingSource,
17464
+ cardExpirationMonth,
17465
+ cardExpirationYear
17355
17466
  } = options;
17356
17467
  const params = isExistingSource ? {
17357
17468
  source_id: token
@@ -17366,6 +17477,8 @@ class CybersourceGateway {
17366
17477
  campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
17367
17478
  subscription_id: subscriptionIdToRenew,
17368
17479
  address_id: product.address_required ? addressId : null,
17480
+ card_expiration_month: cardExpirationMonth,
17481
+ card_expiration_year: cardExpirationYear,
17369
17482
  ...params
17370
17483
  }, (err, res) => {
17371
17484
  callback(err, res);
@@ -17383,7 +17496,9 @@ class CybersourceGateway {
17383
17496
  giftRecipient,
17384
17497
  quantity = 1,
17385
17498
  addressId,
17386
- isExistingSource
17499
+ isExistingSource,
17500
+ cardExpirationMonth,
17501
+ cardExpirationYear
17387
17502
  } = options;
17388
17503
  const params = isExistingSource ? {
17389
17504
  source_id: token
@@ -17403,6 +17518,8 @@ class CybersourceGateway {
17403
17518
  gift_start_date: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.startDate,
17404
17519
  gift_message: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.giftMessage,
17405
17520
  address_id: product.address_required ? addressId : null,
17521
+ card_expiration_month: cardExpirationMonth,
17522
+ card_expiration_year: cardExpirationYear,
17406
17523
  ...params
17407
17524
  }, (err, res) => {
17408
17525
  callback(err, res);
@@ -17419,7 +17536,9 @@ class CybersourceGateway {
17419
17536
  plan,
17420
17537
  couponCode,
17421
17538
  addressId,
17422
- isExistingSource
17539
+ isExistingSource,
17540
+ cardExpirationMonth,
17541
+ cardExpirationYear
17423
17542
  } = options;
17424
17543
  const params = isExistingSource ? {
17425
17544
  source_id: token
@@ -17433,6 +17552,8 @@ class CybersourceGateway {
17433
17552
  coupon_code: couponCode,
17434
17553
  subscription_id: subscriptionIdToRenew,
17435
17554
  address_id: product.address_required ? addressId : null,
17555
+ card_expiration_month: cardExpirationMonth,
17556
+ card_expiration_year: cardExpirationYear,
17436
17557
  ...params
17437
17558
  }, (err, res) => {
17438
17559
  callback(err, res);
@@ -17447,7 +17568,9 @@ class CybersourceGateway {
17447
17568
  items,
17448
17569
  couponCode,
17449
17570
  addressId,
17450
- isExistingSource
17571
+ isExistingSource,
17572
+ cardExpirationMonth,
17573
+ cardExpirationYear
17451
17574
  } = options;
17452
17575
  const params = isExistingSource ? {
17453
17576
  source_id: token
@@ -17462,7 +17585,9 @@ class CybersourceGateway {
17462
17585
  ...params,
17463
17586
  ...(addressId && {
17464
17587
  address_id: addressId
17465
- })
17588
+ }),
17589
+ card_expiration_month: cardExpirationMonth,
17590
+ card_expiration_year: cardExpirationYear
17466
17591
  }, (err, res) => {
17467
17592
  callback(err, res);
17468
17593
  });
@@ -17813,6 +17938,79 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17813
17938
  });
17814
17939
  updateTotalAmountWithTax();
17815
17940
  }, []);
17941
+ // Helper function to calculate total amount for payment methods
17942
+ const calculateTotalAmount = (state, plan, invoice, order) => {
17943
+ var _ref2, _ref3, _state$updatedPrice;
17944
+ const getOrderItemsTotal = () => {
17945
+ if (!order) {
17946
+ return null;
17947
+ }
17948
+ const isQuickPurchase = !Array.isArray(order);
17949
+ if (isQuickPurchase) {
17950
+ return order.price * order.quantity;
17951
+ }
17952
+ if (order.length === 0) {
17953
+ return null;
17954
+ }
17955
+ return order.reduce((total, item) => {
17956
+ return total + item.price * item.quantity;
17957
+ }, 0);
17958
+ };
17959
+ return (_ref2 = (_ref3 = (_state$updatedPrice = state === null || state === void 0 ? void 0 : state.updatedPrice) !== null && _state$updatedPrice !== void 0 ? _state$updatedPrice : plan === null || plan === void 0 ? void 0 : plan.amount) !== null && _ref3 !== void 0 ? _ref3 : invoice === null || invoice === void 0 ? void 0 : invoice.amount_remaining) !== null && _ref2 !== void 0 ? _ref2 : getOrderItemsTotal();
17960
+ };
17961
+
17962
+ // Helper function to get currency from the appropriate source
17963
+ const getCurrencyFromPaymentType = (plan, order, invoice) => {
17964
+ if (plan) {
17965
+ return plan.currency;
17966
+ } else if (order) {
17967
+ var _order$;
17968
+ // Handle both single order and array of orders
17969
+ const isQuickPurchase = !Array.isArray(order);
17970
+ return isQuickPurchase ? order.currency : (_order$ = order[0]) === null || _order$ === void 0 ? void 0 : _order$.currency;
17971
+ } else if (invoice) {
17972
+ return invoice.currency;
17973
+ }
17974
+ return "USD"; // Default fallback
17975
+ };
17976
+
17977
+ // Helper function to get payment label
17978
+ const getPaymentLabel = (plan, order, invoice) => {
17979
+ var _window$Pelcro$site$r;
17980
+ if (plan) {
17981
+ return plan.nickname || plan.description || "Subscription";
17982
+ } else if (order) {
17983
+ // Handle both single order and array of orders
17984
+ const isQuickPurchase = !Array.isArray(order);
17985
+ if (isQuickPurchase) {
17986
+ return order.name || "Order";
17987
+ } else {
17988
+ return order.length === 1 ? order[0].name : "Order";
17989
+ }
17990
+ } else if (invoice) {
17991
+ return `Invoice #${invoice.id}`;
17992
+ }
17993
+ return ((_window$Pelcro$site$r = window.Pelcro.site.read()) === null || _window$Pelcro$site$r === void 0 ? void 0 : _window$Pelcro$site$r.name) || "Payment";
17994
+ };
17995
+
17996
+ // Helper function to format amount for payment methods (Apple Pay, Google Pay)
17997
+ const formatPaymentAmount = function (totalAmount, currency) {
17998
+ var _window$Pelcro2, _window$Pelcro2$utils, _window$Pelcro2$utils2, _currency$toUpperCase;
17999
+ let paymentMethod = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "";
18000
+ if (!totalAmount) return "0.00";
18001
+ const isZeroDecimal = ((_window$Pelcro2 = window.Pelcro) === null || _window$Pelcro2 === void 0 ? void 0 : (_window$Pelcro2$utils = _window$Pelcro2.utils) === null || _window$Pelcro2$utils === void 0 ? void 0 : (_window$Pelcro2$utils2 = _window$Pelcro2$utils.isCurrencyZeroDecimal) === null || _window$Pelcro2$utils2 === void 0 ? void 0 : _window$Pelcro2$utils2.call(_window$Pelcro2$utils, currency)) || ["BIF", "CLP", "DJF", "GNF", "JPY", "KMF", "KRW", "MGA", "PYG", "RWF", "UGX", "VND", "VUV", "XAF", "XOF", "XPF"].includes(currency === null || currency === void 0 ? void 0 : (_currency$toUpperCase = currency.toUpperCase) === null || _currency$toUpperCase === void 0 ? void 0 : _currency$toUpperCase.call(currency));
18002
+
18003
+ // Payment methods expect amount in major currency unit (dollars, not cents)
18004
+ let finalAmount;
18005
+ if (isZeroDecimal) {
18006
+ finalAmount = Math.round(totalAmount).toString();
18007
+ } else {
18008
+ // Convert from cents to dollars and format with 2 decimal places
18009
+ finalAmount = (totalAmount / 100).toFixed(2);
18010
+ }
18011
+ console.log(`${paymentMethod} amount:`, finalAmount, "currency:", currency, "type:", type);
18012
+ return String(finalAmount);
18013
+ };
17816
18014
 
17817
18015
  /* ====== Start Cybersource integration ======== */
17818
18016
  const cybersourceErrorHandle = err => {
@@ -17822,10 +18020,10 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17822
18020
  const errorMessages = [];
17823
18021
 
17824
18022
  // enumerable error (ex: validation errors)
17825
- Object.values(err === null || err === void 0 ? void 0 : (_err$details2 = err.details) === null || _err$details2 === void 0 ? void 0 : (_err$details2$respons = _err$details2.responseStatus) === null || _err$details2$respons === void 0 ? void 0 : _err$details2$respons.details).forEach(_ref2 => {
18023
+ Object.values(err === null || err === void 0 ? void 0 : (_err$details2 = err.details) === null || _err$details2 === void 0 ? void 0 : (_err$details2$respons = _err$details2.responseStatus) === null || _err$details2$respons === void 0 ? void 0 : _err$details2$respons.details).forEach(_ref4 => {
17826
18024
  let {
17827
18025
  message
17828
- } = _ref2;
18026
+ } = _ref4;
17829
18027
  errorMessages.push(message);
17830
18028
  });
17831
18029
 
@@ -17869,7 +18067,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17869
18067
  }
17870
18068
  });
17871
18069
  }
17872
- handleCybersourcePayment(response.token, state);
18070
+ handleCybersourcePayment(response, state);
17873
18071
  });
17874
18072
  };
17875
18073
  function handleCybersourcePayment(paymentRequest, state) {
@@ -17887,7 +18085,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17887
18085
  window.Pelcro.source.create({
17888
18086
  auth_token: window.Pelcro.user.read().auth_token,
17889
18087
  token: paymentRequest,
17890
- gateway: "cybersource"
18088
+ gateway: "cybersource",
18089
+ cardExpirationMonth: state.month,
18090
+ cardExpirationYear: state.year
17891
18091
  }, (err, res) => {
17892
18092
  dispatch({
17893
18093
  type: DISABLE_SUBMIT,
@@ -17915,6 +18115,12 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17915
18115
  content: t("messages.sourceUpdated")
17916
18116
  }
17917
18117
  });
18118
+
18119
+ // Reinitialize Cybersource microform after successful payment
18120
+ setTimeout(() => {
18121
+ cybersourceInstanceRef.current = null;
18122
+ initCybersourceScript();
18123
+ }, 1000);
17918
18124
  onSuccess(res);
17919
18125
  } //
17920
18126
  );
@@ -17938,11 +18144,19 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17938
18144
  product,
17939
18145
  isExistingSource: isUsingExistingPaymentMethod,
17940
18146
  subscriptionIdToRenew,
17941
- addressId: selectedAddressId
18147
+ addressId: selectedAddressId,
18148
+ cardExpirationMonth: state.month,
18149
+ cardExpirationYear: state.year
17942
18150
  }, (err, res) => {
17943
18151
  if (err) {
17944
18152
  return handlePaymentError(err);
17945
18153
  }
18154
+
18155
+ // Reinitialize Cybersource microform after successful payment
18156
+ setTimeout(() => {
18157
+ cybersourceInstanceRef.current = null;
18158
+ initCybersourceScript();
18159
+ }, 1000);
17946
18160
  onSuccess(res);
17947
18161
  });
17948
18162
  } else if (giftSubscriprition) {
@@ -17955,11 +18169,19 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17955
18169
  product,
17956
18170
  isExistingSource: isUsingExistingPaymentMethod,
17957
18171
  giftRecipient,
17958
- addressId: selectedAddressId
18172
+ addressId: selectedAddressId,
18173
+ cardExpirationMonth: state.month,
18174
+ cardExpirationYear: state.year
17959
18175
  }, (err, res) => {
17960
18176
  if (err) {
17961
18177
  return handlePaymentError(err);
17962
18178
  }
18179
+
18180
+ // Reinitialize Cybersource microform after successful payment
18181
+ setTimeout(() => {
18182
+ cybersourceInstanceRef.current = null;
18183
+ initCybersourceScript();
18184
+ }, 1000);
17963
18185
  onSuccess(res);
17964
18186
  });
17965
18187
  } else if (renewSubscription) {
@@ -17972,11 +18194,19 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17972
18194
  product,
17973
18195
  isExistingSource: isUsingExistingPaymentMethod,
17974
18196
  subscriptionIdToRenew,
17975
- addressId: selectedAddressId
18197
+ addressId: selectedAddressId,
18198
+ cardExpirationMonth: state.month,
18199
+ cardExpirationYear: state.year
17976
18200
  }, (err, res) => {
17977
18201
  if (err) {
17978
18202
  return handlePaymentError(err);
17979
18203
  }
18204
+
18205
+ // Reinitialize Cybersource microform after successful payment
18206
+ setTimeout(() => {
18207
+ cybersourceInstanceRef.current = null;
18208
+ initCybersourceScript();
18209
+ }, 1000);
17980
18210
  onSuccess(res);
17981
18211
  });
17982
18212
  } else if (createSubscription) {
@@ -17989,27 +18219,32 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17989
18219
  product,
17990
18220
  isExistingSource: isUsingExistingPaymentMethod,
17991
18221
  addressId: selectedAddressId,
17992
- fingerprint_session_id: state.cyberSourceSessionId
18222
+ fingerprint_session_id: state.cyberSourceSessionId,
18223
+ cardExpirationMonth: state.month,
18224
+ cardExpirationYear: state.year
17993
18225
  }, (err, res) => {
17994
18226
  if (err) {
17995
18227
  return handlePaymentError(err);
17996
18228
  }
18229
+
18230
+ // Reinitialize Cybersource microform after successful payment
18231
+ setTimeout(() => {
18232
+ cybersourceInstanceRef.current = null;
18233
+ initCybersourceScript();
18234
+ }, 1000);
17997
18235
  onSuccess(res);
17998
18236
  });
17999
18237
  }
18000
18238
  }
18001
18239
  }
18002
- const tokenizeCard = (error, microformInstance) => {
18003
- if (error) {
18004
- return;
18005
- }
18006
- cybersourceInstanceRef.current = microformInstance;
18007
- };
18240
+
18241
+ // No longer needed - microform instance is stored directly in initCybersourceScript
18242
+
18008
18243
  const appendCybersourceFingerprintScripts = () => {
18009
- var _window$Pelcro$site$r, _window$Pelcro$site$r2, _window$Pelcro$site$r3, _window$Pelcro$site$r4;
18244
+ var _window$Pelcro$site$r2, _window$Pelcro$site$r3, _window$Pelcro$site$r4, _window$Pelcro$site$r5;
18010
18245
  const uniqueId = crypto.randomUUID();
18011
- const sessionID = ((_window$Pelcro$site$r = window.Pelcro.site.read()) === null || _window$Pelcro$site$r === void 0 ? void 0 : (_window$Pelcro$site$r2 = _window$Pelcro$site$r.cybersource_gateway_settings) === null || _window$Pelcro$site$r2 === void 0 ? void 0 : _window$Pelcro$site$r2.merchant_id) + uniqueId;
18012
- const orgID = (_window$Pelcro$site$r3 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r3 === void 0 ? void 0 : (_window$Pelcro$site$r4 = _window$Pelcro$site$r3.cybersource_gateway_settings) === null || _window$Pelcro$site$r4 === void 0 ? void 0 : _window$Pelcro$site$r4.org_id;
18246
+ const sessionID = ((_window$Pelcro$site$r2 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r2 === void 0 ? void 0 : (_window$Pelcro$site$r3 = _window$Pelcro$site$r2.cybersource_gateway_settings) === null || _window$Pelcro$site$r3 === void 0 ? void 0 : _window$Pelcro$site$r3.merchant_id) + uniqueId;
18247
+ const orgID = (_window$Pelcro$site$r4 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r4 === void 0 ? void 0 : (_window$Pelcro$site$r5 = _window$Pelcro$site$r4.cybersource_gateway_settings) === null || _window$Pelcro$site$r5 === void 0 ? void 0 : _window$Pelcro$site$r5.org_id;
18013
18248
  const fingerPrintScript = document.querySelector(`script[src="https://h.online-metrix.net/fp/tags.js?org_id=${orgID}&session_id=${sessionID}"]`);
18014
18249
  const fingerPringIframe = document.querySelector(`iframe[src="https://h.online-metrix.net/fp/tags?org_id=${orgID}&session_id=${sessionID}"]`);
18015
18250
  if (!fingerPrintScript && !fingerPringIframe) {
@@ -18028,6 +18263,12 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18028
18263
  }
18029
18264
  };
18030
18265
  const initCybersourceScript = () => {
18266
+ // Clear existing card number field before reinitializing
18267
+ const cardNumberElement = document.querySelector("#cybersourceCardNumber");
18268
+ if (cardNumberElement) {
18269
+ cardNumberElement.innerHTML = "";
18270
+ }
18271
+
18031
18272
  // jwk api call
18032
18273
  window.Pelcro.payment.getJWK({
18033
18274
  auth_token: window.Pelcro.user.read().auth_token,
@@ -18052,34 +18293,56 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18052
18293
  });
18053
18294
  }
18054
18295
  const {
18055
- key: jwk
18296
+ key: jwk,
18297
+ captureContext,
18298
+ js_client
18056
18299
  } = res;
18057
- // SETUP MICROFORM
18058
- FLEX.microform({
18059
- keyId: jwk.kid,
18060
- keystore: jwk,
18061
- container: "#cybersourceCardNumber",
18062
- placeholder: "Card Number",
18063
- styles: {
18064
- input: {
18065
- "font-size": "14px",
18066
- "font-family": "helvetica, tahoma, calibri, sans-serif",
18067
- color: "#555"
18068
- },
18069
- ":focus": {
18070
- color: "blue"
18071
- },
18072
- ":disabled": {
18073
- cursor: "not-allowed"
18074
- },
18075
- valid: {
18076
- color: "#3c763d"
18077
- },
18078
- invalid: {
18079
- color: "#a94442"
18300
+
18301
+ // Load the SDK from the dynamic URL (if not already loaded)
18302
+ const existingScript = document.querySelector(`script[src="${js_client}"]`);
18303
+ if (!existingScript) {
18304
+ window.Pelcro.helpers.loadSDK(js_client, "cybersource-cdn");
18305
+ }
18306
+ const initializeMicroform = () => {
18307
+ // SETUP MICROFORM
18308
+ // eslint-disable-next-line no-undef
18309
+ const flex = new Flex(captureContext);
18310
+ const microform = flex.microform({
18311
+ styles: {
18312
+ input: {
18313
+ "font-size": "14px",
18314
+ "font-family": "helvetica, tahoma, calibri, sans-serif",
18315
+ color: "#555"
18316
+ },
18317
+ ":focus": {
18318
+ color: "blue"
18319
+ },
18320
+ ":disabled": {
18321
+ cursor: "not-allowed"
18322
+ },
18323
+ valid: {
18324
+ color: "#3c763d"
18325
+ },
18326
+ invalid: {
18327
+ color: "#a94442"
18328
+ }
18080
18329
  }
18081
- }
18082
- }, tokenizeCard);
18330
+ });
18331
+ const number = microform.createField("number", {
18332
+ placeholder: "Enter your card number"
18333
+ });
18334
+ number.load("#cybersourceCardNumber");
18335
+ cybersourceInstanceRef.current = microform;
18336
+ };
18337
+
18338
+ // Wait for SDK to load then initialize microform
18339
+ if (existingScript) {
18340
+ // Script already loaded, initialize immediately
18341
+ initializeMicroform();
18342
+ } else {
18343
+ // Wait for new script to load
18344
+ document.querySelector(`script[src="${js_client}"]`).addEventListener("load", initializeMicroform);
18345
+ }
18083
18346
  });
18084
18347
  };
18085
18348
 
@@ -18087,7 +18350,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18087
18350
 
18088
18351
  /* ====== Start Tap integration ======== */
18089
18352
  const submitUsingTap = state => {
18090
- var _ref3, _ref4, _ref5, _state$updatedPrice;
18353
+ var _ref5, _ref6, _ref7, _state$updatedPrice2;
18091
18354
  const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
18092
18355
  if (isUsingExistingPaymentMethod) {
18093
18356
  // no need to create a new source using tap
@@ -18111,7 +18374,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18111
18374
  return total + item.price * item.quantity;
18112
18375
  }, 0);
18113
18376
  };
18114
- const totalAmount = (_ref3 = (_ref4 = (_ref5 = (_state$updatedPrice = state === null || state === void 0 ? void 0 : state.updatedPrice) !== null && _state$updatedPrice !== void 0 ? _state$updatedPrice : plan === null || plan === void 0 ? void 0 : plan.amount) !== null && _ref5 !== void 0 ? _ref5 : invoice === null || invoice === void 0 ? void 0 : invoice.amount_remaining) !== null && _ref4 !== void 0 ? _ref4 : getOrderItemsTotal()) !== null && _ref3 !== void 0 ? _ref3 : 10;
18377
+ const totalAmount = (_ref5 = (_ref6 = (_ref7 = (_state$updatedPrice2 = state === null || state === void 0 ? void 0 : state.updatedPrice) !== null && _state$updatedPrice2 !== void 0 ? _state$updatedPrice2 : plan === null || plan === void 0 ? void 0 : plan.amount) !== null && _ref7 !== void 0 ? _ref7 : invoice === null || invoice === void 0 ? void 0 : invoice.amount_remaining) !== null && _ref6 !== void 0 ? _ref6 : getOrderItemsTotal()) !== null && _ref5 !== void 0 ? _ref5 : 10;
18115
18378
  tapInstanceRef.current.createToken(tapInstanceCard.current).then(function (result) {
18116
18379
  if (result.error) {
18117
18380
  // Inform the user if there was an error
@@ -18321,8 +18584,8 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18321
18584
  }
18322
18585
  }
18323
18586
  const initTapScript = () => {
18324
- var _window$Pelcro$site$r5;
18325
- const tapKey = window.Tapjsli((_window$Pelcro$site$r5 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r5 === void 0 ? void 0 : _window$Pelcro$site$r5.tap_gateway_settings.publishable_key);
18587
+ var _window$Pelcro$site$r6;
18588
+ const tapKey = window.Tapjsli((_window$Pelcro$site$r6 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r6 === void 0 ? void 0 : _window$Pelcro$site$r6.tap_gateway_settings.publishable_key);
18326
18589
  let elements = tapKey.elements({});
18327
18590
  let style = {
18328
18591
  base: {
@@ -18372,8 +18635,8 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18372
18635
  };
18373
18636
  /* ====== End Tap integration ======== */
18374
18637
 
18375
- /* ====== Start Braintree integration ======== */
18376
- const braintreeInstanceRef = React__default['default'].useRef(null);
18638
+ /* ====== Start Braintree Drop-in UI integration ======== */
18639
+ const braintreeDropinRef = React__default['default'].useRef(null);
18377
18640
  function getClientToken() {
18378
18641
  return new Promise((resolve, reject) => {
18379
18642
  window.Pelcro.payment.generateClientToken({
@@ -18392,18 +18655,46 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18392
18655
  async function initializeBraintree() {
18393
18656
  if (skipPayment && ((plan === null || plan === void 0 ? void 0 : plan.amount) === 0 || props !== null && props !== void 0 && props.freeOrders)) return;
18394
18657
  if (cardProcessor === "braintree" && !selectedPaymentMethodId) {
18658
+ // Clear container before initializing
18659
+ const dropinContainer = document.getElementById("dropin-container");
18660
+ if (dropinContainer) dropinContainer.innerHTML = "";
18395
18661
  const braintreeToken = await getClientToken();
18396
18662
  const isBraintreeEnabled = Boolean(braintreeToken);
18397
18663
  if (!isBraintreeEnabled) {
18398
18664
  console.error("Braintree integration is currently not enabled on this site's config");
18399
18665
  return;
18400
18666
  }
18667
+ console.log("braintreeToken", plan);
18401
18668
  if (type !== "updatePaymentSource") {
18402
- braintreeInstanceRef.current = new window.braintree.client.create({
18403
- authorization: braintreeToken
18404
- }).then(clientInstance => {
18405
- const options = {
18406
- authorization: braintreeToken,
18669
+ console.log("Setting skeleton loader to true at start of Braintree initialization");
18670
+ dispatch({
18671
+ type: SKELETON_LOADER,
18672
+ payload: true
18673
+ });
18674
+ try {
18675
+ var _window$Pelcro$site$r7, _window$Pelcro$site$r8;
18676
+ // Ensure the DOM element exists before creating Drop-in UI
18677
+ const dropinContainer = document.querySelector("#dropin-container");
18678
+ if (!dropinContainer) {
18679
+ console.error("Drop-in container not found. Waiting for DOM to be ready...");
18680
+ dispatch({
18681
+ type: SKELETON_LOADER,
18682
+ payload: false
18683
+ });
18684
+ return;
18685
+ }
18686
+
18687
+ // Small delay to ensure DOM is fully rendered
18688
+ await new Promise(resolve => setTimeout(resolve, 100));
18689
+
18690
+ // Calculate Google Pay amount using the same logic as Apple Pay
18691
+ const totalAmount = calculateTotalAmount(state, plan, invoice, order);
18692
+ const currency = getCurrencyFromPaymentType(plan, order, invoice);
18693
+ const googlePayAmount = formatPaymentAmount(totalAmount, currency, "Google Pay");
18694
+
18695
+ // Create Braintree Drop-in UI instance
18696
+ braintreeDropinRef.current = await createBraintreeDropin(braintreeToken, "#dropin-container", {
18697
+ // Customize the Drop-in UI appearance
18407
18698
  styles: {
18408
18699
  input: {
18409
18700
  "font-size": "14px"
@@ -18415,48 +18706,85 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18415
18706
  color: "green"
18416
18707
  }
18417
18708
  },
18418
- fields: {
18419
- number: {
18420
- container: "#card-number",
18421
- placeholder: "4111 1111 1111 1111"
18422
- },
18423
- cvv: {
18424
- container: "#cvv",
18425
- placeholder: "123"
18709
+ // Disable PayPal to avoid conflicts with existing PayPal SDK
18710
+ // paypal: {
18711
+ // flow: "vault"
18712
+ // },
18713
+ // Enable Apple Pay if available
18714
+ applePay: {
18715
+ displayName: ((_window$Pelcro$site$r7 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r7 === void 0 ? void 0 : _window$Pelcro$site$r7.name) || "Pelcro",
18716
+ paymentRequest: {
18717
+ total: {
18718
+ label: getPaymentLabel(plan, order, invoice),
18719
+ amount: (() => {
18720
+ const totalAmount = calculateTotalAmount(state, plan, invoice, order);
18721
+ const currency = getCurrencyFromPaymentType(plan, order, invoice);
18722
+ return formatPaymentAmount(totalAmount, currency, "Apple Pay");
18723
+ })()
18724
+ }
18725
+ }
18726
+ },
18727
+ // Enable Google Pay for both orders and subscriptions
18728
+ googlePay: {
18729
+ googlePayVersion: 2,
18730
+ merchantId: (_window$Pelcro$site$r8 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r8 === void 0 ? void 0 : _window$Pelcro$site$r8.google_merchant_id,
18731
+ transactionInfo: {
18732
+ totalPriceStatus: "FINAL",
18733
+ totalPrice: googlePayAmount,
18734
+ currencyCode: (() => {
18735
+ const currency = getCurrencyFromPaymentType(plan, order, invoice);
18736
+ return (currency === null || currency === void 0 ? void 0 : currency.toUpperCase()) || "USD";
18737
+ })()
18426
18738
  },
18427
- expirationDate: {
18428
- container: "#expiration-date",
18429
- placeholder: "10/2022"
18739
+ // Add button configuration
18740
+ button: {
18741
+ color: "black",
18742
+ type: type === "createPayment" ? "subscribe" : "buy"
18430
18743
  }
18431
18744
  }
18432
- };
18745
+ });
18746
+ console.log("Setting skeleton loader to false after successful Braintree initialization");
18433
18747
  dispatch({
18434
18748
  type: SKELETON_LOADER,
18435
- payload: true
18749
+ payload: false
18436
18750
  });
18437
- return window.braintree.hostedFields.create(options);
18438
- });
18439
- braintreeInstanceRef.current.then(hostedFieldInstance => {
18440
- hostedFieldInstance.on("notEmpty", function (event) {
18441
- const field = event.fields[event.emittedBy];
18442
- if (field.isPotentiallyValid) {
18443
- field.container.classList.remove("pelcro-input-invalid");
18751
+
18752
+ // Clear any error alerts that were shown during initialization
18753
+ dispatch({
18754
+ type: SHOW_ALERT,
18755
+ payload: {
18756
+ type: "error",
18757
+ content: ""
18444
18758
  }
18445
18759
  });
18446
- hostedFieldInstance.on("validityChange", function (event) {
18447
- const field = event.fields[event.emittedBy];
18448
-
18449
- // Remove any previously applied error or warning classes
18450
- field.container.classList.remove("is-valid");
18451
- field.container.classList.remove("pelcro-input-invalid");
18452
- if (field.isValid) {
18453
- field.container.classList.add("is-valid");
18454
- } else if (field.isPotentiallyValid) ; else {
18455
- field.container.classList.add("pelcro-input-invalid");
18456
- }
18760
+ } catch (error) {
18761
+ var _error$message, _error$message2, _error$message3, _error$message4;
18762
+ console.error("Failed to initialize Braintree Drop-in UI:", error);
18763
+
18764
+ // Check if it's a Google Pay specific error
18765
+ if (error !== null && error !== void 0 && (_error$message = error.message) !== null && _error$message !== void 0 && _error$message.includes("OR_BIBED_06") || error !== null && error !== void 0 && (_error$message2 = error.message) !== null && _error$message2 !== void 0 && _error$message2.includes("Google Pay")) {
18766
+ console.warn("Google Pay configuration issue detected. " + `Transaction type: ${type}. ` + "This might be due to merchant settings or unsupported payment flow.");
18767
+ }
18768
+ dispatch({
18769
+ type: SKELETON_LOADER,
18770
+ payload: false
18457
18771
  });
18458
- });
18772
+
18773
+ // Don't show error to user for Google Pay configuration issues
18774
+ // as it's expected for subscriptions
18775
+ if (!(error !== null && error !== void 0 && (_error$message3 = error.message) !== null && _error$message3 !== void 0 && _error$message3.includes("OR_BIBED_06")) && !(error !== null && error !== void 0 && (_error$message4 = error.message) !== null && _error$message4 !== void 0 && _error$message4.includes("Google Pay"))) {
18776
+ dispatch({
18777
+ type: SHOW_ALERT,
18778
+ payload: {
18779
+ type: "error",
18780
+ content: "Failed to initialize payment form. Please refresh and try again."
18781
+ }
18782
+ });
18783
+ }
18784
+ }
18459
18785
  } else if (type == "updatePaymentSource" && paymentMethodToEdit) {
18786
+ // For updating payment methods, we still use hosted fields
18787
+ // as Drop-in UI doesn't support partial updates
18460
18788
  const {
18461
18789
  properties
18462
18790
  } = paymentMethodToEdit !== null && paymentMethodToEdit !== void 0 ? paymentMethodToEdit : {};
@@ -18464,9 +18792,14 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18464
18792
  exp_month: expMonth,
18465
18793
  exp_year: expYear
18466
18794
  } = properties !== null && properties !== void 0 ? properties : {};
18467
- braintreeInstanceRef.current = new window.braintree.client.create({
18468
- authorization: braintreeToken
18469
- }).then(clientInstance => {
18795
+ dispatch({
18796
+ type: SKELETON_LOADER,
18797
+ payload: true
18798
+ });
18799
+ try {
18800
+ const clientInstance = await new window.braintree.client.create({
18801
+ authorization: braintreeToken
18802
+ });
18470
18803
  const options = {
18471
18804
  client: clientInstance,
18472
18805
  styles: {
@@ -18488,41 +18821,28 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18488
18821
  expirationYear: {
18489
18822
  container: "#expiration-year",
18490
18823
  prefill: expYear
18824
+ },
18825
+ cvv: {
18826
+ container: "#cvv"
18491
18827
  }
18492
18828
  }
18493
18829
  };
18830
+ braintreeDropinRef.current = await window.braintree.hostedFields.create(options);
18831
+
18832
+ // dispatch({
18833
+ // type: SKELETON_LOADER,
18834
+ // payload: false
18835
+ // });
18836
+ } catch (error) {
18837
+ console.error("Failed to initialize Braintree hosted fields:", error);
18494
18838
  dispatch({
18495
18839
  type: SKELETON_LOADER,
18496
- payload: true
18497
- });
18498
- return window.braintree.hostedFields.create(options);
18499
- });
18500
- braintreeInstanceRef.current.then(hostedFieldInstance => {
18501
- hostedFieldInstance.on("notEmpty", function (event) {
18502
- const field = event.fields[event.emittedBy];
18503
- if (field.isPotentiallyValid) {
18504
- field.container.classList.remove("pelcro-input-invalid");
18505
- }
18506
- });
18507
- hostedFieldInstance.on("validityChange", function (event) {
18508
- const field = event.fields[event.emittedBy];
18509
-
18510
- // Remove any previously applied error or warning classes
18511
- field.container.classList.remove("is-valid");
18512
- field.container.classList.remove("pelcro-input-invalid");
18513
- if (field.isValid) {
18514
- field.container.classList.add("is-valid");
18515
- } else if (field.isPotentiallyValid) ; else {
18516
- field.container.classList.add("pelcro-input-invalid");
18517
- }
18840
+ payload: false
18518
18841
  });
18519
- });
18842
+ }
18520
18843
  }
18521
18844
  }
18522
18845
  }
18523
- React.useEffect(() => {
18524
- initializeBraintree();
18525
- }, [selectedPaymentMethodId, paymentMethodToEdit]);
18526
18846
  const braintreeErrorHandler = tokenizeErr => {
18527
18847
  var _tokenizeErr$details, _tokenizeErr$details2;
18528
18848
  const cardNumber = document.querySelector("#card-number");
@@ -18585,51 +18905,55 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18585
18905
  // no need to create a new source using braintree
18586
18906
  return handleBraintreePayment(null, state.couponCode);
18587
18907
  }
18588
- if (!braintreeInstanceRef.current) {
18589
- return console.error("Braintree sdk script wasn't loaded, you need to load braintree sdk before rendering the braintree payment flow");
18590
- }
18591
- braintreeInstanceRef.current.then(hostedFieldInstance => {
18592
- hostedFieldInstance.tokenize((tokenizeErr, payload) => {
18593
- if (tokenizeErr) {
18594
- dispatch({
18595
- type: DISABLE_SUBMIT,
18596
- payload: false
18597
- });
18598
- dispatch({
18599
- type: LOADING,
18600
- payload: false
18601
- });
18602
- return dispatch({
18603
- type: SHOW_ALERT,
18604
- payload: {
18605
- type: "error",
18606
- content: braintreeErrorHandler(tokenizeErr)
18607
- }
18608
- });
18908
+ if (!braintreeDropinRef.current) {
18909
+ console.error("Braintree Drop-in UI wasn't initialized, please try again");
18910
+ dispatch({
18911
+ type: DISABLE_SUBMIT,
18912
+ payload: false
18913
+ });
18914
+ dispatch({
18915
+ type: LOADING,
18916
+ payload: false
18917
+ });
18918
+ return dispatch({
18919
+ type: SHOW_ALERT,
18920
+ payload: {
18921
+ type: "error",
18922
+ content: "Braintree Drop-in UI wasn't initialized, please try again"
18609
18923
  }
18610
-
18611
- // Directly handle the payment with the tokenized payload
18612
- handleBraintreePayment(payload, state.couponCode);
18613
18924
  });
18925
+ }
18926
+ dispatch({
18927
+ type: LOADING,
18928
+ payload: true
18929
+ });
18930
+ dispatch({
18931
+ type: DISABLE_SUBMIT,
18932
+ payload: true
18933
+ });
18934
+
18935
+ // Use appropriate method based on payment type
18936
+ const paymentMethodPromise = type === "updatePaymentSource" ? requestBraintreeHostedFieldsPaymentMethod(braintreeDropinRef.current) : requestBraintreePaymentMethod(braintreeDropinRef.current);
18937
+ paymentMethodPromise.then(payload => {
18938
+ // Drop-in UI handles 3D Secure automatically, just proceed with payment
18939
+ handleBraintreePayment(payload, state.couponCode);
18614
18940
  }).catch(error => {
18615
- if (error) {
18616
- console.error(error);
18617
- dispatch({
18618
- type: DISABLE_SUBMIT,
18619
- payload: false
18620
- });
18621
- dispatch({
18622
- type: LOADING,
18623
- payload: false
18624
- });
18625
- return dispatch({
18626
- type: SHOW_ALERT,
18627
- payload: {
18628
- type: "error",
18629
- content: "There was a problem with your request."
18630
- }
18631
- });
18632
- }
18941
+ console.error("Braintree payment error:", error);
18942
+ dispatch({
18943
+ type: DISABLE_SUBMIT,
18944
+ payload: false
18945
+ });
18946
+ dispatch({
18947
+ type: LOADING,
18948
+ payload: false
18949
+ });
18950
+ return dispatch({
18951
+ type: SHOW_ALERT,
18952
+ payload: {
18953
+ type: "error",
18954
+ content: braintreeErrorHandler(error)
18955
+ }
18956
+ });
18633
18957
  });
18634
18958
  };
18635
18959
  const handleBraintreePayment = (braintreePaymentRequest, couponCode) => {
@@ -18679,7 +19003,6 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18679
19003
  content: t("messages.sourceCreated")
18680
19004
  }
18681
19005
  });
18682
- refreshUser();
18683
19006
  onSuccess(res);
18684
19007
  });
18685
19008
  }
@@ -19148,9 +19471,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19148
19471
  React.useEffect(() => {
19149
19472
  if (skipPayment && ((plan === null || plan === void 0 ? void 0 : plan.amount) === 0 || props !== null && props !== void 0 && props.freeOrders)) return;
19150
19473
  if (cardProcessor === "vantiv" && !selectedPaymentMethodId) {
19151
- var _window$Pelcro$site$r6, _window$Pelcro$site$r7;
19152
- const payPageId = (_window$Pelcro$site$r6 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r6 === void 0 ? void 0 : _window$Pelcro$site$r6.vantiv_gateway_settings.pay_page_id;
19153
- const reportGroup = (_window$Pelcro$site$r7 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r7 === void 0 ? void 0 : _window$Pelcro$site$r7.vantiv_gateway_settings.report_group;
19474
+ var _window$Pelcro$site$r9, _window$Pelcro$site$r10;
19475
+ const payPageId = (_window$Pelcro$site$r9 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r9 === void 0 ? void 0 : _window$Pelcro$site$r9.vantiv_gateway_settings.pay_page_id;
19476
+ const reportGroup = (_window$Pelcro$site$r10 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r10 === void 0 ? void 0 : _window$Pelcro$site$r10.vantiv_gateway_settings.report_group;
19154
19477
  vantivInstanceRef.current = new window.EprotectIframeClient({
19155
19478
  paypageId: payPageId,
19156
19479
  reportGroup: reportGroup,
@@ -19193,13 +19516,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19193
19516
  if (cardProcessor === "tap" && !selectedPaymentMethodId && window.Tapjsli) {
19194
19517
  initTapScript();
19195
19518
  }
19196
- if (cardProcessor === "cybersource" && !selectedPaymentMethodId && !window.FLEX) {
19197
- window.Pelcro.helpers.loadSDK("https://flex.cybersource.com/cybersource/assets/microform/0.4/flex-microform.min.js", "cybersource-cdn");
19198
- document.querySelector('script[src="https://flex.cybersource.com/cybersource/assets/microform/0.4/flex-microform.min.js"]').addEventListener("load", () => {
19199
- initCybersourceScript();
19200
- });
19201
- }
19202
- if (cardProcessor === "cybersource" && !selectedPaymentMethodId && window.FLEX) {
19519
+ if (cardProcessor === "cybersource" && !selectedPaymentMethodId) {
19203
19520
  initCybersourceScript();
19204
19521
  }
19205
19522
  if (cardProcessor === "cybersource") {
@@ -19220,13 +19537,13 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19220
19537
  });
19221
19538
 
19222
19539
  // When Google pay / Apple pay source created
19223
- paymentRequest.on("source", _ref6 => {
19540
+ paymentRequest.on("source", _ref8 => {
19224
19541
  var _source$card;
19225
19542
  let {
19226
19543
  complete,
19227
19544
  source,
19228
19545
  ...data
19229
- } = _ref6;
19546
+ } = _ref8;
19230
19547
  dispatch({
19231
19548
  type: DISABLE_COUPON_BUTTON,
19232
19549
  payload: true
@@ -19241,11 +19558,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19241
19558
  });
19242
19559
  complete("success");
19243
19560
  if ((source === null || source === void 0 ? void 0 : (_source$card = source.card) === null || _source$card === void 0 ? void 0 : _source$card.three_d_secure) === "required") {
19244
- return generate3DSecureSource(source).then(_ref7 => {
19561
+ return generate3DSecureSource(source).then(_ref9 => {
19245
19562
  let {
19246
19563
  source,
19247
19564
  error
19248
- } = _ref7;
19565
+ } = _ref9;
19249
19566
  if (error) {
19250
19567
  return handlePaymentError(error);
19251
19568
  }
@@ -19276,9 +19593,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19276
19593
  * Updates the total amount after adding taxes only if site taxes are enabled
19277
19594
  */
19278
19595
  const updateTotalAmountWithTax = () => {
19279
- var _window$Pelcro$site$r8;
19596
+ var _window$Pelcro$site$r11;
19280
19597
  if (skipPayment && ((plan === null || plan === void 0 ? void 0 : plan.amount) === 0 || props !== null && props !== void 0 && props.freeOrders)) return;
19281
- const taxesEnabled = (_window$Pelcro$site$r8 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r8 === void 0 ? void 0 : _window$Pelcro$site$r8.taxes_enabled;
19598
+ const taxesEnabled = (_window$Pelcro$site$r11 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r11 === void 0 ? void 0 : _window$Pelcro$site$r11.taxes_enabled;
19282
19599
  if (taxesEnabled && type === "createPayment") {
19283
19600
  dispatch({
19284
19601
  type: DISABLE_SUBMIT,
@@ -19715,7 +20032,10 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19715
20032
  gift_recipient_last_name: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.lastName,
19716
20033
  gift_start_date: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.startDate,
19717
20034
  gift_message: giftRecipient === null || giftRecipient === void 0 ? void 0 : giftRecipient.giftMessage,
19718
- address_id: product.address_required ? selectedAddressId : null
20035
+ address_id: product.address_required ? selectedAddressId : null,
20036
+ metadata: props === null || props === void 0 ? void 0 : props.subCreateMetadata,
20037
+ cardExpirationMonth: state === null || state === void 0 ? void 0 : state.month,
20038
+ cardExpirationYear: state === null || state === void 0 ? void 0 : state.year
19719
20039
  }, (err, res) => {
19720
20040
  var _res$data;
19721
20041
  if (res !== null && res !== void 0 && (_res$data = res.data) !== null && _res$data !== void 0 && _res$data.setup_intent) {
@@ -19890,9 +20210,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19890
20210
  isExistingSource: Boolean(selectedPaymentMethodId),
19891
20211
  items: mappedOrderItems,
19892
20212
  addressId: selectedAddressId,
19893
- couponCode
20213
+ couponCode,
20214
+ cardExpirationMonth: state === null || state === void 0 ? void 0 : state.month,
20215
+ cardExpirationYear: state === null || state === void 0 ? void 0 : state.year
19894
20216
  }, (err, orderResponse) => {
19895
- var _window$Pelcro2, _window$Pelcro2$user, _window$Pelcro2$user$;
20217
+ var _window$Pelcro3, _window$Pelcro3$user, _window$Pelcro3$user$;
19896
20218
  if (err) {
19897
20219
  toggleAuthenticationSuccessPendingView(false);
19898
20220
  dispatch({
@@ -19923,7 +20245,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19923
20245
  });
19924
20246
  }
19925
20247
  window.Pelcro.user.refresh({
19926
- auth_token: (_window$Pelcro2 = window.Pelcro) === null || _window$Pelcro2 === void 0 ? void 0 : (_window$Pelcro2$user = _window$Pelcro2.user) === null || _window$Pelcro2$user === void 0 ? void 0 : (_window$Pelcro2$user$ = _window$Pelcro2$user.read()) === null || _window$Pelcro2$user$ === void 0 ? void 0 : _window$Pelcro2$user$.auth_token
20248
+ auth_token: (_window$Pelcro3 = window.Pelcro) === null || _window$Pelcro3 === void 0 ? void 0 : (_window$Pelcro3$user = _window$Pelcro3.user) === null || _window$Pelcro3$user === void 0 ? void 0 : (_window$Pelcro3$user$ = _window$Pelcro3$user.read()) === null || _window$Pelcro3$user$ === void 0 ? void 0 : _window$Pelcro3$user$.auth_token
19927
20249
  }, (err, res) => {
19928
20250
  dispatch({
19929
20251
  type: DISABLE_SUBMIT,
@@ -19962,11 +20284,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19962
20284
  const createPaymentSource = (state, dispatch) => {
19963
20285
  return stripe.createSource({
19964
20286
  type: "card"
19965
- }).then(_ref8 => {
20287
+ }).then(_ref10 => {
19966
20288
  let {
19967
20289
  source,
19968
20290
  error
19969
- } = _ref8;
20291
+ } = _ref10;
19970
20292
  if (error) {
19971
20293
  return handlePaymentError(error);
19972
20294
  }
@@ -20080,11 +20402,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20080
20402
  } = paymentMethodToDelete;
20081
20403
  return stripe.createSource({
20082
20404
  type: "card"
20083
- }).then(_ref9 => {
20405
+ }).then(_ref11 => {
20084
20406
  let {
20085
20407
  source,
20086
20408
  error
20087
- } = _ref9;
20409
+ } = _ref11;
20088
20410
  if (error) {
20089
20411
  return handlePaymentError(error);
20090
20412
  }
@@ -20171,7 +20493,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20171
20493
  campaign_key: window.Pelcro.helpers.getURLParameter("campaign_key"),
20172
20494
  ...(selectedAddressId && {
20173
20495
  address_id: selectedAddressId
20174
- })
20496
+ }),
20497
+ cardExpirationMonth: state === null || state === void 0 ? void 0 : state.month,
20498
+ cardExpirationYear: state === null || state === void 0 ? void 0 : state.year
20175
20499
  }, (err, res) => {
20176
20500
  if (err) {
20177
20501
  return handlePaymentError(err);
@@ -20182,12 +20506,12 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20182
20506
  }
20183
20507
  stripe.createSource({
20184
20508
  type: "card"
20185
- }).then(_ref10 => {
20186
- var _ref11, _ref12, _state$updatedPrice2;
20509
+ }).then(_ref12 => {
20510
+ var _ref13, _ref14, _state$updatedPrice3;
20187
20511
  let {
20188
20512
  source,
20189
20513
  error
20190
- } = _ref10;
20514
+ } = _ref12;
20191
20515
  if (error) {
20192
20516
  return handlePaymentError(error);
20193
20517
  }
@@ -20206,7 +20530,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20206
20530
  return total + item.price * item.quantity;
20207
20531
  }, 0);
20208
20532
  };
20209
- (_ref11 = (_ref12 = (_state$updatedPrice2 = state === null || state === void 0 ? void 0 : state.updatedPrice) !== null && _state$updatedPrice2 !== void 0 ? _state$updatedPrice2 : plan === null || plan === void 0 ? void 0 : plan.amount) !== null && _ref12 !== void 0 ? _ref12 : invoice === null || invoice === void 0 ? void 0 : invoice.amount_remaining) !== null && _ref11 !== void 0 ? _ref11 : getOrderItemsTotal();
20533
+ (_ref13 = (_ref14 = (_state$updatedPrice3 = state === null || state === void 0 ? void 0 : state.updatedPrice) !== null && _state$updatedPrice3 !== void 0 ? _state$updatedPrice3 : plan === null || plan === void 0 ? void 0 : plan.amount) !== null && _ref14 !== void 0 ? _ref14 : invoice === null || invoice === void 0 ? void 0 : invoice.amount_remaining) !== null && _ref13 !== void 0 ? _ref13 : getOrderItemsTotal();
20210
20534
  return handlePayment(source);
20211
20535
  }).catch(error => {
20212
20536
  return handlePaymentError(error);
@@ -20218,11 +20542,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20218
20542
  * @return {Promise}
20219
20543
  */
20220
20544
  const resolveTaxCalculation = () => {
20221
- var _window$Pelcro$site$r9;
20545
+ var _window$Pelcro$site$r12;
20222
20546
  if (type === "invoicePayment") {
20223
20547
  return new Promise(resolve => resolve());
20224
20548
  }
20225
- const taxesEnabled = (_window$Pelcro$site$r9 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r9 === void 0 ? void 0 : _window$Pelcro$site$r9.taxes_enabled;
20549
+ const taxesEnabled = (_window$Pelcro$site$r12 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r12 === void 0 ? void 0 : _window$Pelcro$site$r12.taxes_enabled;
20226
20550
  return new Promise((resolve, reject) => {
20227
20551
  // resolve early if taxes isn't enabled
20228
20552
  if (!taxesEnabled) {
@@ -20580,6 +20904,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20580
20904
  return state;
20581
20905
  }
20582
20906
  }, initialState$l);
20907
+ React.useEffect(() => {
20908
+ initializeBraintree();
20909
+ }, [selectedPaymentMethodId, paymentMethodToEdit, state.updatedPrice]);
20583
20910
  return /*#__PURE__*/React__default['default'].createElement("div", {
20584
20911
  style: {
20585
20912
  ...style
@@ -20882,32 +21209,21 @@ const CheckoutForm = _ref => {
20882
21209
  }, "Expiration Year *"), /*#__PURE__*/React__default['default'].createElement("div", {
20883
21210
  id: "expiration-year",
20884
21211
  className: "pelcro-input-field plc-h-12 plc-bg-white"
21212
+ })), /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement("label", {
21213
+ htmlFor: "cvv"
21214
+ }, "CVV *"), /*#__PURE__*/React__default['default'].createElement("div", {
21215
+ id: "cvv",
21216
+ className: "pelcro-input-field plc-h-12 plc-bg-white"
20885
21217
  })))) : /*#__PURE__*/React__default['default'].createElement("div", {
20886
21218
  className: "plc-w-full plc-h-40 plc-bg-gray-300 plc-rounded plc-animate-pulse"
20887
21219
  }));
20888
21220
  }
20889
- return /*#__PURE__*/React__default['default'].createElement("div", null, isSkeletonLoaded ? /*#__PURE__*/React__default['default'].createElement("div", {
21221
+ return /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement("div", {
20890
21222
  className: "plc-max-w-[50em]"
20891
- }, /*#__PURE__*/React__default['default'].createElement("label", {
20892
- htmlFor: "card-number"
20893
- }, "Card Number *"), /*#__PURE__*/React__default['default'].createElement("div", {
20894
- id: "card-number",
20895
- className: "pelcro-input-field plc-h-12 plc-bg-white"
20896
- }), /*#__PURE__*/React__default['default'].createElement("div", {
20897
- className: "plc-flex plc-items-start plc-space-x-8 plc-my-6"
20898
- }, /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement("label", {
20899
- htmlFor: "expiration-date"
20900
- }, "Expiration Date *"), /*#__PURE__*/React__default['default'].createElement("div", {
20901
- id: "expiration-date",
20902
- className: "pelcro-input-field plc-h-12 plc-bg-white"
20903
- })), /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement("label", {
20904
- htmlFor: "cvv"
20905
- }, "CVC *"), /*#__PURE__*/React__default['default'].createElement("div", {
20906
- id: "cvv",
20907
- className: "pelcro-input-field plc-h-12 plc-bg-white"
20908
- })))) : /*#__PURE__*/React__default['default'].createElement("div", {
20909
- className: "plc-w-full plc-h-40 plc-bg-gray-300 plc-rounded plc-animate-pulse"
20910
- }));
21223
+ }, /*#__PURE__*/React__default['default'].createElement("div", {
21224
+ id: "dropin-container",
21225
+ className: "plc-w-full plc-min-h-[300px]"
21226
+ })));
20911
21227
  }
20912
21228
  if (cardProcessor === "stripe") {
20913
21229
  if (type === "updatePaymentSource") {
@@ -22125,7 +22441,7 @@ function PaymentMethodView(_ref) {
22125
22441
  label: t("labels.isDefault")
22126
22442
  }), /*#__PURE__*/React__default['default'].createElement("div", {
22127
22443
  className: "plc-grid plc-mt-4 plc-gap-y-2"
22128
- }, /*#__PURE__*/React__default['default'].createElement(SubmitPaymentMethod, null), showExternalPaymentMethods && !supportsVantiv && !supportsCybersource && !supportsTap ? /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, null, /*#__PURE__*/React__default['default'].createElement(PelcroPaymentRequestButton, null), /*#__PURE__*/React__default['default'].createElement(PaypalSubscribeButton, null)) : showExternalPaymentMethods && supportsVantiv ? /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, null, /*#__PURE__*/React__default['default'].createElement(PaypalSubscribeButton, null)) : null, showApplePayButton && supportsVantiv ? /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, null, /*#__PURE__*/React__default['default'].createElement(ApplePayButton, null)) : null)))));
22444
+ }, /*#__PURE__*/React__default['default'].createElement(SubmitPaymentMethod, null), showExternalPaymentMethods && cardProcessor === "braintree" && /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, null, !supportsVantiv && !supportsCybersource && !supportsTap && /*#__PURE__*/React__default['default'].createElement(PelcroPaymentRequestButton, null), /*#__PURE__*/React__default['default'].createElement(PaypalSubscribeButton, null)), showApplePayButton && supportsVantiv && /*#__PURE__*/React__default['default'].createElement(ApplePayButton, null))))));
22129
22445
  }
22130
22446
 
22131
22447
  const SubscriptionRenewView = _ref => {