function initializeDropIn(payPalOptions, isMiniCartCheckout) {

  var submitButton = document.querySelector(CONST.DROP_IN_SUBMIT_BUTTON);
  var containerBillingAddress = document.getElementsByClassName("select-billing-address-container")[0];

  var container = CONST.DROP_IN_CONTAINER;

  var containerAddPayment = document.getElementsByClassName(CONST.DROP_IN_ADD_PAYMENT_CONTAINER)[0];
  var spinner = document.getElementsByClassName(CONST.WAIT_SPINNER)[0];

  var targetMiniCart = document.getElementsByClassName(CONST.MINI_CART_BODY);
  var targetAddToCart = document.getElementsByClassName(CONST.ADD_TO_CART);
  var cardValue = false;
  var payPalValue = false;
  var payPalCreditValue = false;
  var venmoValue = false;
  var googlePayValue = false;
  var applePayValue = false;
  var threeDSecureValue = false;
  var translationsValue = false;
  var vaultManager = true;
  var customerCanceled3ds = false;

  if (typeof dropInIsLimitedDeletePaymentMethod != 'undefined'
    && dropInIsLimitedDeletePaymentMethod) {
    vaultManager = false;
  }

  var cardOptions = {
    cardholderName: {
      required: true
    },
    vault: {
      vaultCard: false,
      allowVaultCardOverride: false
    }
  };

  var googlePayOptions = {
    googlePayVersion: 2,
    transactionInfo: {
      countryCode: googlePayCountryCode,
      currencyCode: currency,
      totalPriceStatus: 'FINAL'
    },
    emailRequired: true,
    allowedPaymentMethods: [{
      type: 'CARD',
      parameters: {
        billingAddressRequired: true,
        billingAddressParameters: {
          format: 'FULL',
          phoneNumberRequired: true
        }
      }
    }]
  };

  var applePayOptions = {
    displayName: 'Electronics',
    paymentRequest: {
      total: {
        label: payPalOptions.flow,
        amount: amount
      }
    }
  };

  var venmoOptions = {
    ignoreHistoryChanges: true,
    allowDesktop: true
  };

  var threeDSecureOptions = {
    cardinalSDKConfig: {
      version: 2
    }
  };

  if (is3DSecureEnabled()) {
    threeDSecureValue = threeDSecureOptions;
  }

  if ((typeof googleMerchantId != 'undefined') && (googleMerchantId !== '')) {
    googlePayOptions.merchantId = googleMerchantId;
  }

  if (((typeof addPaymentMethodsPage != 'undefined') && (typeof isMiniCartCheckout == 'undefined')) || (typeof accountPaymentInfoPage != 'undefined')) {
    if (payPalStandardEnabled) {
      payPalValue = Object.assign({}, payPalOptions);
      payPalValue.buttonStyle = payPalButtonConfig;
    }
    if (hostedFieldsEnabled) {
      cardValue = cardOptions
    }
    translationsValue = {
      payingWith: ACC.addons.braintreeaddon['braintree.message.dropin.paying.with'],
      chooseAWayToPay: ACC.addons.braintreeaddon['braintree.message.dropin.choose.way.to.pay'],
      chooseAnotherWayToPay: ACC.addons.braintreeaddon['braintree.message.dropin.choose.another.way.to.pay'],
      payWithCard: ACC.addons.braintreeaddon['braintree.message.dropin.pay.with.card']
    };
    payPalCreditValue = false;
    venmoValue = false;
    googlePayValue = false;
    applePayValue = false;
    threeDSecureValue = false;
  }

  if (is3DSecureOnMyAccountPage()) {
    threeDSecureValue = true;
  }

  if (typeof paymentMethodsPage != 'undefined') {
    if (payPalStandardEnabled) {
      payPalValue = Object.assign({}, payPalOptions);
      payPalValue.buttonStyle = payPalButtonConfig;

      if (creditEnabled) {
        if (typeof cartPopup == 'undefined') {
          payPalCreditValue = payPalOptions;
        }
      }
    }
    if (hostedFieldsEnabled) {
      cardValue = cardOptions
    }
    if (venmoEnabled) {
      venmoValue = venmoOptions;
    }
    if (googlePayEnabled) {
      googlePayOptions.transactionInfo.totalPrice = amount;
      googlePayOptions.button = mapStylesProperties(googlePayBillingDropInConfig);
      googlePayValue = googlePayOptions;
    }
    if (applePayEnabled) {
      applePayOptions.paymentRequest.requiredShippingContactFields = ['email'];
      applePayOptions.paymentRequest.requiredBillingContactFields = ['postalAddress',
        'name'];
      applePayOptions.buttonStyle = applePayBillingDropInColorConfig;
      applePayValue = applePayOptions;
    }
  }

  if (typeof shoppingCart != 'undefined' && shoppingCart !== '') {
    cardValue = false;
    if (payPalExpressEnabled) {
      payPalValue = Object.assign({}, payPalOptions);
      payPalValue.buttonStyle = payPalButtonConfig;

      if (creditEnabled) {
        if (typeof cartPage == 'undefined' && typeof cartPopup == 'undefined' && typeof addToCartPopup == 'undefined') {
            payPalCreditValue = payPalOptions;
        }
      }
    }
    if (googlePayEnabled && googlePayOnExpressCheckoutEnabled) {
      googlePayOptions.transactionInfo.totalPrice = amount;
      googlePayOptions.shippingAddressRequired = true;
      googlePayOptions.button = mapStylesProperties(googlePayCartDropInConfig);
      googlePayValue = googlePayOptions;
    }
    if (applePayEnabled && applePayOnExpressCheckoutEnabled) {
      applePayOptions.paymentRequest.requiredShippingContactFields = ['postalAddress',
        'name', 'phone', 'email'];
      applePayOptions.paymentRequest.requiredBillingContactFields = ['postalAddress',
        'name'];
      applePayOptions.buttonStyle = applePayCartDropInColorConfig;
      applePayValue = applePayOptions;
    }
  }

  if (targetMiniCart.length > 0 || targetAddToCart.length > 0) {
    container = CONST.DROP_IN_MINI_CART_CONTAINER;
    cardValue = false;
    venmoValue = false;
    translationsValue = false;

    if (payPalExpressEnabled) {
      payPalValue = Object.assign({}, payPalOptions);
      payPalValue.buttonStyle = payPalButtonConfig;

      if (creditEnabled) {
        if (typeof cartPage == 'undefined' && typeof cartPopup == 'undefined' && typeof addToCartPopup == 'undefined') {
            payPalCreditValue = payPalOptions;
        }
      }
    }
    if (!payPalExpressEnabled) {
      payPalValue = false;
    }
    if (googlePayEnabled && googlePayOnExpressCheckoutEnabled) {
      googlePayOptions.transactionInfo.totalPrice = amount;
      googlePayOptions.shippingAddressRequired = true;
      googlePayOptions.button = mapStylesProperties(googlePayMiniCartDropInConfig);
      googlePayValue = googlePayOptions;
    }
    if (applePayEnabled && applePayOnExpressCheckoutEnabled) {
      applePayOptions.paymentRequest.requiredShippingContactFields = ['postalAddress',
        'name', 'phone', 'email'];
      applePayOptions.paymentRequest.requiredBillingContactFields = ['postalAddress',
        'name'];
      applePayOptions.buttonStyle = applePayMiniCartDropInColorConfig;
      applePayValue = applePayOptions;
    }
  }

  braintree.dropin.create({
    authorization: clientToken,
    container: container,
    locale: braintreeLocale,
    dataCollector: true,
    vaultManager: vaultManager,
    threeDSecure: threeDSecureValue,
    card: cardValue,
    paypal: payPalValue,
    paypalCredit: payPalCreditValue,
    venmo: venmoValue,
    googlePay: googlePayValue,
    applePay: applePayValue,
    translations: translationsValue

  }, function (err, dropinInstance) {
    if (err) {
      showCustomAbsoluteErrorMessage(err.message);
      submitButton.classList.add('hidden');
      containerBillingAddress.classList.add('hidden');
      return;
    }

    if (typeof accountPaymentInfoPage != 'undefined') {
      changeViewOnMyAccountPage(dropinInstance);

      if (typeof dropInIsLimitedDeletePaymentMethod != 'undefined'
          && dropInIsLimitedDeletePaymentMethod
          && dropinInstance._model._paymentMethods.length > 0) {

        const warningMessage = ACC.addons.braintreeaddon['braintree.message.dropin.myaccount.text.limited.delete.payment.methods'];
        showWarningMessage(warningMessage);
      }
    }
    if ((typeof addPaymentMethodsPage != 'undefined') && (typeof isMiniCartCheckout == 'undefined')) {
      changeViewOnAddPaymentPage(dropinInstance);
    }
    if (typeof paymentMethodsPage != 'undefined') {
      changeViewOnBillingPage(dropinInstance);
    }
    if (typeof shoppingCart != 'undefined' || typeof shoppingMiniCart != 'undefined') {
      changeViewOnExpressCheckout(dropinInstance, isMiniCartCheckout);
      return;
    }

    if (is3DSecureOnMyAccountPage()) {
      showErrorMessageForCanceled3ds();
        submitButton.addEventListener('click', function () {
            performDropIn(dropinInstance, spinner, containerAddPayment, containerBillingAddress,
                                                            isMiniCartCheckout, prepareAddressData());
        });
    } else if (is3DSecureEnabled()
        && (typeof addPaymentMethodsPage == 'undefined') && (typeof accountPaymentInfoPage == 'undefined')) {
      showErrorMessageForCanceled3ds();
      submitButton.addEventListener('click', function () {
        var additionalInfoUrl = ACC.config.encodedContextPath + '/braintree/checkout/hop/getAdditionalInfo';
        $.get(additionalInfoUrl).then((additionalInformation) => performDropIn(dropinInstance, spinner,
            containerAddPayment, containerBillingAddress, isMiniCartCheckout, additionalInformation));
      });
    } else {
      submitButton.addEventListener('click', function () {
        if (typeof addPaymentMethodsPage != 'undefined' && document.getElementById('selected-address').children.length === 0) {
          deleteFieldErrorMessages();
        }
        requestPaymentMethodThroughDropIn(dropinInstance, isMiniCartCheckout, spinner, containerAddPayment);
      });
    }

    dropinInstance.on('3ds:customer-canceled', function () {
      this.customerCanceled3ds = true;
    });

    if (dropinInstance._model !== undefined && dropinInstance._model._events !== undefined
        && typeof showWarningMessageAboutReplenishmentDropIn != 'undefined'
        && showWarningMessageAboutReplenishmentDropIn) {
      const defaultEnableEdit = dropinInstance._model._events.enableEditMode[0];
      dropinInstance._model._events.enableEditMode[0] = function () {
        showCustomAbsoluteErrorMessage(ACC.addons.braintreeaddon['braintree.message.has.active.replenishment.dropin']);
        defaultEnableEdit();
      };
    }

  });
}

