@pelcro/react-pelcro-js 3.26.0-beta.79 → 3.26.0-beta.80

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
@@ -12032,6 +12032,101 @@ function getFourDigitYear(lastTwoDigits) {
12032
12032
  return fourDigitYear;
12033
12033
  }
12034
12034
 
12035
+ /**
12036
+ * Loads Braintree Drop-in UI script
12037
+ * @returns {Promise} Promise that resolves when script is loaded
12038
+ */
12039
+ function loadBraintreeScript() {
12040
+ return new Promise((resolve, reject) => {
12041
+ // Check if script is already loaded
12042
+ if (window.braintree) {
12043
+ console.log("Braintree script already loaded");
12044
+ resolve(window.braintree);
12045
+ return;
12046
+ }
12047
+ console.log("Loading Braintree script...");
12048
+ const script = document.createElement("script");
12049
+ script.src = "https://js.braintreegateway.com/web/dropin/1.45.1/js/dropin.js";
12050
+ script.onload = () => {
12051
+ console.log("Braintree script loaded successfully");
12052
+ resolve(window.braintree);
12053
+ };
12054
+ script.onerror = error => {
12055
+ console.error("Failed to load Braintree script:", error);
12056
+ reject(new Error("Failed to load Braintree script"));
12057
+ };
12058
+ document.head.appendChild(script);
12059
+ });
12060
+ }
12061
+
12062
+ /**
12063
+ * Creates Braintree Drop-in UI instance
12064
+ * @param {string} authorization - Braintree authorization token
12065
+ * @param {string} selector - CSS selector for the container
12066
+ * @param {Object} options - Additional options for dropin creation
12067
+ * @returns {Promise} Promise that resolves with the dropin instance
12068
+ */
12069
+ function createBraintreeDropin(authorization, selector) {
12070
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
12071
+ console.log("Creating Braintree Drop-in with:", {
12072
+ authorization: authorization ? "present" : "missing",
12073
+ selector,
12074
+ options
12075
+ });
12076
+ return loadBraintreeScript().then(() => {
12077
+ console.log("Braintree script loaded, creating dropin...");
12078
+ return new Promise((resolve, reject) => {
12079
+ window.braintree.dropin.create({
12080
+ authorization,
12081
+ selector,
12082
+ ...options
12083
+ }, (err, instance) => {
12084
+ if (err) {
12085
+ console.error("Braintree dropin creation failed:", err);
12086
+ reject(err);
12087
+ } else {
12088
+ console.log("Braintree dropin created successfully:", instance);
12089
+ resolve(instance);
12090
+ }
12091
+ });
12092
+ });
12093
+ });
12094
+ }
12095
+
12096
+ /**
12097
+ * Requests payment method from Braintree Drop-in UI
12098
+ * @param {Object} instance - Braintree dropin instance
12099
+ * @returns {Promise} Promise that resolves with payment method payload
12100
+ */
12101
+ function requestBraintreePaymentMethod(instance) {
12102
+ return new Promise((resolve, reject) => {
12103
+ instance.requestPaymentMethod((err, payload) => {
12104
+ if (err) {
12105
+ reject(err);
12106
+ } else {
12107
+ resolve(payload);
12108
+ }
12109
+ });
12110
+ });
12111
+ }
12112
+
12113
+ /**
12114
+ * Requests payment method from Braintree Hosted Fields
12115
+ * @param {Object} hostedFieldsInstance - Braintree hosted fields instance
12116
+ * @returns {Promise} Promise that resolves with payment method payload
12117
+ */
12118
+ function requestBraintreeHostedFieldsPaymentMethod(hostedFieldsInstance) {
12119
+ return new Promise((resolve, reject) => {
12120
+ hostedFieldsInstance.tokenize((err, payload) => {
12121
+ if (err) {
12122
+ reject(err);
12123
+ } else {
12124
+ resolve(payload);
12125
+ }
12126
+ });
12127
+ });
12128
+ }
12129
+
12035
12130
  /**
12036
12131
  * @typedef {Object} OptionsType
12037
12132
  * @property {boolean} loadPaymentSDKs
@@ -12134,6 +12229,8 @@ const loadPaymentSDKs = () => {
12134
12229
  }
12135
12230
  if (supportsBraintree) {
12136
12231
  window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.99.0/js/three-d-secure.min.js", "braintree-3D-secure-sdk");
12232
+ window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/dropin/1.45.1/js/dropin.js", "braintree-dropin-sdk");
12233
+ // Keep hosted fields for payment method updates
12137
12234
  window.Pelcro.helpers.loadSDK("https://js.braintreegateway.com/web/3.99.0/js/hosted-fields.min.js", "braintree-hosted-fields-sdk");
12138
12235
  }
12139
12236
 
@@ -17440,10 +17537,6 @@ var es_13 = es.StripeProvider;
17440
17537
 
17441
17538
  function _classPrivateFieldInitSpec$1(obj, privateMap, value) { _checkPrivateRedeclaration$1(obj, privateMap); privateMap.set(obj, value); }
17442
17539
  function _checkPrivateRedeclaration$1(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
17443
- /**
17444
- * @TODO: All payment related business logic should end up moving
17445
- * to this service, and out of react components.
17446
- */
17447
17540
 
