@pelcro/react-pelcro-js 3.50.0 → 3.52.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
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var React = require('react');
6
- var ReactDOM = require('react-dom');
7
6
  var PropTypes = require('prop-types');
7
+ var ReactDOM = require('react-dom');
8
8
 
9
9
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
10
 
@@ -30,8 +30,8 @@ function _interopNamespace(e) {
30
30
 
31
31
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
32
32
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
33
- var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM);
34
33
  var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
34
+ var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM);
35
35
 
36
36
  function _typeof$3(obj) {
37
37
  "@babel/helpers - typeof";
@@ -2574,7 +2574,7 @@ var voidElements = {
2574
2574
  "wbr": true
2575
2575
  };
2576
2576
 
2577
- var t$1=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function n$1(n){var r={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},i=n.match(/<\/?([^\s]+?)[/\s>]/);if(i&&(r.name=i[1],(voidElements[i[1]]||"/"===n.charAt(n.length-2))&&(r.voidElement=!0),r.name.startsWith("!--"))){var s=n.indexOf("--\x3e");return {type:"comment",comment:-1!==s?n.slice(4,s):""}}for(var a=new RegExp(t$1),c=null;null!==(c=a.exec(n));)if(c[0].trim())if(c[1]){var o=c[1].trim(),l=[o,""];o.indexOf("=")>-1&&(l=o.split("=")),r.attrs[l[0]]=l[1],a.lastIndex--;}else c[2]&&(r.attrs[c[2]]=c[3].trim().substring(1,c[3].length-1));return r}var r=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,i$2=/^\s*$/,s$1=Object.create(null);function a$1(e,t){switch(t.type){case"text":return e+t.content;case"tag":return e+="<"+t.name+(t.attrs?function(e){var t=[];for(var n in e)t.push(n+'="'+e[n]+'"');return t.length?" "+t.join(" "):""}(t.attrs):"")+(t.voidElement?"/>":">"),t.voidElement?e:e+t.children.reduce(a$1,"")+"</"+t.name+">";case"comment":return e+"\x3c!--"+t.comment+"--\x3e"}}var c$2={parse:function(e,t){t||(t={}),t.components||(t.components=s$1);var a,c=[],o=[],l=-1,m=!1;if(0!==e.indexOf("<")){var u=e.indexOf("<");c.push({type:"text",content:-1===u?e:e.substring(0,u)});}return e.replace(r,function(r,s){if(m){if(r!=="</"+a.name+">")return;m=!1;}var u,f="/"!==r.charAt(1),h=r.startsWith("\x3c!--"),p=s+r.length,d=e.charAt(p);if(h){var v=n$1(r);return l<0?(c.push(v),c):((u=o[l]).children.push(v),c)}if(f&&(l++,"tag"===(a=n$1(r)).type&&t.components[a.name]&&(a.type="component",m=!0),a.voidElement||m||!d||"<"===d||a.children.push({type:"text",content:e.slice(p,e.indexOf("<",p))}),0===l&&c.push(a),(u=o[l-1])&&u.children.push(a),o[l]=a),(!f||a.voidElement)&&(l>-1&&(a.voidElement||a.name===r.slice(2,-1))&&(l--,a=-1===l?c:o[l]),!m&&"<"!==d&&d)){u=-1===l?c:o[l].children;var x=e.indexOf("<",p),g=e.slice(p,-1===x?void 0:x);i$2.test(g)&&(g=" "),(x>-1&&l+u.length>=0||" "!==g)&&u.push({type:"text",content:g});}}),c},stringify:function(e){return e.reduce(function(e,t){return e+a$1("",t)},"")}};
2577
+ var t$1=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function n$1(n){var r={type:"tag",name:"",voidElement:!1,attrs:{},children:[]},i=n.match(/<\/?([^\s]+?)[/\s>]/);if(i&&(r.name=i[1],(voidElements[i[1]]||"/"===n.charAt(n.length-2))&&(r.voidElement=!0),r.name.startsWith("!--"))){var s=n.indexOf("--\x3e");return {type:"comment",comment:-1!==s?n.slice(4,s):""}}for(var a=new RegExp(t$1),c=null;null!==(c=a.exec(n));)if(c[0].trim())if(c[1]){var o=c[1].trim(),l=[o,""];o.indexOf("=")>-1&&(l=o.split("=")),r.attrs[l[0]]=l[1],a.lastIndex--;}else c[2]&&(r.attrs[c[2]]=c[3].trim().substring(1,c[3].length-1));return r}var r=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,i$2=/^\s*$/,s$1=Object.create(null);function a$1(e,t){switch(t.type){case"text":return e+t.content;case"tag":return e+="<"+t.name+(t.attrs?function(e){var t=[];for(var n in e)t.push(n+'="'+e[n]+'"');return t.length?" "+t.join(" "):""}(t.attrs):"")+(t.voidElement?"/>":">"),t.voidElement?e:e+t.children.reduce(a$1,"")+"</"+t.name+">";case"comment":return e+"\x3c!--"+t.comment+"--\x3e"}}var c$1={parse:function(e,t){t||(t={}),t.components||(t.components=s$1);var a,c=[],o=[],l=-1,m=!1;if(0!==e.indexOf("<")){var u=e.indexOf("<");c.push({type:"text",content:-1===u?e:e.substring(0,u)});}return e.replace(r,function(r,s){if(m){if(r!=="</"+a.name+">")return;m=!1;}var u,f="/"!==r.charAt(1),h=r.startsWith("\x3c!--"),p=s+r.length,d=e.charAt(p);if(h){var v=n$1(r);return l<0?(c.push(v),c):((u=o[l]).children.push(v),c)}if(f&&(l++,"tag"===(a=n$1(r)).type&&t.components[a.name]&&(a.type="component",m=!0),a.voidElement||m||!d||"<"===d||a.children.push({type:"text",content:e.slice(p,e.indexOf("<",p))}),0===l&&c.push(a),(u=o[l-1])&&u.children.push(a),o[l]=a),(!f||a.voidElement)&&(l>-1&&(a.voidElement||a.name===r.slice(2,-1))&&(l--,a=-1===l?c:o[l]),!m&&"<"!==d&&d)){u=-1===l?c:o[l].children;var x=e.indexOf("<",p),g=e.slice(p,-1===x?void 0:x);i$2.test(g)&&(g=" "),(x>-1&&l+u.length>=0||" "!==g)&&u.push({type:"text",content:g});}}),c},stringify:function(e){return e.reduce(function(e,t){return e+a$1("",t)},"")}};
2578
2578
 
2579
2579
  var classCallCheck = createCommonjsModule(function (module) {
2580
2580
  function _classCallCheck(instance, Constructor) {
@@ -2836,7 +2836,7 @@ function renderNodes(children, targetString, i18n, i18nOptions, combinedTOpts) {
2836
2836
 
2837
2837
  getData(children);
2838
2838
  var interpolatedString = i18n.services.interpolator.interpolate(targetString, _objectSpread$5(_objectSpread$5({}, data), combinedTOpts), i18n.language);
2839
- var ast = c$2.parse("<0>".concat(interpolatedString, "</0>"));
2839
+ var ast = c$1.parse("<0>".concat(interpolatedString, "</0>"));
2840
2840
 
2841
2841
  function renderInner(child, node, rootReactNode) {
2842
2842
  var childs = getChildren(child);
@@ -7098,8 +7098,6 @@ exports.default = create;
7098
7098
 
7099
7099
  var createStore = unwrapExports(vanilla);
7100
7100
 
7101
- function c$1(c,r,d){const u={count:0},s=t=>{const o=React.useRef(u.count);return React.useEffect(()=>{o.current+=1,o.current===u.count+1&&(o.current-=1,r.setState(t));}),null};if(s.displayName=`((${c})) devtool`,!d){let t=document.getElementById("simple-zustand-devtools");t||(t=document.createElement("div"),t.id="simple-zustand-devtools"),document.body.appendChild(t),d=t;}const m=e=>{e&&(ReactDOM.render(React__default['default'].createElement(s,Object.assign({},e)),d),u.count+=1);};m(r.getState()),r.subscribe(m);}
7102
-
7103
7101
  var _extends_1 = createCommonjsModule(function (module) {
7104
7102
  function _extends() {
7105
7103
  module.exports = _extends = Object.assign || function (target) {
@@ -9301,7 +9299,8 @@ const usePelcro = createPelcroHook(pelcroStore);
9301
9299
 
9302
9300
  /* istanbul ignore next */
9303
9301
  if (process.env.NODE_ENV === "development") {
9304
- c$1("Pelcro Store", usePelcro);
9302
+ // mountStoreDevtool("Pelcro Store", usePelcro);
9303
+ console.log("Pelcro Store devtools disabled - simple-zustand-devtools incompatible with React 16");
9305
9304
  }
9306
9305
 
9307
9306
  /**
@@ -11682,6 +11681,101 @@ function getFourDigitYear(lastTwoDigits) {
11682
11681
  return fourDigitYear;
11683
11682
  }
11684
11683
 
11684
+ /**
11685
+ * Loads Braintree Drop-in UI script
11686
+ * @returns {Promise} Promise that resolves when script is loaded
11687
+ */
11688
+ function loadBraintreeScript() {
11689
+ return new Promise((resolve, reject) => {
11690
+ // Check if script is already loaded
11691
+ if (window.braintree) {
11692
+ console.log("Braintree script already loaded");
11693
+ resolve(window.braintree);
11694
+ return;
11695
+ }
11696
+ console.log("Loading Braintree script...");
11697
+ const script = document.createElement("script");
11698
+ script.src = "https://js.braintreegateway.com/web/dropin/1.45.1/js/dropin.js";
11699
+ script.onload = () => {
11700
+ console.log("Braintree script loaded successfully");
11701
+ resolve(window.braintree);
11702
+ };
11703
+ script.onerror = error => {
11704
+ console.error("Failed to load Braintree script:", error);
11705
+ reject(new Error("Failed to load Braintree script"));
11706
+ };
11707
+ document.head.appendChild(script);
11708
+ });
11709
+ }
11710
+
11711
+ /**
11712
+ * Creates Braintree Drop-in UI instance
11713
+ * @param {string} authorization - Braintree authorization token
11714
+ * @param {string} selector - CSS selector for the container
11715
+ * @param {Object} options - Additional options for dropin creation
11716
+ * @returns {Promise} Promise that resolves with the dropin instance
11717
+ */
11718
+ function createBraintreeDropin(authorization, selector) {
11719
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
11720
+ console.log("Creating Braintree Drop-in with:", {
11721
+ authorization: authorization ? "present" : "missing",
11722
+ selector,
11723
+ options
11724
+ });
11725
+ return loadBraintreeScript().then(() => {
11726
+ console.log("Braintree script loaded, creating dropin...");
11727
+ return new Promise((resolve, reject) => {
11728
+ window.braintree.dropin.create({
11729
+ authorization,
11730
+ selector,
11731
+ ...options
11732
+ }, (err, instance) => {
11733
+ if (err) {
11734
+ console.error("Braintree dropin creation failed:", err);
11735
+ reject(err);
11736
+ } else {
11737
+ console.log("Braintree dropin created successfully:", instance);
11738
+ resolve(instance);
11739
+ }
11740
+ });
11741
+ });
11742
+ });
11743
+ }
11744
+
11745
+ /**
11746
+ * Requests payment method from Braintree Drop-in UI
11747
+ * @param {Object} instance - Braintree dropin instance
11748
+ * @returns {Promise} Promise that resolves with payment method payload
11749
+ */
11750
+ function requestBraintreePaymentMethod(instance) {
11751
+ return new Promise((resolve, reject) => {
11752
+ instance.requestPaymentMethod((err, payload) => {
11753
+ if (err) {
11754
+ reject(err);
11755
+ } else {
11756
+ resolve(payload);
11757
+ }
11758
+ });
11759
+ });
11760
+ }
11761
+
11762
+ /**
11763
+ * Requests payment method from Braintree Hosted Fields
11764
+ * @param {Object} hostedFieldsInstance - Braintree hosted fields instance
11765
+ * @returns {Promise} Promise that resolves with payment method payload
11766
+ */
11767
+ function requestBraintreeHostedFieldsPaymentMethod(hostedFieldsInstance) {
11768
+ return new Promise((resolve, reject) => {
11769
+ hostedFieldsInstance.tokenize((err, payload) => {
11770
+ if (err) {
11771
+ reject(err);
11772
+ } else {
11773
+ resolve(payload);
11774
+ }
11775
+ });
11776
+ });
11777
+ }
11778
+
11685
11779
  /**
11686
11780
  * @typedef {Object} OptionsType
11687
11781
  * @property {boolean} loadPaymentSDKs
@@ -11792,6 +11886,7 @@ const loadPaymentSDKs = () => {
11792
11886
  // "braintree-3D-secure-sdk"
11793
11887
  // );
11794
11888
  window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.99.0/js/hosted-fields.min.js", "braintree-hosted-fields-sdk");
11889
+ window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/dropin/1.45.1/js/dropin.js", "braintree-dropin-sdk");
11795
11890
  }
11796
11891
 
11797
11892
  // Load Vantiv SDKs
@@ -11836,16 +11931,16 @@ const initSecuritySdk = () => {
11836
11931
  });
11837
11932
  };
11838
11933
  const initGATracking = () => {
11839
- var _window, _window$Pelcro, _window$Pelcro$uiSett;
11934
+ var _window, _window$Pelcro, _window$Pelcro$uiSett, _window2, _window2$Pelcro, _window2$Pelcro$uiSet;
11840
11935
  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;
11936
+ // Respect disablePageViewEvents flag from uiSettings
11937
+ 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
11938
  if (window.Pelcro.site.read().google_analytics_id) {
11842
11939
  if (enableReactGA4) {
11843
- // Initialize ReactGA4 with your tracking ID
11844
- ReactGA4.initialize(window.Pelcro.site.read().google_analytics_id);
11845
- // Enable e-commerce tracking
11940
+ // Initialize ReactGA4 with your tracking ID and options, only once
11846
11941
  ReactGA4.initialize(window.Pelcro.site.read().google_analytics_id, {
11847
11942
  gaOptions: {
11848
- send_page_view: true,
11943
+ send_page_view: disablePageViewEvents ? false : true,
11849
11944
  ecommerce: {
11850
11945
  enabled: true
11851
11946
  }
@@ -11859,8 +11954,8 @@ const initGATracking = () => {
11859
11954
  }
11860
11955
  };
11861
11956
  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;
11957
+ var _window3, _window3$Pelcro, _window3$Pelcro$uiSet, _modalName$replace, _modalName$replace2;
11958
+ 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
11959
  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
11960
  if (enableReactGA4) {
11866
11961
  ReactGA4.event(`${formattedAction} viewed`, {
@@ -16454,10 +16549,6 @@ var es_13 = es.StripeProvider;
16454
16549
 
16455
16550
  function _classPrivateFieldInitSpec$1(obj, privateMap, value) { _checkPrivateRedeclaration$1(obj, privateMap); privateMap.set(obj, value); }
16456
16551
  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
16552
 
16462
16553
  /**
16463
16554
  * Enum for payment types
@@ -16593,6 +16684,16 @@ class StripeGateway {
16593
16684
  console.error("Unsupported payment method: Stripe Gateway");
16594
16685
  }
16595
16686
  });
16687
+ _defineProperty$3(this, "createDropin", function (authorization, selector) {
16688
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
16689
+ return createBraintreeDropin(authorization, selector, options);
16690
+ });
16691
+ _defineProperty$3(this, "requestPaymentMethod", instance => {
16692
+ return requestBraintreePaymentMethod(instance);
16693
+ });
16694
+ _defineProperty$3(this, "loadScript", () => {
16695
+ return loadBraintreeScript();
16696
+ });
16596
16697
  _classPrivateFieldInitSpec$1(this, _createSubscription, {
16597
16698
  writable: true,
16598
16699
  value: (options, callback) => {
@@ -17790,6 +17891,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17790
17891
  onSuccess = () => {},
17791
17892
  onGiftRenewalSuccess = () => {},
17792
17893
  onFailure = () => {},
17894
+ onPriceUpdate = () => {},
17793
17895
  ...props
17794
17896
  } = _ref;
17795
17897
  const [vantivPaymentRequest, setVantivPaymentRequest] = React.useState(null);
@@ -17836,6 +17938,79 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17836
17938
  });
17837
17939
  updateTotalAmountWithTax();
17838
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
+ };
17839
18014
 
17840
18015
  /* ====== Start Cybersource integration ======== */
17841
18016
  const cybersourceErrorHandle = err => {
@@ -17845,10 +18020,10 @@ const PaymentMethodContainerWithoutStripe = _ref => {
17845
18020
  const errorMessages = [];
17846
18021
 
17847
18022
  // enumerable error (ex: validation errors)
17848
- 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 => {
17849
18024
  let {
17850
18025
  message
17851
- } = _ref2;
18026
+ } = _ref4;
17852
18027
  errorMessages.push(message);
17853
18028
  });
17854
18029
 
@@ -18066,10 +18241,10 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18066
18241
  // No longer needed - microform instance is stored directly in initCybersourceScript
18067
18242
 
18068
18243
  const appendCybersourceFingerprintScripts = () => {
18069
- 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;
18070
18245
  const uniqueId = crypto.randomUUID();
18071
- 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;
18072
- 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;
18073
18248
  const fingerPrintScript = document.querySelector(`script[src="https://h.online-metrix.net/fp/tags.js?org_id=${orgID}&session_id=${sessionID}"]`);
18074
18249
  const fingerPringIframe = document.querySelector(`iframe[src="https://h.online-metrix.net/fp/tags?org_id=${orgID}&session_id=${sessionID}"]`);
18075
18250
  if (!fingerPrintScript && !fingerPringIframe) {
@@ -18175,7 +18350,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18175
18350
 
18176
18351
  /* ====== Start Tap integration ======== */
18177
18352
  const submitUsingTap = state => {
18178
- var _ref3, _ref4, _ref5, _state$updatedPrice;
18353
+ var _ref5, _ref6, _ref7, _state$updatedPrice2;
18179
18354
  const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
18180
18355
  if (isUsingExistingPaymentMethod) {
18181
18356
  // no need to create a new source using tap
@@ -18199,7 +18374,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18199
18374
  return total + item.price * item.quantity;
18200
18375
  }, 0);
18201
18376
  };
18202
- 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;
18203
18378
  tapInstanceRef.current.createToken(tapInstanceCard.current).then(function (result) {
18204
18379
  if (result.error) {
18205
18380
  // Inform the user if there was an error
@@ -18409,8 +18584,8 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18409
18584
  }
18410
18585
  }
18411
18586
  const initTapScript = () => {
18412
- var _window$Pelcro$site$r5;
18413
- 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);
18414
18589
  let elements = tapKey.elements({});
18415
18590
  let style = {
18416
18591
  base: {
@@ -18460,8 +18635,8 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18460
18635
  };
18461
18636
  /* ====== End Tap integration ======== */
18462
18637
 
18463
- /* ====== Start Braintree integration ======== */
18464
- const braintreeInstanceRef = React__default['default'].useRef(null);
18638
+ /* ====== Start Braintree Drop-in UI integration ======== */
18639
+ const braintreeDropinRef = React__default['default'].useRef(null);
18465
18640
  function getClientToken() {
18466
18641
  return new Promise((resolve, reject) => {
18467
18642
  window.Pelcro.payment.generateClientToken({
@@ -18480,18 +18655,46 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18480
18655
  async function initializeBraintree() {
18481
18656
  if (skipPayment && ((plan === null || plan === void 0 ? void 0 : plan.amount) === 0 || props !== null && props !== void 0 && props.freeOrders)) return;
18482
18657
  if (cardProcessor === "braintree" && !selectedPaymentMethodId) {
18658
+ // Clear container before initializing
18659
+ const dropinContainer = document.getElementById("dropin-container");
18660
+ if (dropinContainer) dropinContainer.innerHTML = "";
18483
18661
  const braintreeToken = await getClientToken();
18484
18662
  const isBraintreeEnabled = Boolean(braintreeToken);
18485
18663
  if (!isBraintreeEnabled) {
18486
18664
  console.error("Braintree integration is currently not enabled on this site's config");
18487
18665
  return;
18488
18666
  }
18667
+ console.log("braintreeToken", plan);
18489
18668
  if (type !== "updatePaymentSource") {
18490
- braintreeInstanceRef.current = new window.braintree.client.create({
18491
- authorization: braintreeToken
18492
- }).then(clientInstance => {
18493
- const options = {
18494
- 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
18495
18698
  styles: {
18496
18699
  input: {
18497
18700
  "font-size": "14px"
@@ -18503,48 +18706,85 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18503
18706
  color: "green"
18504
18707
  }
18505
18708
  },
18506
- fields: {
18507
- number: {
18508
- container: "#card-number",
18509
- placeholder: "4111 1111 1111 1111"
18510
- },
18511
- cvv: {
18512
- container: "#cvv",
18513
- 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
+ })()
18514
18738
  },
18515
- expirationDate: {
18516
- container: "#expiration-date",
18517
- placeholder: "10/2022"
18739
+ // Add button configuration
18740
+ button: {
18741
+ color: "black",
18742
+ type: type === "createPayment" ? "subscribe" : "buy"
18518
18743
  }
18519
18744
  }
18520
- };
18745
+ });
18746
+ console.log("Setting skeleton loader to false after successful Braintree initialization");
18521
18747
  dispatch({
18522
18748
  type: SKELETON_LOADER,
18523
- payload: true
18749
+ payload: false
18524
18750
  });
18525
- return window.braintree.hostedFields.create(options);
18526
- });
18527
- braintreeInstanceRef.current.then(hostedFieldInstance => {
18528
- hostedFieldInstance.on("notEmpty", function (event) {
18529
- const field = event.fields[event.emittedBy];
18530
- if (field.isPotentiallyValid) {
18531
- 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: ""
18532
18758
  }
18533
18759
  });
18534
- hostedFieldInstance.on("validityChange", function (event) {
18535
- const field = event.fields[event.emittedBy];
18536
-
18537
- // Remove any previously applied error or warning classes
18538
- field.container.classList.remove("is-valid");
18539
- field.container.classList.remove("pelcro-input-invalid");
18540
- if (field.isValid) {
18541
- field.container.classList.add("is-valid");
18542
- } else if (field.isPotentiallyValid) ; else {
18543
- field.container.classList.add("pelcro-input-invalid");
18544
- }
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
18545
18771
  });
18546
- });
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
+ }
18547
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
18548
18788
  const {
18549
18789
  properties
18550
18790
  } = paymentMethodToEdit !== null && paymentMethodToEdit !== void 0 ? paymentMethodToEdit : {};
@@ -18552,9 +18792,14 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18552
18792
  exp_month: expMonth,
18553
18793
  exp_year: expYear
18554
18794
  } = properties !== null && properties !== void 0 ? properties : {};
18555
- braintreeInstanceRef.current = new window.braintree.client.create({
18556
- authorization: braintreeToken
18557
- }).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
+ });
18558
18803
  const options = {
18559
18804
  client: clientInstance,
18560
18805
  styles: {
@@ -18576,41 +18821,28 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18576
18821
  expirationYear: {
18577
18822
  container: "#expiration-year",
18578
18823
  prefill: expYear
18824
+ },
18825
+ cvv: {
18826
+ container: "#cvv"
18579
18827
  }
18580
18828
  }
18581
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);
18582
18838
  dispatch({
18583
18839
  type: SKELETON_LOADER,
18584
- payload: true
18585
- });
18586
- return window.braintree.hostedFields.create(options);
18587
- });
18588
- braintreeInstanceRef.current.then(hostedFieldInstance => {
18589
- hostedFieldInstance.on("notEmpty", function (event) {
18590
- const field = event.fields[event.emittedBy];
18591
- if (field.isPotentiallyValid) {
18592
- field.container.classList.remove("pelcro-input-invalid");
18593
- }
18594
- });
18595
- hostedFieldInstance.on("validityChange", function (event) {
18596
- const field = event.fields[event.emittedBy];
18597
-
18598
- // Remove any previously applied error or warning classes
18599
- field.container.classList.remove("is-valid");
18600
- field.container.classList.remove("pelcro-input-invalid");
18601
- if (field.isValid) {
18602
- field.container.classList.add("is-valid");
18603
- } else if (field.isPotentiallyValid) ; else {
18604
- field.container.classList.add("pelcro-input-invalid");
18605
- }
18840
+ payload: false
18606
18841
  });
18607
- });
18842
+ }
18608
18843
  }
18609
18844
  }
18610
18845
  }
18611
- React.useEffect(() => {
18612
- initializeBraintree();
18613
- }, [selectedPaymentMethodId, paymentMethodToEdit]);
18614
18846
  const braintreeErrorHandler = tokenizeErr => {
18615
18847
  var _tokenizeErr$details, _tokenizeErr$details2;
18616
18848
  const cardNumber = document.querySelector("#card-number");
@@ -18673,51 +18905,55 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18673
18905
  // no need to create a new source using braintree
18674
18906
  return handleBraintreePayment(null, state.couponCode);
18675
18907
  }
18676
- if (!braintreeInstanceRef.current) {
18677
- return console.error("Braintree sdk script wasn't loaded, you need to load braintree sdk before rendering the braintree payment flow");
18678
- }
18679
- braintreeInstanceRef.current.then(hostedFieldInstance => {
18680
- hostedFieldInstance.tokenize((tokenizeErr, payload) => {
18681
- if (tokenizeErr) {
18682
- dispatch({
18683
- type: DISABLE_SUBMIT,
18684
- payload: false
18685
- });
18686
- dispatch({
18687
- type: LOADING,
18688
- payload: false
18689
- });
18690
- return dispatch({
18691
- type: SHOW_ALERT,
18692
- payload: {
18693
- type: "error",
18694
- content: braintreeErrorHandler(tokenizeErr)
18695
- }
18696
- });
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"
18697
18923
  }
18698
-
18699
- // Directly handle the payment with the tokenized payload
18700
- handleBraintreePayment(payload, state.couponCode);
18701
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);
18702
18940
  }).catch(error => {
18703
- if (error) {
18704
- console.error(error);
18705
- dispatch({
18706
- type: DISABLE_SUBMIT,
18707
- payload: false
18708
- });
18709
- dispatch({
18710
- type: LOADING,
18711
- payload: false
18712
- });
18713
- return dispatch({
18714
- type: SHOW_ALERT,
18715
- payload: {
18716
- type: "error",
18717
- content: "There was a problem with your request."
18718
- }
18719
- });
18720
- }
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
+ });
18721
18957
  });
18722
18958
  };
18723
18959
  const handleBraintreePayment = (braintreePaymentRequest, couponCode) => {
@@ -18767,7 +19003,6 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18767
19003
  content: t("messages.sourceCreated")
18768
19004
  }
18769
19005
  });
18770
- refreshUser();
18771
19006
  onSuccess(res);
18772
19007
  });
18773
19008
  }
@@ -19236,9 +19471,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19236
19471
  React.useEffect(() => {
19237
19472
  if (skipPayment && ((plan === null || plan === void 0 ? void 0 : plan.amount) === 0 || props !== null && props !== void 0 && props.freeOrders)) return;
19238
19473
  if (cardProcessor === "vantiv" && !selectedPaymentMethodId) {
19239
- var _window$Pelcro$site$r6, _window$Pelcro$site$r7;
19240
- 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;
19241
- 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;
19242
19477
  vantivInstanceRef.current = new window.EprotectIframeClient({
19243
19478
  paypageId: payPageId,
19244
19479
  reportGroup: reportGroup,
@@ -19302,13 +19537,13 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19302
19537
  });
19303
19538
 
19304
19539
  // When Google pay / Apple pay source created
19305
- paymentRequest.on("source", _ref6 => {
19540
+ paymentRequest.on("source", _ref8 => {
19306
19541
  var _source$card;
19307
19542
  let {
19308
19543
  complete,
19309
19544
  source,
19310
19545
  ...data
19311
- } = _ref6;
19546
+ } = _ref8;
19312
19547
  dispatch({
19313
19548
  type: DISABLE_COUPON_BUTTON,
19314
19549
  payload: true
@@ -19323,11 +19558,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19323
19558
  });
19324
19559
  complete("success");
19325
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") {
19326
- return generate3DSecureSource(source).then(_ref7 => {
19561
+ return generate3DSecureSource(source).then(_ref9 => {
19327
19562
  let {
19328
19563
  source,
19329
19564
  error
19330
- } = _ref7;
19565
+ } = _ref9;
19331
19566
  if (error) {
19332
19567
  return handlePaymentError(error);
19333
19568
  }
@@ -19358,9 +19593,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19358
19593
  * Updates the total amount after adding taxes only if site taxes are enabled
19359
19594
  */
19360
19595
  const updateTotalAmountWithTax = () => {
19361
- var _window$Pelcro$site$r8;
19596
+ var _window$Pelcro$site$r11;
19362
19597
  if (skipPayment && ((plan === null || plan === void 0 ? void 0 : plan.amount) === 0 || props !== null && props !== void 0 && props.freeOrders)) return;
19363
- 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;
19364
19599
  if (taxesEnabled && type === "createPayment") {
19365
19600
  dispatch({
19366
19601
  type: DISABLE_SUBMIT,
@@ -19979,7 +20214,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19979
20214
  cardExpirationMonth: state === null || state === void 0 ? void 0 : state.month,
19980
20215
  cardExpirationYear: state === null || state === void 0 ? void 0 : state.year
19981
20216
  }, (err, orderResponse) => {
19982
- var _window$Pelcro2, _window$Pelcro2$user, _window$Pelcro2$user$;
20217
+ var _window$Pelcro3, _window$Pelcro3$user, _window$Pelcro3$user$;
19983
20218
  if (err) {
19984
20219
  toggleAuthenticationSuccessPendingView(false);
19985
20220
  dispatch({
@@ -20010,7 +20245,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20010
20245
  });
20011
20246
  }
20012
20247
  window.Pelcro.user.refresh({
20013
- 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
20014
20249
  }, (err, res) => {
20015
20250
  dispatch({
20016
20251
  type: DISABLE_SUBMIT,
@@ -20049,11 +20284,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20049
20284
  const createPaymentSource = (state, dispatch) => {
20050
20285
  return stripe.createSource({
20051
20286
  type: "card"
20052
- }).then(_ref8 => {
20287
+ }).then(_ref10 => {
20053
20288
  let {
20054
20289
  source,
20055
20290
  error
20056
- } = _ref8;
20291
+ } = _ref10;
20057
20292
  if (error) {
20058
20293
  return handlePaymentError(error);
20059
20294
  }
@@ -20167,11 +20402,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20167
20402
  } = paymentMethodToDelete;
20168
20403
  return stripe.createSource({
20169
20404
  type: "card"
20170
- }).then(_ref9 => {
20405
+ }).then(_ref11 => {
20171
20406
  let {
20172
20407
  source,
20173
20408
  error
20174
- } = _ref9;
20409
+ } = _ref11;
20175
20410
  if (error) {
20176
20411
  return handlePaymentError(error);
20177
20412
  }
@@ -20271,12 +20506,12 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20271
20506
  }
20272
20507
  stripe.createSource({
20273
20508
  type: "card"
20274
- }).then(_ref10 => {
20275
- var _ref11, _ref12, _state$updatedPrice2;
20509
+ }).then(_ref12 => {
20510
+ var _ref13, _ref14, _state$updatedPrice3;
20276
20511
  let {
20277
20512
  source,
20278
20513
  error
20279
- } = _ref10;
20514
+ } = _ref12;
20280
20515
  if (error) {
20281
20516
  return handlePaymentError(error);
20282
20517
  }
@@ -20295,7 +20530,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20295
20530
  return total + item.price * item.quantity;
20296
20531
  }, 0);
20297
20532
  };
20298
- (_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();
20299
20534
  return handlePayment(source);
20300
20535
  }).catch(error => {
20301
20536
  return handlePaymentError(error);
@@ -20307,11 +20542,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20307
20542
  * @return {Promise}
20308
20543
  */
20309
20544
  const resolveTaxCalculation = () => {
20310
- var _window$Pelcro$site$r9;
20545
+ var _window$Pelcro$site$r12;
20311
20546
  if (type === "invoicePayment") {
20312
20547
  return new Promise(resolve => resolve());
20313
20548
  }
20314
- 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;
20315
20550
  return new Promise((resolve, reject) => {
20316
20551
  // resolve early if taxes isn't enabled
20317
20552
  if (!taxesEnabled) {
@@ -20553,10 +20788,10 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20553
20788
  setVantivPaymentRequest(action.payload);
20554
20789
  });
20555
20790
  case SET_UPDATED_PRICE:
20556
- return lib_7({
20791
+ return lib_5({
20557
20792
  ...state,
20558
20793
  updatedPrice: action.payload
20559
- });
20794
+ }, () => onPriceUpdate(action.payload));
20560
20795
  case SET_TAX_AMOUNT:
20561
20796
  return lib_7({
20562
20797
  ...state,
@@ -20669,6 +20904,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20669
20904
  return state;
20670
20905
  }
20671
20906
  }, initialState$l);
20907
+ React.useEffect(() => {
20908
+ initializeBraintree();
20909
+ }, [selectedPaymentMethodId, paymentMethodToEdit, state.updatedPrice]);
20672
20910
  return /*#__PURE__*/React__default['default'].createElement("div", {
20673
20911
  style: {
20674
20912
  ...style
@@ -20971,32 +21209,21 @@ const CheckoutForm = _ref => {
20971
21209
  }, "Expiration Year *"), /*#__PURE__*/React__default['default'].createElement("div", {
20972
21210
  id: "expiration-year",
20973
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"
20974
21217
  })))) : /*#__PURE__*/React__default['default'].createElement("div", {
20975
21218
  className: "plc-w-full plc-h-40 plc-bg-gray-300 plc-rounded plc-animate-pulse"
20976
21219
  }));
20977
21220
  }
20978
- 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", {
20979
21222
  className: "plc-max-w-[50em]"
20980
- }, /*#__PURE__*/React__default['default'].createElement("label", {
20981
- htmlFor: "card-number"
20982
- }, "Card Number *"), /*#__PURE__*/React__default['default'].createElement("div", {
20983
- id: "card-number",
20984
- className: "pelcro-input-field plc-h-12 plc-bg-white"
20985
- }), /*#__PURE__*/React__default['default'].createElement("div", {
20986
- className: "plc-flex plc-items-start plc-space-x-8 plc-my-6"
20987
- }, /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement("label", {
20988
- htmlFor: "expiration-date"
20989
- }, "Expiration Date *"), /*#__PURE__*/React__default['default'].createElement("div", {
20990
- id: "expiration-date",
20991
- className: "pelcro-input-field plc-h-12 plc-bg-white"
20992
- })), /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement("label", {
20993
- htmlFor: "cvv"
20994
- }, "CVC *"), /*#__PURE__*/React__default['default'].createElement("div", {
20995
- id: "cvv",
20996
- className: "pelcro-input-field plc-h-12 plc-bg-white"
20997
- })))) : /*#__PURE__*/React__default['default'].createElement("div", {
20998
- className: "plc-w-full plc-h-40 plc-bg-gray-300 plc-rounded plc-animate-pulse"
20999
- }));
21223
+ }, /*#__PURE__*/React__default['default'].createElement("div", {
21224
+ id: "dropin-container",
21225
+ className: "plc-w-full plc-min-h-[300px]"
21226
+ })));
21000
21227
  }
21001
21228
  if (cardProcessor === "stripe") {
21002
21229
  if (type === "updatePaymentSource") {
@@ -22141,7 +22368,8 @@ function PaymentMethodView(_ref) {
22141
22368
  showSubscriptionButton,
22142
22369
  showOrderButton,
22143
22370
  showApplePayButton,
22144
- order
22371
+ order,
22372
+ onPriceUpdate
22145
22373
  } = _ref;
22146
22374
  const {
22147
22375
  t
@@ -22184,7 +22412,8 @@ function PaymentMethodView(_ref) {
22184
22412
  onSuccess: onSuccess,
22185
22413
  onGiftRenewalSuccess: onGiftRenewalSuccess,
22186
22414
  onFailure: onFailure,
22187
- freeOrders: showOrderButton
22415
+ freeOrders: showOrderButton,
22416
+ onPriceUpdate: onPriceUpdate
22188
22417
  }, /*#__PURE__*/React__default['default'].createElement(AlertWithContext, {
22189
22418
  className: "plc-mb-2"
22190
22419
  }), showSubscriptionButton && /*#__PURE__*/React__default['default'].createElement(SubscriptionCreateFreePlanButton, null), showOrderButton && /*#__PURE__*/React__default['default'].createElement(OrderCreateFreeButton, null), !showSubscriptionButton && !showOrderButton && /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement(BankRedirection, null), /*#__PURE__*/React__default['default'].createElement(BankAuthenticationSuccess, null), /*#__PURE__*/React__default['default'].createElement(SelectedPaymentMethod, null), supportsTap && (!isUserFirstName || !isUserLastName || !isUserPhone) && /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, null, /*#__PURE__*/React__default['default'].createElement("div", {
@@ -22214,7 +22443,7 @@ function PaymentMethodView(_ref) {
22214
22443
  label: t("labels.isDefault")
22215
22444
  }), /*#__PURE__*/React__default['default'].createElement("div", {
22216
22445
  className: "plc-grid plc-mt-4 plc-gap-y-2"
22217
- }, /*#__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)))));
22446
+ }, /*#__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))))));
22218
22447
  }
22219
22448
 
22220
22449
  const SubscriptionRenewView = _ref => {
@@ -22231,8 +22460,11 @@ const SubscriptionRenewView = _ref => {
22231
22460
  product,
22232
22461
  plan
22233
22462
  } = usePelcro();
22463
+ const [updatedPrice, setUpdatedPrice] = React.useState(null);
22234
22464
  const skipPayment = (_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.skipPaymentForFreePlans;
22235
- const showSubscriptionButton = skipPayment && (plan === null || plan === void 0 ? void 0 : plan.amount) === 0;
22465
+
22466
+ // Check both original plan amount and final amount after coupon
22467
+ const showSubscriptionButton = skipPayment && ((plan === null || plan === void 0 ? void 0 : plan.amount) === 0 || updatedPrice === 0);
22236
22468
  const getPricingText = plan => {
22237
22469
  const autoRenewed = plan.auto_renew;
22238
22470
  const {
@@ -22269,7 +22501,8 @@ const SubscriptionRenewView = _ref => {
22269
22501
  onSuccess: onSuccess,
22270
22502
  onGiftRenewalSuccess: onGiftRenewalSuccess,
22271
22503
  onFailure: onFailure,
22272
- showSubscriptionButton: showSubscriptionButton
22504
+ showSubscriptionButton: showSubscriptionButton,
22505
+ onPriceUpdate: setUpdatedPrice
22273
22506
  }));
22274
22507
  };
22275
22508
 
@@ -23602,8 +23835,11 @@ const SubscriptionCreateView = _ref => {
23602
23835
  product,
23603
23836
  plan
23604
23837
  } = usePelcro();
23838
+ const [updatedPrice, setUpdatedPrice] = React.useState(null);
23605
23839
  const skipPayment = (_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.skipPaymentForFreePlans;
23606
- const showSubscriptionButton = skipPayment && (plan === null || plan === void 0 ? void 0 : plan.amount) === 0;
23840
+
23841
+ // Check both original plan amount and final amount after coupon
23842
+ const showSubscriptionButton = skipPayment && ((plan === null || plan === void 0 ? void 0 : plan.amount) === 0 || updatedPrice === 0);
23607
23843
  const getPricingText = plan => {
23608
23844
  var _plan$quantity;
23609
23845
  const autoRenewed = plan.auto_renew;
@@ -23641,7 +23877,8 @@ const SubscriptionCreateView = _ref => {
23641
23877
  showApplePayButton: true,
23642
23878
  onSuccess: onSuccess,
23643
23879
  onFailure: onFailure,
23644
- showSubscriptionButton: showSubscriptionButton
23880
+ showSubscriptionButton: showSubscriptionButton,
23881
+ onPriceUpdate: setUpdatedPrice
23645
23882
  }));
23646
23883
  };
23647
23884