function requestPaymentMethodThroughDropIn(dropinInstance, isMiniCartCheckout, spinner, containerAddPayment) {
  dropinInstance.requestPaymentMethod(function (err, payload) {
    if (err) {
      if (err.message === 'No payment method is available.') {
        err.message = ACC.addons.braintreeaddon['braintree.message.invalid.card'];
      }
      showCustomAbsoluteErrorMessage(err.message);
      return;
    }
    if ((typeof addPaymentMethodsPage != 'undefined') && (typeof isMiniCartCheckout == 'undefined')) {
      spinner.classList.remove('hidden');
      containerAddPayment.classList.add('hidden');
    }
    processDropInResponse(dropinInstance, payload, payload.deviceData, isMiniCartCheckout);
  });
}


  function performDropIn(dropinInstance, spinner, containerAddPayment, containerBillingAddress, isMiniCartCheckout, address) {
    var threeDSecureData;
    if (typeof addPaymentMethodsPage != 'undefined') {
        threeDSecureData = get3DSVerificationDataDropInForMyAccountPage(address);
    }else{
        threeDSecureData = get3DSVerificationDataDropIn(address);
    }
    dropinInstance.requestPaymentMethod({
        threeDSecure: threeDSecureData
    }, function (err, payload) {
        if (err) {
            process3dsAuthenticationFail(dropinInstance, isMiniCartCheckout);
        }
        if ((typeof addPaymentMethodsPage != 'undefined') && (typeof isMiniCartCheckout == 'undefined')) {
            spinner.classList.remove('hidden');
            containerAddPayment.classList.add('hidden');
        }
        if (!this.customerCanceled3ds) {
            processDropInResponse(dropinInstance, payload, payload.deviceData, isMiniCartCheckout);
        } else {
            process3dsAuthenticationFail(dropinInstance, isMiniCartCheckout);
        }
    });
}

