{"version":3,"file":"registration-otp.min.js","sources":["registration-otp.min.js"],"sourcesContent":["/******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId])\n/******/ \t\t\treturn installedModules[moduleId].exports;\n\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\texports: {},\n/******/ \t\t\tid: moduleId,\n/******/ \t\t\tloaded: false\n/******/ \t\t};\n\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.loaded = true;\n\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n\n\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"\";\n\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(0);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ (function(module, exports) {\n\n\t/* eslint-disable no-native-reassign */\n\t'use strict';\n\n\tvar $otpButton,\n\t fraudDetected,\n\t otpTriggerInterval,\n\t securityEnabled,\n\t lastPhoneEntered,\n\t isTimeoutStarted = false;\n\t/**\n\t * @description shows the error message below the otp button\n\t * @param {String} [message] The error message to display, if not provided, the default one will be displayed\n\t */\n\tfunction showotpErrorMessage(message) {\n\t var messageToDisplay = message || $otpButton.data('otp-interval-message');\n\t $otpButton.closest('.cc-form-group').find('.cc-text-message').text(messageToDisplay);\n\t $otpButton.closest('.cc-form-group').addClass('is-invalid');\n\t}\n\n\t// in this way, the variables values cannot change during time after the user edits the DOM\n\t$(document).ready(function () {\n\t $otpButton = $('#registration-send-otp');\n\t fraudDetected = $otpButton.data('fraud-detected');\n\t otpTriggerInterval = $otpButton.data('otp-interval');\n\t securityEnabled = $otpButton.data('security-enabled') === 'true';\n\t});\n\n\t/**\n\t * Phone verification and OTP send\n\t */\n\t$('#registration-send-otp').on('click', function () {\n\t if (!fraudDetected || !securityEnabled) {\n\t var $phoneField = $('#registration-form-phone');\n\t if ($otpButton.hasClass('cc-disabled')) {\n\t if (!$otpButton.closest('.cc-form-group').hasClass('is-invalid')) {\n\t if ($phoneField.closest('.cc-phone-input-box').hasClass('is-valid')) {\n\t // display the default error message only if the phone number is valid and there is not yet another error message displayed under the otp button\n\t showotpErrorMessage();\n\t } else if (!$phoneField.closest('.cc-phone-input-box').hasClass('is-invalid')) {\n\t // in this case, the phone field is neither valid or invalid, it means the user never inserted a phone number yet\n\t // trigger the phone number validation, in this way it's more clear to the user what they have to do in order to send the OTP\n\t $phoneField.trigger('blur');\n\t }\n\t }\n\t } else {\n\t // no error on phone level -> send the otp\n\t //clear error\n\t $phoneField.removeClass('is-invalid');\n\t var url = $otpButton.attr('actionurl'),\n\t data = {\n\t phoneNumber: $phoneField.val(),\n\t isCheckout: false\n\t };\n\t $.spinner().start();\n\t $.ajax({\n\t url: url,\n\t type: 'POST',\n\t dataType: 'json',\n\t data: data,\n\t success: function success(data) {\n\t // adding the class and not directly the prop disabled, since we want to warn the users if they clicks again the button while disabled\n\t $('body').trigger('otp:invalidPhone');\n\t if (data.success) {\n\t $.spinner().stop();\n\t $('#OTPValidation-phoneNumber').val(data.phoneNumber);\n\t $phoneField.removeClass('custom-error');\n\t isTimeoutStarted = true;\n\t lastPhoneEntered = $phoneField.val();\n\t setTimeout(function () {\n\t if (isTimeoutStarted && lastPhoneEntered === $phoneField.val()) {\n\t $('body').trigger('otp:validPhone');\n\t }\n\t }, otpTriggerInterval);\n\t } else if (data.otpErrorDetected) {\n\t showotpErrorMessage(data.error[0]);\n\t $.spinner().stop();\n\t } else {\n\t $('#form-phone-message').hide();\n\t $phoneField.parents('.cc-form-group').find('.cc-text-message').text(data.error);\n\t $phoneField.closest('.cc-content-input').removeClass('is-valid');\n\t $phoneField.addClass('is-invalid custom-error');\n\t $phoneField.closest('.cc-phone-input-box').removeClass('is-valid');\n\t $phoneField.closest('.cc-phone-input-box').addClass('is-invalid custom-error');\n\t $.spinner().stop();\n\t }\n\t },\n\t error: function error() {\n\t $.spinner().stop();\n\t }\n\t });\n\t }\n\t }\n\t});\n\n\t// enable the otp button (e.g. after a phone is successfully validated, after the trigger interval expired)\n\t$('body').on('otp:validPhone', function () {\n\t $otpButton.removeClass('cc-disabled');\n\t $otpButton.closest('.cc-form-group').removeClass('is-invalid');\n\t isTimeoutStarted = false;\n\t});\n\n\t// disable the otp button (e.g. the phone isn't valid, the user has just sent the otp, etc.)\n\t$('body').on('otp:invalidPhone', function () {\n\t $otpButton.addClass('cc-disabled');\n\t $otpButton.closest('.cc-form-group').removeClass('is-invalid');\n\t isTimeoutStarted = false;\n\t});\n\n/***/ })\n/******/ ]);"],"names":["modules","installedModules","__webpack_require__","moduleId","module","exports","id","loaded","call","m","c","p","$otpButton","fraudDetected","otpTriggerInterval","securityEnabled","lastPhoneEntered","isTimeoutStarted","showotpErrorMessage","message","messageToDisplay","data","closest","find","text","addClass","$","document","ready","on","$phoneField","url","hasClass","trigger","removeClass","attr","phoneNumber","val","isCheckout","spinner","start","ajax","type","dataType","success","stop","setTimeout","otpErrorDetected","error","hide","parents"],"mappings":"AAAS,CAAA,SAAUA,GAET,IAAIC,EAAmB,GAGvB,SAASC,EAAoBC,GAG5B,IAIIC,EAJJ,OAAGH,EAAiBE,KAIhBC,EAASH,EAAiBE,GAAY,CACzCE,QAAS,GACTC,GAAIH,EACJI,OAAQ,CAAA,CACT,EAGAP,EAAQG,GAAUK,KAAKJ,EAAOC,QAASD,EAAQA,EAAOC,QAASH,CAAmB,EAGlFE,EAAOG,OAAS,CAAA,EAGTH,IAhB4BC,OAiBpC,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