17448
17541
  /**
17449
17542
  * Enum for payment types
@@ -18528,6 +18621,16 @@ class BraintreeGateway {
18528
18621
  console.error("Unsupported payment method: braintree Gateway");
18529
18622
  }
18530
18623
  });
18624
+ _defineProperty$3(this, "createDropin", function (authorization, selector) {
18625
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
18626
+ return createBraintreeDropin(authorization, selector, options);
18627
+ });
18628
+ _defineProperty$3(this, "requestPaymentMethod", instance => {
18629
+ return requestBraintreePaymentMethod(instance);
18630
+ });
18631
+ _defineProperty$3(this, "loadScript", () => {
18632
+ return loadBraintreeScript();
18633
+ });
18531
18634
  _classPrivateFieldInitSpec$1(this, _createSubscription6, {
18532
18635
  writable: true,
18533
18636
  value: (options, callback) => {
@@ -18854,6 +18957,80 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18854
18957
  });
18855
18958
  };
18856
18959
 
18960
+ // Helper function to calculate total amount for payment methods
18961
+ const calculateTotalAmount = (state, plan, invoice, order) => {
18962
+ var _ref3, _ref4, _state$updatedPrice;
18963
+ const getOrderItemsTotal = () => {
18964
+ if (!order) {
18965
+ return null;
18966
+ }
18967
+ const isQuickPurchase = !Array.isArray(order);
18968
+ if (isQuickPurchase) {
18969
+ return order.price * order.quantity;
18970
+ }
18971
+ if (order.length === 0) {
18972
+ return null;
18973
+ }
18974
+ return order.reduce((total, item) => {
18975
+ return total + item.price * item.quantity;
18976
+ }, 0);
18977
+ };
18978
+ return (_ref3 = (_ref4 = (_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 && _ref4 !== void 0 ? _ref4 : invoice === null || invoice === void 0 ? void 0 : invoice.amount_remaining) !== null && _ref3 !== void 0 ? _ref3 : getOrderItemsTotal();
18979
+ };
18980
+
18981
+ // Helper function to get currency from the appropriate source
18982
+ const getCurrencyFromPaymentType = (plan, order, invoice) => {
18983
+ if (plan) {
18984
+ return plan.currency;
18985
+ } else if (order) {
18986
+ var _order$;
18987
+ // Handle both single order and array of orders
18988
+ const isQuickPurchase = !Array.isArray(order);
18989
+ return isQuickPurchase ? order.currency : (_order$ = order[0]) === null || _order$ === void 0 ? void 0 : _order$.currency;
18990
+ } else if (invoice) {
18991
+ return invoice.currency;
18992
+ }
18993
+ return "USD"; // Default fallback
18994
+ };
18995
+
18996
+ // Helper function to get payment label
18997
+ const getPaymentLabel = (plan, order, invoice) => {
18998
+ var _window$Pelcro$site$r;
18999
+ if (plan) {
19000
+ return plan.nickname || plan.description || "Subscription";
19001
+ } else if (order) {
19002
+ // Handle both single order and array of orders
19003
+ const isQuickPurchase = !Array.isArray(order);
19004
+ if (isQuickPurchase) {
19005
+ return order.name || "Order";
19006
+ } else {
19007
+ return order.length === 1 ? order[0].name : "Order";
19008
+ }
19009
+ } else if (invoice) {
19010
+ return `Invoice #${invoice.id}`;
19011
+ }
19012
+ return ((_window$Pelcro$site$r = window.Pelcro.site.read()) === null || _window$Pelcro$site$r === void 0 ? void 0 : _window$Pelcro$site$r.name) || "Payment";
19013
+ };
19014
+
19015
+ // Helper function to format amount for payment methods (Apple Pay, Google Pay)
19016
+ const formatPaymentAmount = function (totalAmount, currency) {
19017
+ var _window$Pelcro5, _window$Pelcro5$utils, _window$Pelcro5$utils2, _currency$toUpperCase;
19018
+ let paymentMethod = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "";
19019
+ if (!totalAmount) return "0.00";
19020
+ const isZeroDecimal = ((_window$Pelcro5 = window.Pelcro) === null || _window$Pelcro5 === void 0 ? void 0 : (_window$Pelcro5$utils = _window$Pelcro5.utils) === null || _window$Pelcro5$utils === void 0 ? void 0 : (_window$Pelcro5$utils2 = _window$Pelcro5$utils.isCurrencyZeroDecimal) === null || _window$Pelcro5$utils2 === void 0 ? void 0 : _window$Pelcro5$utils2.call(_window$Pelcro5$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));
19021
+
19022
+ // Payment methods expect amount in major currency unit (dollars, not cents)
19023
+ let finalAmount;
19024
+ if (isZeroDecimal) {
19025
+ finalAmount = Math.round(totalAmount).toString();
19026
+ } else {
19027
+ // Convert from cents to dollars and format with 2 decimal places
19028
+ finalAmount = (totalAmount / 100).toFixed(2);
19029
+ }
19030
+ console.log(`${paymentMethod} amount:`, finalAmount, "currency:", currency, "type:", type);
19031
+ return String(finalAmount);
19032
+ };
19033
+
18857
19034
  /* ====== Start Cybersource integration ======== */