function getBillingAddressFor3DSDropIn() {
  var billingAddress = {};

  var givenName = document.getElementById('address.firstName');
  var surname = document.getElementById('address.surname');
  var phoneNumber = document.getElementById('address.phone');
  var streetAddress = document.getElementById('address.line1');
  var extendedAddress = document.getElementById('address.line2');
  var locality = document.getElementById('address.townCity');
  var region = document.getElementById('address.region');
  var postalCode = document.getElementById('address.postcode');
  var countryCodeAlpha2 = document.getElementById('address.country');

  if (givenName !== null) {
    billingAddress.givenName = givenName.value;
  }
  if (surname !== null) {
    billingAddress.surname = surname.value;
  }
  if (phoneNumber !== null) {
    billingAddress.phoneNumber = phoneNumber.value;
  }
  if (streetAddress !== null) {
    billingAddress.streetAddress = streetAddress.value;
  }
  if (extendedAddress !== null) {
    billingAddress.extendedAddress = extendedAddress.value;
  }
  if (locality !== null) {
    billingAddress.locality = locality.value;
  }
  if (region !== null) {
    billingAddress.region = region.value;
  }
  if (postalCode !== null) {
    billingAddress.postalCode = postalCode.value;
  }
  if (countryCodeAlpha2 !== null) {
    billingAddress.countryCodeAlpha2 = countryCodeAlpha2.value;
  }

  return billingAddress;
}

function get3DSVerificationDataDropInForMyAccountPage(address) {
  return {
    amount: amount
  };
}

function get3DSVerificationDataDropIn(additionalInformation) {
  var data = {
    amount: amount,
    billingAddress: getBillingAddressFor3DSDropIn(),
  }

  if (additionalInformation !== null) {
    data.email = additionalInformation.email;
    data.additionalInformation = {
      workPhoneNumber: additionalInformation.phone,
      shippingGivenName: additionalInformation.firstName,
      shippingSurname: additionalInformation.lastName,
      shippingPhone: additionalInformation.phone,
      shippingAddress: {
        streetAddress: additionalInformation.line1,
        extendedAddress: additionalInformation.line2,
        locality: additionalInformation.town,
        postalCode: additionalInformation.postalCode,
        countryCodeAlpha2: additionalInformation.country.isocode
      },
      acsWindowSize: '05'
    }
    if (additionalInformation.region !== null) {
      data.additionalInformation.shippingAddress.region = additionalInformation.region.isocodeShort;
    }
  }

  return data;
}

function processDropInResponse(dropinInstance, payload, deviceData, isMiniCartCheckout) {
  if(payload.type === 'CreditCard'){
      if ((threeDSecureFlow !== CONST.DISABLED && typeof accountPaymentInfoPage == 'undefined')) {
        if (payload.liabilityShifted || !payload.liabilityShiftPossible) {
          processResponse(payload, deviceData);
        } else {
          process3dsAuthenticationFail(dropinInstance, isMiniCartCheckout);
        }
      } else {
        if (typeof addPaymentMethodsPage != 'undefined') {
          const shouldSaveAddress = $(CONST.SAVE_ADDRESS_CHECKBOX_DROP_IN).is(HTML.CHECKED);
          $('#' + CONST.BRAINTREE_PAYMENT_FORM_ID).append(createHiddenParameter('shouldSaveAddress', shouldSaveAddress));
        }
        processResponse(payload, deviceData);
      }
    }

    if (payload.type === "AndroidPayCard") {
      var payloadCopy = convertGoogleDataToPayloadObject(
        payload,
        payload.details.rawPaymentData
      );
      if (is3DSecureEnabled()) {
        if (payload.liabilityShifted || !payload.liabilityShiftPossible) {
          processExpressCheckoutForm(payloadCopy, false, deviceData,isMiniCartCheckout);
        } else {
          process3dsAuthenticationFail(dropinInstance, isMiniCartCheckout);
        }
      } else {
        processExpressCheckoutForm(payloadCopy, false, deviceData, isMiniCartCheckout);
      }
    }

  if (payload.type === 'PayPalAccount') {
    if (storeInVault === false) {
      processExpressCheckoutForm(payload, false, deviceData, isMiniCartCheckout);
    } else {
      processExpressCheckoutForm(payload,
        typeof payPalShouldBeSaved !== "undefined" ? payPalShouldBeSaved : false, deviceData, isMiniCartCheckout);
    }
  }

  if (payload.type === 'VenmoAccount') {
    processVenmoResponse(payload, false, deviceData);
  }

  if (payload.type === 'ApplePayCard') {
    processExpressCheckoutForm(prepareApplePayPayload(payload), false, deviceData, isMiniCartCheckout)
  }

}