18858
19035
  const cybersourceErrorHandle = err => {
18859
19036
  var _err$details, _err$details$response, _err$details$response2;
@@ -18862,10 +19039,10 @@ const PaymentMethodContainerWithoutStripe = _ref => {
18862
19039
  const errorMessages = [];
18863
19040
 
18864
19041
  // enumerable error (ex: validation errors)
18865
- 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(_ref3 => {
19042
+ 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(_ref5 => {
18866
19043
  let {
18867
19044
  message
18868
- } = _ref3;
19045
+ } = _ref5;
18869
19046
  errorMessages.push(message);
18870
19047
  });
18871
19048
 
@@ -19083,10 +19260,10 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19083
19260
  // No longer needed - microform instance is stored directly in initCybersourceScript
19084
19261
 
19085
19262
  const appendCybersourceFingerprintScripts = () => {
19086
- var _window$Pelcro$site$r, _window$Pelcro$site$r2, _window$Pelcro$site$r3, _window$Pelcro$site$r4;
19263
+ var _window$Pelcro$site$r2, _window$Pelcro$site$r3, _window$Pelcro$site$r4, _window$Pelcro$site$r5;
19087
19264
  const uniqueId = crypto.randomUUID();
19088
- 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;
19089
- 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;
19265
+ 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;
19266
+ 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;
19090
19267
  const fingerPrintScript = document.querySelector(`script[src="https://h.online-metrix.net/fp/tags.js?org_id=${orgID}&session_id=${sessionID}"]`);
19091
19268
  const fingerPringIframe = document.querySelector(`iframe[src="https://h.online-metrix.net/fp/tags?org_id=${orgID}&session_id=${sessionID}"]`);
19092
19269
  if (!fingerPrintScript && !fingerPringIframe) {
@@ -19192,7 +19369,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19192
19369
 
19193
19370
  /* ====== Start Tap integration ======== */
19194
19371
  const submitUsingTap = state => {
19195
- var _ref4, _ref5, _getPlanAmount;
19372
+ var _ref6, _ref7, _getPlanAmount;
19196
19373
  const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
19197
19374
  if (isUsingExistingPaymentMethod) {
19198
19375
  // no need to create a new source using tap
@@ -19224,7 +19401,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19224
19401
  return plan.amount;
19225
19402
  }
19226
19403
  }
19227
- const totalAmount = (_ref4 = (_ref5 = (_getPlanAmount = getPlanAmount()) !== null && _getPlanAmount !== void 0 ? _getPlanAmount : invoice === null || invoice === void 0 ? void 0 : invoice.amount_remaining) !== null && _ref5 !== void 0 ? _ref5 : getOrderItemsTotal()) !== null && _ref4 !== void 0 ? _ref4 : 10;
19404
+ const totalAmount = (_ref6 = (_ref7 = (_getPlanAmount = getPlanAmount()) !== null && _getPlanAmount !== void 0 ? _getPlanAmount : invoice === null || invoice === void 0 ? void 0 : invoice.amount_remaining) !== null && _ref7 !== void 0 ? _ref7 : getOrderItemsTotal()) !== null && _ref6 !== void 0 ? _ref6 : 10;
19228
19405
  tapInstanceRef.current.createToken(tapInstanceCard.current).then(function (result) {
19229
19406
  if (result.error) {
19230
19407
  // Inform the user if there was an error
@@ -19434,8 +19611,8 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19434
19611
  }
19435
19612
  }
19436
19613
  const initTapScript = () => {
19437
- var _window$Pelcro$site$r5;
19438
- 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);
19614
+ var _window$Pelcro$site$r6;
19615
+ 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);
19439
19616
  let elements = tapKey.elements({});
19440
19617
  let style = {
19441
19618
  base: {
@@ -19485,8 +19662,8 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19485
19662
  };
19486
19663
  /* ====== End Tap integration ======== */
19487
19664
 
19488
- /* ====== Start Braintree integration ======== */
19489
- const braintreeInstanceRef = React__default['default'].useRef(null);
19665
+ /* ====== Start Braintree Drop-in UI integration ======== */
19666
+ const braintreeDropinRef = React__default['default'].useRef(null);
19490
19667
  const braintree3DSecureInstanceRef = React__default['default'].useRef(null);
19491
19668
  function getClientToken() {
19492
19669
  return new Promise((resolve, reject) => {
@@ -19506,18 +19683,46 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19506
19683
  async function initializeBraintree() {
19507
19684
  if (skipPayment && ((plan === null || plan === void 0 ? void 0 : plan.amount) === 0 || props !== null && props !== void 0 && props.freeOrders)) return;
19508
19685
  if (cardProcessor === "braintree" && !selectedPaymentMethodId) {
19686
+ // Clear container before initializing
19687
+ const dropinContainer = document.getElementById("dropin-container");
19688
+ if (dropinContainer) dropinContainer.innerHTML = "";
19509
19689
  const braintreeToken = await getClientToken();
19510
19690
  const isBraintreeEnabled = Boolean(braintreeToken);
19511
19691
  if (!isBraintreeEnabled) {
19512
19692
  console.error("Braintree integration is currently not enabled on this site's config");
19513
19693
  return;
19514
19694
  }
19695
+ console.log("braintreeToken", plan);
19515
19696
  if (type !== "updatePaymentSource") {
19516
- braintreeInstanceRef.current = new window.braintree.client.create({
19517
- authorization: braintreeToken
19518
- }).then(clientInstance => {
19519
- const options = {
19520
- authorization: braintreeToken,
19697
+ console.log("Setting skeleton loader to true at start of Braintree initialization");
19698
+ dispatch({
19699
+ type: SKELETON_LOADER,
19700
+ payload: true
19701
+ });
19702
+ try {
19703
+ var _window$Pelcro$site$r7, _window$Pelcro$site$r8;
19704
+ // Ensure the DOM element exists before creating Drop-in UI
19705
+ const dropinContainer = document.querySelector("#dropin-container");
19706
+ if (!dropinContainer) {
19707
+ console.error("Drop-in container not found. Waiting for DOM to be ready...");
19708
+ dispatch({
19709
+ type: SKELETON_LOADER,
19710
+ payload: false
19711
+ });
19712
+ return;
19713
+ }
19714
+
19715
+ // Small delay to ensure DOM is fully rendered
19716
+ await new Promise(resolve => setTimeout(resolve, 100));
19717
+
19718
+ // Calculate Google Pay amount using the same logic as Apple Pay
19719
+ const totalAmount = calculateTotalAmount(state, plan, invoice, order);
19720
+ const currency = getCurrencyFromPaymentType(plan, order, invoice);
19721
+ const googlePayAmount = formatPaymentAmount(totalAmount, currency, "Google Pay");
19722
+
19723
+ // Create Braintree Drop-in UI instance
19724
+ braintreeDropinRef.current = await createBraintreeDropin(braintreeToken, "#dropin-container", {
19725
+ // Customize the Drop-in UI appearance
19521
19726
  styles: {
19522
19727
  input: {
19523
19728
  "font-size": "14px"
@@ -19529,54 +19734,93 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19529
19734
  color: "green"
19530
19735
  }
19531
19736
  },
19532
- fields: {
19533
- number: {
19534
- container: "#card-number",
19535
- placeholder: "4111 1111 1111 1111"
19536
- },
19537
- cvv: {
19538
- container: "#cvv",
19539
- placeholder: "123"
19737
+ // Disable PayPal to avoid conflicts with existing PayPal SDK
19738
+ // paypal: {
19739
+ // flow: "vault"
19740
+ // },
19741
+ // Enable Apple Pay if available
19742
+ applePay: {
19743
+ displayName: ((_window$Pelcro$site$r7 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r7 === void 0 ? void 0 : _window$Pelcro$site$r7.name) || "Pelcro",
19744
+ paymentRequest: {
19745
+ total: {
19746
+ label: getPaymentLabel(plan, order, invoice),
19747
+ amount: (() => {
19748
+ const totalAmount = calculateTotalAmount(state, plan, invoice, order);
19749
+ const currency = getCurrencyFromPaymentType(plan, order, invoice);
19750
+ return formatPaymentAmount(totalAmount, currency, "Apple Pay");
19751
+ })()
19752
+ }
19753
+ }
19754
+ },
19755
+ // Enable Google Pay for both orders and subscriptions
19756
+ googlePay: {
19757
+ googlePayVersion: 2,
19758
+ 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,
19759
+ transactionInfo: {
19760
+ totalPriceStatus: "FINAL",
19761
+ totalPrice: googlePayAmount,
19762
+ currencyCode: (() => {
19763
+ const currency = getCurrencyFromPaymentType(plan, order, invoice);
19764
+ return (currency === null || currency === void 0 ? void 0 : currency.toUpperCase()) || "USD";
19765
+ })()
19540
19766
  },
19541
- expirationDate: {
19542
- container: "#expiration-date",
19543
- placeholder: "10/2022"
19767
+ // Add button configuration
19768
+ button: {
19769
+ color: "black",
19770
+ type: type === "createPayment" ? "subscribe" : "buy"
19544
19771
  }
19545
19772
  }
19546
- };
19547
- dispatch({
19548
- type: SKELETON_LOADER,
19549
- payload: true
19550
19773
  });
19774
+
19775
+ // Initialize 3D Secure for additional security
19551
19776
  braintree3DSecureInstanceRef.current = new window.braintree.threeDSecure.create({
19552
19777
  version: 2,
19553
19778
  authorization: braintreeToken
19554
19779
  }).then(threeDSecureInstance => {
19555
19780
  return threeDSecureInstance;
19556
19781
  });
19557
- return window.braintree.hostedFields.create(options);
19558
- });
19559
- braintreeInstanceRef.current.then(hostedFieldInstance => {
19560
- hostedFieldInstance.on("notEmpty", function (event) {
19561
- const field = event.fields[event.emittedBy];
19562
- if (field.isPotentiallyValid) {
19563
- field.container.classList.remove("pelcro-input-invalid");
19564
- }
19782
+ console.log("Setting skeleton loader to false after successful Braintree initialization");
19783
+ dispatch({
19784
+ type: SKELETON_LOADER,
19785
+ payload: false
19565
19786
  });
19566
- hostedFieldInstance.on("validityChange", function (event) {
19567
- const field = event.fields[event.emittedBy];
19568
-
19569
- // Remove any previously applied error or warning classes
19570
- field.container.classList.remove("is-valid");
19571
- field.container.classList.remove("pelcro-input-invalid");
19572
- if (field.isValid) {
19573
- field.container.classList.add("is-valid");
19574
- } else if (field.isPotentiallyValid) ; else {
19575
- field.container.classList.add("pelcro-input-invalid");
19787
+
19788
+ // Clear any error alerts that were shown during initialization
19789
+ dispatch({
19790
+ type: SHOW_ALERT,
19791
+ payload: {
19792
+ type: "error",
19793
+ content: ""
19576
19794
  }
19577
19795
  });
19578
- });
19796
+ } catch (error) {
19797
+ var _error$message, _error$message2, _error$message3, _error$message4;
19798
+ console.error("Failed to initialize Braintree Drop-in UI:", error);
19799
+
19800
+ // Check if it's a Google Pay specific error
19801
+ 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")) {
19802
+ console.warn("Google Pay configuration issue detected. " + `Transaction type: ${type}. ` + "This might be due to merchant settings or unsupported payment flow.");
19803
+ }
19804
+ dispatch({
19805
+ type: SKELETON_LOADER,
19806
+ payload: false
19807
+ });
19808
+
19809
+ // Don't show error to user for Google Pay configuration issues
19810
+ // as it's expected for subscriptions
19811
+ 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"))) {
19812
+ dispatch({
19813
+ type: SHOW_ALERT,
19814
+ payload: {
19815
+ type: "error",
19816
+ content: "Failed to initialize payment form. Please refresh and try again."
19817
+ }
19818
+ });
19819
+ }
19820
+ }
19579
19821
  } else if (type == "updatePaymentSource" && paymentMethodToEdit) {
19822
+ // For updating payment methods, we still use hosted fields
19823
+ // as Drop-in UI doesn't support partial updates
19580
19824
  const {
19581
19825
  properties
19582
19826
  } = paymentMethodToEdit !== null && paymentMethodToEdit !== void 0 ? paymentMethodToEdit : {};
@@ -19584,9 +19828,14 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19584
19828
  exp_month: expMonth,
19585
19829
  exp_year: expYear
19586
19830
  } = properties !== null && properties !== void 0 ? properties : {};
19587
- braintreeInstanceRef.current = new window.braintree.client.create({
19588
- authorization: braintreeToken
19589
- }).then(clientInstance => {
19831
+ dispatch({
19832
+ type: SKELETON_LOADER,
19833
+ payload: true
19834
+ });
19835
+ try {
19836
+ const clientInstance = await new window.braintree.client.create({
19837
+ authorization: braintreeToken
19838
+ });
19590
19839
  const options = {
19591
19840
  client: clientInstance,
19592
19841
  styles: {
@@ -19608,41 +19857,28 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19608
19857
  expirationYear: {
19609
19858
  container: "#expiration-year",
19610
19859
  prefill: expYear
19860
+ },
19861
+ cvv: {
19862
+ container: "#cvv"
19611
19863
  }
19612
19864
  }
19613
19865
  };
19866
+ braintreeDropinRef.current = await window.braintree.hostedFields.create(options);
19867
+
19868
+ // dispatch({
19869
+ // type: SKELETON_LOADER,
19870
+ // payload: false
19871
+ // });
19872
+ } catch (error) {
19873
+ console.error("Failed to initialize Braintree hosted fields:", error);
19614
19874
  dispatch({
19615
19875
  type: SKELETON_LOADER,
19616
- payload: true
19617
- });
19618
- return window.braintree.hostedFields.create(options);
19619
- });
19620
- braintreeInstanceRef.current.then(hostedFieldInstance => {
19621
- hostedFieldInstance.on("notEmpty", function (event) {
19622
- const field = event.fields[event.emittedBy];
19623
- if (field.isPotentiallyValid) {
19624
- field.container.classList.remove("pelcro-input-invalid");
19625
- }
19626
- });
19627
- hostedFieldInstance.on("validityChange", function (event) {
19628
- const field = event.fields[event.emittedBy];
19629
-
19630
- // Remove any previously applied error or warning classes
19631
- field.container.classList.remove("is-valid");
19632
- field.container.classList.remove("pelcro-input-invalid");
19633
- if (field.isValid) {
19634
- field.container.classList.add("is-valid");
19635
- } else if (field.isPotentiallyValid) ; else {
19636
- field.container.classList.add("pelcro-input-invalid");
19637
- }
19876
+ payload: false
19638
19877
  });
19639
- });
19878
+ }
19640
19879
  }
19641
19880
  }
19642
19881
  }
19643
- React.useEffect(() => {
19644
- initializeBraintree();
19645
- }, [selectedPaymentMethodId, paymentMethodToEdit]);
19646
19882
  const braintreeErrorHandler = tokenizeErr => {
19647
19883
  var _tokenizeErr$details, _tokenizeErr$details2;
19648
19884
  const cardNumber = document.querySelector("#card-number");
@@ -19700,14 +19936,29 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19700
19936
  }
19701
19937
  };
19702
19938
  const submitUsingBraintree = (state, dispatch) => {
19703
- var _ref6, _ref7, _state$updatedPrice;
19939
+ var _ref8, _ref9, _state$updatedPrice2;
19704
19940
  const isUsingExistingPaymentMethod = Boolean(selectedPaymentMethodId);
19705
19941
  if (isUsingExistingPaymentMethod) {
19706
19942
  // no need to create a new source using braintree
19707
19943
  return handleBraintreePayment(null, state.couponCode);
19708
19944
  }
19709
- if (!braintreeInstanceRef.current) {
19710
- return console.error("Braintree sdk script wasn't loaded, you need to load braintree sdk before rendering the braintree payment flow");
19945
+ if (!braintreeDropinRef.current) {
19946
+ console.error("Braintree Drop-in UI wasn't initialized, please try again");
19947
+ dispatch({
19948
+ type: DISABLE_SUBMIT,
19949
+ payload: false
19950
+ });
19951
+ dispatch({
19952
+ type: LOADING,
19953
+ payload: false
19954
+ });
19955
+ return dispatch({
19956
+ type: SHOW_ALERT,
19957
+ payload: {
19958
+ type: "error",
19959
+ content: "Braintree Drop-in UI wasn't initialized, please try again"
19960
+ }
19961
+ });
19711
19962
  }
19712
19963
  const getOrderItemsTotal = () => {
19713
19964
  if (!order) {
@@ -19724,41 +19975,36 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19724
19975
  return total + item.price * item.quantity;
19725
19976
  }, 0);
19726
19977
  };
19727
- const totalAmount = (_ref6 = (_ref7 = (_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 && _ref7 !== void 0 ? _ref7 : invoice === null || invoice === void 0 ? void 0 : invoice.amount_remaining) !== null && _ref6 !== void 0 ? _ref6 : getOrderItemsTotal();
19728
- braintreeInstanceRef.current.then(hostedFieldInstance => {
19729
- hostedFieldInstance.tokenize((tokenizeErr, payload) => {
19730
- if (tokenizeErr) {
19731
- dispatch({
19732
- type: DISABLE_SUBMIT,
19733
- payload: false
19734
- });
19735
- dispatch({
19736
- type: LOADING,
19737
- payload: false
19738
- });
19739
- return dispatch({
19740
- type: SHOW_ALERT,
19741
- payload: {
19742
- type: "error",
19743
- content: braintreeErrorHandler(tokenizeErr)
19744
- }
19745
- });
19746
- }
19747
- if (type == "updatePaymentSource" || type == "deletePaymentSource") {
19748
- handleBraintreePayment(payload, state.couponCode);
19749
- } else {
19978
+ const totalAmount = (_ref8 = (_ref9 = (_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 && _ref9 !== void 0 ? _ref9 : invoice === null || invoice === void 0 ? void 0 : invoice.amount_remaining) !== null && _ref8 !== void 0 ? _ref8 : getOrderItemsTotal();
19979
+ dispatch({
19980
+ type: LOADING,
19981
+ payload: true
19982
+ });
19983
+ dispatch({
19984
+ type: DISABLE_SUBMIT,
19985
+ payload: true
19986
+ });
19987
+
19988
+ // Use appropriate method based on payment type
19989
+ const paymentMethodPromise = type === "updatePaymentSource" ? requestBraintreeHostedFieldsPaymentMethod(braintreeDropinRef.current) : requestBraintreePaymentMethod(braintreeDropinRef.current);
19990
+ paymentMethodPromise.then(payload => {
19991
+ if (type == "updatePaymentSource" || type == "deletePaymentSource") {
19992
+ handleBraintreePayment(payload, state.couponCode);
19993
+ } else {
19994
+ // For new payments, use 3D Secure if available
19995
+ if (braintree3DSecureInstanceRef.current) {
19750
19996
  braintree3DSecureInstanceRef.current.then(threeDSecureInstance => {
19751
19997
  threeDSecureInstance.verifyCard({
19752
19998
  onLookupComplete: function (data, next) {
19753
19999
  next();
19754
20000
  },
19755
- amount: totalAmount !== null && totalAmount !== void 0 ? totalAmount : "0.00",
20001
+ amount: totalAmount ? (totalAmount / 100).toFixed(2) : "0.00",
19756
20002
  nonce: payload.nonce,
19757
20003
  bin: payload.details.bin
19758
- }).then(payload => {
19759
- if (payload.liabilityShifted) {
19760
- handleBraintreePayment(payload, state.couponCode);
19761
- } else if (payload.liabilityShiftPossible) {
20004
+ }).then(securePayload => {
20005
+ if (securePayload.liabilityShifted) {
20006
+ handleBraintreePayment(securePayload, state.couponCode);
20007
+ } else if (securePayload.liabilityShiftPossible) {
19762
20008
  dispatch({
19763
20009
  type: DISABLE_SUBMIT,
19764
20010
  payload: false
@@ -19811,13 +20057,28 @@ const PaymentMethodContainerWithoutStripe = _ref => {
19811
20057
  });
19812
20058
  });
19813
20059
  });
20060
+ } else {
20061
+ // If 3D Secure is not available, proceed with regular payment
20062
+ handleBraintreePayment(payload, state.couponCode);
19814
20063
  }
19815
- });
19816
- }).catch(error => {
19817
- if (error) {
19818
- console.error(error);
19819
- return;
19820
20064
  }
20065
+ }).catch(error => {
20066
+ console.error("Braintree payment error:", error);
20067
+ dispatch({
20068
+ type: DISABLE_SUBMIT,
20069
+ payload: false
20070
+ });
20071
+ dispatch({
20072
+ type: LOADING,
20073
+ payload: false
20074
+ });
20075
+ return dispatch({
20076
+ type: SHOW_ALERT,
20077
+ payload: {
20078
+ type: "error",
20079
+ content: braintreeErrorHandler(error)
20080
+ }
20081
+ });
19821
20082
  });
19822
20083
  };
19823
20084
  const handleBraintreePayment = (braintreePaymentRequest, couponCode) => {
@@ -20335,9 +20596,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20335
20596
  React.useEffect(() => {
20336
20597
  if (skipPayment && ((plan === null || plan === void 0 ? void 0 : plan.amount) === 0 || props !== null && props !== void 0 && props.freeOrders)) return;
20337
20598
  if (cardProcessor === "vantiv" && !selectedPaymentMethodId) {
20338
- var _window$Pelcro$site$r6, _window$Pelcro$site$r7;
20339
- 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;
20340
- 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;
20599
+ var _window$Pelcro$site$r9, _window$Pelcro$site$r10;
20600
+ 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;
20601
+ 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;
20341
20602
  vantivInstanceRef.current = new window.EprotectIframeClient({
20342
20603
  paypageId: payPageId,
20343
20604
  reportGroup: reportGroup,
@@ -20409,13 +20670,13 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20409
20670
  });
20410
20671
 
20411
20672
  // When Google pay / Apple pay source created
20412
- paymentRequest.on("source", _ref8 => {
20673
+ paymentRequest.on("source", _ref10 => {
20413
20674
  var _source$card;
20414
20675
  let {
20415
20676
  complete,
20416
20677
  source,
20417
20678
  ...data
20418
- } = _ref8;
20679
+ } = _ref10;
20419
20680
  dispatch({
20420
20681
  type: DISABLE_COUPON_BUTTON,
20421
20682
  payload: true
@@ -20430,11 +20691,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20430
20691
  });
20431
20692
  complete("success");
20432
20693
  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") {
20433
- return generate3DSecureSource(source).then(_ref9 => {
20694
+ return generate3DSecureSource(source).then(_ref11 => {
20434
20695
  let {
20435
20696
  source,
20436
20697
  error
20437
- } = _ref9;
20698
+ } = _ref11;
20438
20699
  if (error) {
20439
20700
  handlePaymentError(error);
20440
20701
  fireBugSnag({
@@ -20470,9 +20731,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20470
20731
  * Updates the total amount after adding taxes only if site taxes are enabled
20471
20732
  */
20472
20733
  const updateTotalAmountWithTax = () => {
20473
- var _window$Pelcro$site$r8;
20734
+ var _window$Pelcro$site$r11;
20474
20735
  if (skipPayment && ((plan === null || plan === void 0 ? void 0 : plan.amount) === 0 || props !== null && props !== void 0 && props.freeOrders)) return;
20475
- 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;
20736
+ 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;
20476
20737
  if (taxesEnabled && type === "createPayment") {
20477
20738
  dispatch({
20478
20739
  type: DISABLE_SUBMIT,
@@ -20630,7 +20891,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20630
20891
  address_id: selectedAddressId
20631
20892
  }, handleCouponResponse);
20632
20893
  } else if (type === "orderCreate") {
20633
- var _window$Pelcro$site$r9;
20894
+ var _window$Pelcro$site$r12;
20634
20895
  const isQuickPurchase = !Array.isArray(order);
20635
20896
  const mappedOrderItems = isQuickPurchase ? [{
20636
20897
  sku_id: order.id,
@@ -20643,7 +20904,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20643
20904
  items: mappedOrderItems,
20644
20905
  coupon_code: couponCode
20645
20906
  };
20646
- if ((_window$Pelcro$site$r9 = window.Pelcro.site.read()) !== null && _window$Pelcro$site$r9 !== void 0 && _window$Pelcro$site$r9.taxes_enabled) {
20907
+ if ((_window$Pelcro$site$r12 = window.Pelcro.site.read()) !== null && _window$Pelcro$site$r12 !== void 0 && _window$Pelcro$site$r12.taxes_enabled) {
20647
20908
  orderSummaryParams.address_id = selectedAddressId;
20648
20909
  }
20649
20910
  window.Pelcro.ecommerce.order.createSummary(orderSummaryParams, handleCouponResponse);
@@ -20733,15 +20994,15 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20733
20994
  notifyBugsnag(() => {
20734
20995
  // eslint-disable-next-line no-undef
20735
20996
  Bugsnag.notify(`Payment ${res.error}`, event => {
20736
- var _error$response3, _error$response3$data, _error$response3$data2, _window$Pelcro5, _window$Pelcro5$site, _window$Pelcro6, _window$Pelcro6$user, _window$Pelcro7;
20997
+ var _error$response3, _error$response3$data, _error$response3$data2, _window$Pelcro6, _window$Pelcro6$site, _window$Pelcro7, _window$Pelcro7$user, _window$Pelcro8;
20737
20998
  event.addMetadata("Stripe Error MetaData", {
20738
20999
  message: res.error.message,
20739
21000
  type: res.error.type,
20740
21001
  code: res.error.code,
20741
21002
  error_message: error === null || error === void 0 ? void 0 : (_error$response3 = error.response) === null || _error$response3 === void 0 ? void 0 : (_error$response3$data = _error$response3.data) === null || _error$response3$data === void 0 ? void 0 : (_error$response3$data2 = _error$response3$data.error) === null || _error$response3$data2 === void 0 ? void 0 : _error$response3$data2.message,
20742
- site: (_window$Pelcro5 = window.Pelcro) === null || _window$Pelcro5 === void 0 ? void 0 : (_window$Pelcro5$site = _window$Pelcro5.site) === null || _window$Pelcro5$site === void 0 ? void 0 : _window$Pelcro5$site.read(),
20743
- user: (_window$Pelcro6 = window.Pelcro) === null || _window$Pelcro6 === void 0 ? void 0 : (_window$Pelcro6$user = _window$Pelcro6.user) === null || _window$Pelcro6$user === void 0 ? void 0 : _window$Pelcro6$user.read(),
20744
- environment: (_window$Pelcro7 = window.Pelcro) === null || _window$Pelcro7 === void 0 ? void 0 : _window$Pelcro7.environment
21003
+ site: (_window$Pelcro6 = window.Pelcro) === null || _window$Pelcro6 === void 0 ? void 0 : (_window$Pelcro6$site = _window$Pelcro6.site) === null || _window$Pelcro6$site === void 0 ? void 0 : _window$Pelcro6$site.read(),
21004
+ user: (_window$Pelcro7 = window.Pelcro) === null || _window$Pelcro7 === void 0 ? void 0 : (_window$Pelcro7$user = _window$Pelcro7.user) === null || _window$Pelcro7$user === void 0 ? void 0 : _window$Pelcro7$user.read(),
21005
+ environment: (_window$Pelcro8 = window.Pelcro) === null || _window$Pelcro8 === void 0 ? void 0 : _window$Pelcro8.environment
20745
21006
  });
20746
21007
  });
20747
21008
  });
@@ -20790,7 +21051,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20790
21051
  notifyBugsnag(() => {
20791
21052
  // eslint-disable-next-line no-undef
20792
21053
  Bugsnag.notify(`Payment ${error}`, event => {
20793
- var _error$response4, _error$response5, _error$response5$data, _error$response5$data2, _window$Pelcro8, _window$Pelcro8$site, _window$Pelcro9, _window$Pelcro9$user, _window$Pelcro10;
21054
+ var _error$response4, _error$response5, _error$response5$data, _error$response5$data2, _window$Pelcro9, _window$Pelcro9$site, _window$Pelcro10, _window$Pelcro10$user, _window$Pelcro11;
20794
21055
  event.addMetadata("MetaData", {
20795
21056
  name: error === null || error === void 0 ? void 0 : error.name,
20796
21057
  message: error === null || error === void 0 ? void 0 : error.message,
@@ -20798,9 +21059,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20798
21059
  code: error === null || error === void 0 ? void 0 : error.code,
20799
21060
  status: error === null || error === void 0 ? void 0 : (_error$response4 = error.response) === null || _error$response4 === void 0 ? void 0 : _error$response4.status,
20800
21061
  error_message: error === null || error === void 0 ? void 0 : (_error$response5 = error.response) === null || _error$response5 === void 0 ? void 0 : (_error$response5$data = _error$response5.data) === null || _error$response5$data === void 0 ? void 0 : (_error$response5$data2 = _error$response5$data.error) === null || _error$response5$data2 === void 0 ? void 0 : _error$response5$data2.message,
20801
- site: (_window$Pelcro8 = window.Pelcro) === null || _window$Pelcro8 === void 0 ? void 0 : (_window$Pelcro8$site = _window$Pelcro8.site) === null || _window$Pelcro8$site === void 0 ? void 0 : _window$Pelcro8$site.read(),
20802
- user: (_window$Pelcro9 = window.Pelcro) === null || _window$Pelcro9 === void 0 ? void 0 : (_window$Pelcro9$user = _window$Pelcro9.user) === null || _window$Pelcro9$user === void 0 ? void 0 : _window$Pelcro9$user.read(),
20803
- environment: (_window$Pelcro10 = window.Pelcro) === null || _window$Pelcro10 === void 0 ? void 0 : _window$Pelcro10.environment
21062
+ site: (_window$Pelcro9 = window.Pelcro) === null || _window$Pelcro9 === void 0 ? void 0 : (_window$Pelcro9$site = _window$Pelcro9.site) === null || _window$Pelcro9$site === void 0 ? void 0 : _window$Pelcro9$site.read(),
21063
+ user: (_window$Pelcro10 = window.Pelcro) === null || _window$Pelcro10 === void 0 ? void 0 : (_window$Pelcro10$user = _window$Pelcro10.user) === null || _window$Pelcro10$user === void 0 ? void 0 : _window$Pelcro10$user.read(),
21064
+ environment: (_window$Pelcro11 = window.Pelcro) === null || _window$Pelcro11 === void 0 ? void 0 : _window$Pelcro11.environment
20804
21065
  });
20805
21066
  });
20806
21067
  });
@@ -20819,14 +21080,14 @@ const PaymentMethodContainerWithoutStripe = _ref => {
20819
21080
  notifyBugsnag(() => {
20820
21081
  // eslint-disable-next-line no-undef
20821
21082
  Bugsnag.notify(`Payment ${error}`, event => {
20822
- var _error$response6, _error$response6$data, _error$response6$data2, _window$Pelcro11, _window$Pelcro11$site, _window$Pelcro12, _window$Pelcro12$user, _window$Pelcro13;
21083
+ var _error$response6, _error$response6$data, _error$response6$data2, _window$Pelcro12, _window$Pelcro12$site, _window$Pelcro13, _window$Pelcro13$user, _window$Pelcro14;
20823
21084
  event.addMetadata("UnexpectedError", {
20824
21085
  message: error.message,
20825
21086
  stack: error.stack,
20826
21087
  error_message: error === null || error === void 0 ? void 0 : (_error$response6 = error.response) === null || _error$response6 === void 0 ? void 0 : (_error$response6$data = _error$response6.data) === null || _error$response6$data === void 0 ? void 0 : (_error$response6$data2 = _error$response6$data.error) === null || _error$response6$data2 === void 0 ? void 0 : _error$response6$data2.message,
20827
- site: (_window$Pelcro11 = window.Pelcro) === null || _window$Pelcro11 === void 0 ? void 0 : (_window$Pelcro11$site = _window$Pelcro11.site) === null || _window$Pelcro11$site === void 0 ? void 0 : _window$Pelcro11$site.read(),
20828
- user: (_window$Pelcro12 = window.Pelcro) === null || _window$Pelcro12 === void 0 ? void 0 : (_window$Pelcro12$user = _window$Pelcro12.user) === null || _window$Pelcro12$user === void 0 ? void 0 : _window$Pelcro12$user.read(),
20829
- environment: (_window$Pelcro13 = window.Pelcro) === null || _window$Pelcro13 === void 0 ? void 0 : _window$Pelcro13.environment
21088
+ site: (_window$Pelcro12 = window.Pelcro) === null || _window$Pelcro12 === void 0 ? void 0 : (_window$Pelcro12$site = _window$Pelcro12.site) === null || _window$Pelcro12$site === void 0 ? void 0 : _window$Pelcro12$site.read(),
21089
+ user: (_window$Pelcro13 = window.Pelcro) === null || _window$Pelcro13 === void 0 ? void 0 : (_window$Pelcro13$user = _window$Pelcro13.user) === null || _window$Pelcro13$user === void 0 ? void 0 : _window$Pelcro13$user.read(),
21090
+ environment: (_window$Pelcro14 = window.Pelcro) === null || _window$Pelcro14 === void 0 ? void 0 : _window$Pelcro14.environment
20830
21091
  });
20831
21092
  });
20832
21093
  });
@@ -21160,7 +21421,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
21160
21421
  cardExpirationMonth: state === null || state === void 0 ? void 0 : state.month,
21161
21422
  cardExpirationYear: state === null || state === void 0 ? void 0 : state.year
21162
21423
  }, (err, orderResponse) => {
21163
- var _window$Pelcro14, _window$Pelcro14$user, _window$Pelcro14$user2;
21424
+ var _window$Pelcro15, _window$Pelcro15$user, _window$Pelcro15$user2;
21164
21425
  if (err) {
21165
21426
  toggleAuthenticationSuccessPendingView(false);
21166
21427
  dispatch({
@@ -21191,7 +21452,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
21191
21452
  });
21192
21453
  }
21193
21454
  window.Pelcro.user.refresh({
21194
- auth_token: (_window$Pelcro14 = window.Pelcro) === null || _window$Pelcro14 === void 0 ? void 0 : (_window$Pelcro14$user = _window$Pelcro14.user) === null || _window$Pelcro14$user === void 0 ? void 0 : (_window$Pelcro14$user2 = _window$Pelcro14$user.read()) === null || _window$Pelcro14$user2 === void 0 ? void 0 : _window$Pelcro14$user2.auth_token
21455
+ auth_token: (_window$Pelcro15 = window.Pelcro) === null || _window$Pelcro15 === void 0 ? void 0 : (_window$Pelcro15$user = _window$Pelcro15.user) === null || _window$Pelcro15$user === void 0 ? void 0 : (_window$Pelcro15$user2 = _window$Pelcro15$user.read()) === null || _window$Pelcro15$user2 === void 0 ? void 0 : _window$Pelcro15$user2.auth_token
21195
21456
  }, (err, res) => {
21196
21457
  dispatch({
21197
21458
  type: DISABLE_SUBMIT,
@@ -21253,11 +21514,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
21253
21514
  const createPaymentSource = (state, dispatch) => {
21254
21515
  return stripe.createSource({
21255
21516
  type: "card"
21256
- }).then(_ref10 => {
21517
+ }).then(_ref12 => {
21257
21518
  let {
21258
21519
  source,
21259
21520
  error
21260
- } = _ref10;
21521
+ } = _ref12;
21261
21522
  if (error) {
21262
21523
  return handlePaymentError(error);
21263
21524
  }
@@ -21371,11 +21632,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
21371
21632
  } = paymentMethodToDelete;
21372
21633
  return stripe.createSource({
21373
21634
  type: "card"
21374
- }).then(_ref11 => {
21635
+ }).then(_ref13 => {
21375
21636
  let {
21376
21637
  source,
21377
21638
  error
21378
- } = _ref11;
21639
+ } = _ref13;
21379
21640
  if (error) {
21380
21641
  return handlePaymentError(error);
21381
21642
  }
@@ -21519,12 +21780,12 @@ const PaymentMethodContainerWithoutStripe = _ref => {
21519
21780
  }
21520
21781
  stripe.createSource({
21521
21782
  type: "card"
21522
- }).then(_ref12 => {
21523
- var _ref13, _ref14, _state$updatedPrice2;
21783
+ }).then(_ref14 => {
21784
+ var _ref15, _ref16, _state$updatedPrice3;
21524
21785
  let {
21525
21786
  source,
21526
21787
  error
21527
- } = _ref12;
21788
+ } = _ref14;
21528
21789
  if (error) {
21529
21790
  return handlePaymentError(error);
21530
21791
  }
@@ -21543,7 +21804,7 @@ const PaymentMethodContainerWithoutStripe = _ref => {
21543
21804
  return total + item.price * item.quantity;
21544
21805
  }, 0);
21545
21806
  };
21546
- (_ref13 = (_ref14 = (_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 && _ref14 !== void 0 ? _ref14 : invoice === null || invoice === void 0 ? void 0 : invoice.amount_remaining) !== null && _ref13 !== void 0 ? _ref13 : getOrderItemsTotal();
21807
+ (_ref15 = (_ref16 = (_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 && _ref16 !== void 0 ? _ref16 : invoice === null || invoice === void 0 ? void 0 : invoice.amount_remaining) !== null && _ref15 !== void 0 ? _ref15 : getOrderItemsTotal();
21547
21808
  return handlePayment(source);
21548
21809
  }).catch(error => {
21549
21810
  return handlePaymentError(error);
@@ -21555,11 +21816,11 @@ const PaymentMethodContainerWithoutStripe = _ref => {
21555
21816
  * @return {Promise}
21556
21817
  */
21557
21818
  const resolveTaxCalculation = () => {
21558
- var _window$Pelcro$site$r10;
21819
+ var _window$Pelcro$site$r13;
21559
21820
  if (type === "invoicePayment") {
21560
21821
  return new Promise(resolve => resolve());
21561
21822
  }
21562
- const taxesEnabled = (_window$Pelcro$site$r10 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r10 === void 0 ? void 0 : _window$Pelcro$site$r10.taxes_enabled;
21823
+ const taxesEnabled = (_window$Pelcro$site$r13 = window.Pelcro.site.read()) === null || _window$Pelcro$site$r13 === void 0 ? void 0 : _window$Pelcro$site$r13.taxes_enabled;
21563
21824
  return new Promise((resolve, reject) => {
21564
21825
  // resolve early if taxes isn't enabled
21565
21826
  if (!taxesEnabled) {
@@ -21960,6 +22221,9 @@ const PaymentMethodContainerWithoutStripe = _ref => {
21960
22221
  return state;
21961
22222
  }
21962
22223
  }, initialState$l);
22224
+ React.useEffect(() => {
22225
+ initializeBraintree();
22226
+ }, [selectedPaymentMethodId, paymentMethodToEdit, state.updatedPrice]);
21963
22227
  return /*#__PURE__*/React__default['default'].createElement("div", {
21964
22228
  style: {
21965
22229
  ...style
@@ -22255,32 +22519,21 @@ const CheckoutForm = _ref => {
22255
22519
  }, "Expiration Year *"), /*#__PURE__*/React__default['default'].createElement("div", {
22256
22520
  id: "expiration-year",
22257
22521
  className: "pelcro-input-field plc-h-12 plc-bg-white"
22522
+ })), /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement("label", {
22523
+ htmlFor: "cvv"
22524
+ }, "CVV *"), /*#__PURE__*/React__default['default'].createElement("div", {
22525
+ id: "cvv",
22526
+ className: "pelcro-input-field plc-h-12 plc-bg-white"
22258
22527
  })))) : /*#__PURE__*/React__default['default'].createElement("div", {
22259
22528
  className: "plc-w-full plc-h-40 plc-bg-gray-300 plc-rounded plc-animate-pulse"
22260
22529
  }));
22261
22530
  }
22262
- return /*#__PURE__*/React__default['default'].createElement("div", null, isSkeletonLoaded ? /*#__PURE__*/React__default['default'].createElement("div", {
22531
+ return /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement("div", {
22263
22532
  className: "plc-max-w-[50em]"
22264
- }, /*#__PURE__*/React__default['default'].createElement("label", {
22265
- htmlFor: "card-number"
22266
- }, "Card Number *"), /*#__PURE__*/React__default['default'].createElement("div", {
22267
- id: "card-number",
22268
- className: "pelcro-input-field plc-h-12 plc-bg-white"
22269
- }), /*#__PURE__*/React__default['default'].createElement("div", {
22270
- className: "plc-flex plc-items-start plc-space-x-8 plc-my-6"
22271
- }, /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement("label", {
22272
- htmlFor: "expiration-date"
22273
- }, "Expiration Date *"), /*#__PURE__*/React__default['default'].createElement("div", {
22274
- id: "expiration-date",
22275
- className: "pelcro-input-field plc-h-12 plc-bg-white"
22276
- })), /*#__PURE__*/React__default['default'].createElement("div", null, /*#__PURE__*/React__default['default'].createElement("label", {
22277
- htmlFor: "cvv"
22278
- }, "CVC *"), /*#__PURE__*/React__default['default'].createElement("div", {
22279
- id: "cvv",
22280
- className: "pelcro-input-field plc-h-12 plc-bg-white"
22281
- })))) : /*#__PURE__*/React__default['default'].createElement("div", {
22282
- className: "plc-w-full plc-h-40 plc-bg-gray-300 plc-rounded plc-animate-pulse"
22283
- }));
22533
+ }, /*#__PURE__*/React__default['default'].createElement("div", {
22534
+ id: "dropin-container",
22535
+ className: "plc-w-full plc-min-h-[300px]"
22536
+ })));
22284
22537
  }
22285
22538
  if (cardProcessor === "stripe") {
22286
22539
  if (type === "updatePaymentSource") {
@@ -23511,7 +23764,7 @@ function PaymentMethodView(_ref) {
23511
23764
  label: t("labels.isDefault")
23512
23765
  }, props)), /*#__PURE__*/React__default['default'].createElement("div", {
23513
23766
  className: "plc-grid plc-mt-4 plc-gap-y-2"
23514
- }, /*#__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)))));
23767
+ }, /*#__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))))));
23515
23768
  }
23516
23769
 
23517
23770
  const SubscriptionRenewView = _ref => {