function prepareApplePayPayload(payload) {
  var payloadCopy = {};
  var shippingContact = payload.details.rawPaymentData.shippingContact;
  var billingContact = payload.details.rawPaymentData.billingContact;

  payloadCopy.nonce = payload.nonce;
  payloadCopy.details = {};
  payloadCopy.cardDetails = {};
  payloadCopy.type = payload.type;
  payloadCopy.details.email = shippingContact.emailAddress;
  payloadCopy.details.cardType = payload.details.cardType;
  payloadCopy.cardDetails.cardType = payload.details.cardType;
  payloadCopy.details.firstName = shippingContact.givenName;
  payloadCopy.details.lastName = shippingContact.familyName;
  payloadCopy.details.phone = shippingContact.phoneNumber;
  payloadCopy.details.billingAddress = {
    line1: billingContact.addressLines[0],
    line2: billingContact.addressLines[1],
    city: billingContact.locality,
    state: billingContact.administrativeArea.toUpperCase(),
    postalCode: billingContact.postalCode,
    countryCode: billingContact.countryCode.toUpperCase()
  };

  if (typeof paymentMethodsPage == 'undefined') {
    payloadCopy.details.shippingAddress = {
      line1: shippingContact.addressLines[0],
      line2: shippingContact.addressLines[1],
      city: shippingContact.locality,
      state: shippingContact.administrativeArea.toUpperCase(),
      postalCode: shippingContact.postalCode,
      countryCode: shippingContact.countryCode.toUpperCase()
    };
  }

  return payloadCopy;
}

function mapStylesProperties(stylesToMap) {
             const mappedStyles = {
               buttonSizeMode: stylesToMap.size,
               buttonType: stylesToMap.type
             }
             return mappedStyles;
           }

function changeViewOnMyAccountPage(dropinInstance) {
  var containerMyAccount = document.getElementsByClassName(CONST.DROP_IN_MY_ACCOUNT_CONTAINER)[0];
  var containerMessage = document.getElementsByClassName(CONST.NO_SAVED_PAYMENT_METHODS_MESSAGE)[0];

  if (dropinInstance._model._paymentMethods.length > 0) {
    containerMyAccount.classList.remove('hidden');
  } else {
    containerMessage.classList.remove('hidden');
  }
  dropinInstance.on('changeActiveView', function () {
    if (dropinInstance._model._paymentMethods.length === 0) {
      containerMyAccount.classList.add('hidden');
      containerMessage.classList.remove('hidden');
    }
  });
}

function changeViewOnAddPaymentPage(dropinInstance) {
  var submitButtonAddPayment = document.getElementsByClassName(CONST.DROP_IN_SUBMIT_BUTTON_ADD_PAYMENT)[0];
  var containerBillingAddress = document.getElementsByClassName("select-billing-address-container")[0];
  var containerAddPayment = document.getElementsByClassName(CONST.DROP_IN_ADD_PAYMENT_CONTAINER)[0];
  var spinner = document.getElementsByClassName(CONST.WAIT_SPINNER)[0];

  dropinInstance.on('changeActiveView', function (event) {
    if (event.newViewId === 'methods') {
      if (dropinInstance._model._activePaymentMethod != null && event.previousViewId === 'paypal') {
        spinner.classList.remove('hidden');
        containerAddPayment.classList.add('hidden');

        dropinInstance.requestPaymentMethod(function (err, payload) {
          processExpressCheckoutForm(payload, false);
        });
      }
      changeCorrectView(dropinInstance);
    }
    if (event.newViewId === 'card') {
      submitButtonAddPayment.classList.remove('hidden');
    } else {
      submitButtonAddPayment.classList.add('hidden');
      containerBillingAddress.classList.add('hidden');
    }
  });
  dropinInstance.clearSelectedPaymentMethod();
  changeCorrectView(dropinInstance);
  spinner.classList.add('hidden');
  containerAddPayment.classList.remove('hidden');
}

function changeViewOnBillingPage(dropinInstance) {
  var billingAddressData = document.getElementsByClassName(CONST.BILLING_ADDRESS_DATA_CONTAINER)[0];
  if (dropinInstance._model._activePaymentViewId === 'methods' && dropinInstance._model._activePaymentMethod.type === 'CreditCard') {
    billingAddressData.classList.remove('hidden');
  } else {
    billingAddressData.classList.add('hidden');
  }
  dropinInstance.on('changeActiveView', function (event) {
    const activePaymentMethod = dropinInstance._model._activePaymentMethod;
    if ((dropinInstance._model._activePaymentViewId === 'methods'
        && activePaymentMethod !== undefined && activePaymentMethod.type === 'CreditCard'
        && !dropinInstance._model._isInEditMode)
        || (event.newViewId === 'card')) {
      billingAddressData.classList.remove('hidden');
    } else {
      billingAddressData.classList.add('hidden');
    }
  });
  dropinInstance.on('paymentMethodRequestable', function () {
    var activePaymentMethod = dropinInstance._model._activePaymentMethod;
    if (dropinInstance._model._activePaymentViewId === 'card'
        || (activePaymentMethod !== undefined && activePaymentMethod.type === 'CreditCard')) {
      billingAddressData.classList.remove('hidden');
    }
  });
}

function changeViewOnExpressCheckout(dropinInstance, isMiniCartCheckout) {
  var containerExpressCheckout = Array.from(document.getElementsByClassName(CONST.DROP_IN_CONTAINER_EXPRESS_CHECKOUT));
  dropinInstance.on('changeActiveView', function (event) {
    if (event.newViewId === 'methods') {
      if (dropinInstance._model._activePaymentMethod != null
          && (event.previousViewId === 'paypal'
          || event.previousViewId === 'paypalCredit'
          || event.previousViewId === 'googlePay'
          || event.previousViewId === 'applePay')) {
        dropinInstance.requestPaymentMethod(function (err, payload) {
          if (payload.type === 'AndroidPayCard') {
            var payloadCopy = convertGoogleDataToPayloadObject(
              payload,
              payload.details.rawPaymentData
            );
            if (threeDSecureFlow !== CONST.DISABLED) {
              ACC.threeDSecure.verifyGooglePayBy3DSecureOnExpressCheckout(
                payload,
                payload.details.rawPaymentData,
                false
              );
            } else {
              processExpressCheckoutForm(
                payloadCopy,
                false,
                deviceData,
                isMiniCartCheckout
              );
            }
          } else if (payload.type === 'PayPalAccount') {
            processExpressCheckoutForm(payload, typeof payPalShouldBeSaved !== "undefined" ? payPalShouldBeSaved : false, deviceData, isMiniCartCheckout);
          } else if (payload.type === 'ApplePayCard') {
            processExpressCheckoutForm(prepareApplePayPayload(payload), false, deviceData, isMiniCartCheckout)
          }
        });
      }
      changeCorrectView(dropinInstance);
      containerExpressCheckout.forEach((container) => container.classList.remove('hidden'));
    }
  });
  dropinInstance.clearSelectedPaymentMethod();
  changeCorrectView(dropinInstance);
  containerExpressCheckout.forEach((container) => container.classList.remove('hidden'));
}

function changeCorrectView(dropInInstance) {
  if (dropInInstance._model.supportedPaymentOptions.length > 1) {
    dropInInstance._mainView.setPrimaryView('options', undefined);
  } else {
    dropInInstance._mainView.setPrimaryView(dropInInstance._model.supportedPaymentOptions[0], undefined);
  }
}

function is3DSecureEnabled() {
  return typeof pageType !== 'undefined' && pageType === 'billing' && threeDSecureFlow !== CONST.DISABLED;
}

function is3DSecureOnMyAccountPage() {
    return typeof addPaymentMethodsPage !== 'undefined' && threeDSecureFlow !== CONST.DISABLED;
}

function process3dsAuthenticationFail(dropInInstance, isMiniCartCheckout) {

  const currentURL = window.location.href;
  let unSecuredCard = getValueFromUrlByKey(currentURL, 'unSecuredCard');
  if (unSecuredCard != null) {
    window.location.href = currentURL;
  } else {
    if ((typeof addPaymentMethodsPage != 'undefined') && (typeof isMiniCartCheckout == 'undefined')) {
      window.location.href = currentURL + '?unSecuredCard=true';
    }
    if (typeof paymentMethodsPage != 'undefined') {
      dropInInstance.clearSelectedPaymentMethod();
      window.location.href = currentURL + '?unSecuredCard=true';
    }
  }
}

function getValueFromUrlByKey(url, key) {
  let currentUrl = new URL(url);
  return currentUrl.searchParams.get(key);
}

function showErrorMessageForCanceled3ds() {
  let unSecuredCard = getValueFromUrlByKey(window.location.href, 'unSecuredCard');
  if (unSecuredCard != null && unSecuredCard === 'true') {
    showErrorMessage(ACC.addons.braintreeaddon['braintree.message.unsecured.card']);
  }
}
