/*
 * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
 * This devtool is neither made for production nor for readable output files.
 * It uses "eval()" calls to create a separate source file in the browser devtools.
 * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
 * or disable the default devtool with "devtool: false".
 * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
 */
/******/ (() => { // webpackBootstrap
/******/ 	var __webpack_modules__ = ({

/***/ "./modules/mangopay/assets/src/js/checkout.js":
/*!****************************************************!*\
  !*** ./modules/mangopay/assets/src/js/checkout.js ***!
  \****************************************************/
/***/ (() => {

eval(";\n\n(function ($) {\n  var dokanMangopayCheckout = {\n    init: function init() {\n      this.threeDs2.init();\n      this.payOptions.init();\n    },\n    threeDs2: {\n      init: function init() {\n        $('#dokan-mangopay-3ds2-js').val('yes');\n        $('#dokan-mangopay-3ds2-lang').val(navigator.language);\n        $('#dokan-mangopay-3ds2-color-depth').val(window.screen.colorDepth);\n        $('#dokan-mangopay-3ds2-screen-height').val(screen.height);\n        $('#dokan-mangopay-3ds2-screen-width').val(screen.width);\n        $('#dokan-mangopay-3ds2-timezone-offset').val(new Date().getTimezoneOffset().toString());\n        $('#dokan-mangopay-3ds2-user-agent').val(navigator.userAgent);\n\n        if (navigator.javaEnabled == true) {\n          $('#dokan-mangopay-3ds2-java').val('yes');\n        } else {\n          $('#dokan-mangopay-3ds2-java').val('no');\n        }\n      }\n    },\n    payOptions: {\n      init: function init() {\n        var self = this;\n        $('#dokan-mangopay-card-type').on('change click', function (e) {\n          $('.dokan-mangopay-payment-type.card').attr('checked', 'checked');\n        });\n        $('#dokan-mangopay-directdw-type').on('change click', function (e) {\n          $('.dokan-mangopay-payment-type-directdebitweb').attr('checked', 'checked');\n        });\n        $('#dokan-mp-add-card').hide();\n        $('#dokan-mp-card-registration-fields').hide();\n        /** When option is chosen open/close block **/\n\n        $(document).on('change', 'input[name=\"dokan_mangopay_payment_type\"]', function () {\n          $('#dokan-mp-card-registration-fields').hide();\n          $('#dokan-mp-saved-cards-list').hide();\n        });\n        $(document).on(\"click\", \"#dokan-mp-add-card\", function () {\n          $(\"#dokan-mp-card-registration-fields\").toggle();\n          $('#dokan-mp-add-card').hide();\n        });\n        $(document).on(\"click\", \"#cancel_addcard\", function () {\n          $(\"#dokan-mp-card-registration-fields\").hide();\n          $('#dokan-mp-add-card').show();\n        });\n        $(document).on('change', ':radio', function () {\n          if (!$('#dokan-mangopay-payment-type-registeredcard').is(':checked')) {\n            $('#dokan-mp-add-card').hide();\n          }\n        });\n        $(document).on('change', '#dokan-mangopay-payment-type-registeredcard:checked', self.cards.get);\n        $(document).on('click', '#dokan-mp-cancel-card', self.cards.cancel);\n        $(document).on('click', '#save_preauth_card_button', self.cards.save);\n      },\n      cards: {\n        get: function get() {\n          $('#dokan-mp-card-save-processing').show();\n          $('#dokan-mp-saved-cards-list').show();\n          dokanMangopayCheckout.payOptions.cards.list();\n        },\n        cancel: function cancel(e) {\n          e.preventDefault();\n          $('#dokan-mp-card-save-error').html('').hide();\n          var cardId = $(this).data('cardid');\n          var data = {\n            action: 'dokan_mangopay_deactivate_card',\n            card_id: cardId,\n            _wpnonce: dokanMangopay.nonce\n          };\n          $.post(dokanMangopay.ajaxurl, data, function (response) {\n            if (response.success) {\n              /** Remove line **/\n              $('#dokan-mp-saved-card-line-' + cardId).remove();\n            } else {\n              $('#dokan-mp-card-save-error').html(response.data).show();\n            }\n          });\n        },\n        save: function save() {\n          /** Reset error messages **/\n          $('#dokan-mp-card-save-error').html('').hide();\n          var userId = $('#user_id').val();\n\n          if (userId != undefined || userId != 0 || userId != '') {\n            selectedCardType = $('#registered_card_type').val();\n            /** Data for FIRST step **/\n\n            var data = {\n              action: 'dokan_mangopay_register_card',\n              user_id: userId,\n              order_currency: $('#order_currency').val(),\n              card_type: selectedCardType,\n              _wpnonce: dokanMangopay.nonce\n            };\n            var clientId = $('#dokan-mp-client-id').val();\n            var date_month = $('#preauth_ccdate_month').val();\n            var date_year = $('#preauth_ccdate_year').val();\n\n            if (date_month.length == 1) {\n              date_month = '0' + date_month;\n            }\n\n            var date = date_month + '' + date_year;\n            /** data for SECOND STEP **/\n\n            var cardData = {\n              cardNumber: $('#dokan-mp-ccnumber').val(),\n              cardExpirationDate: date,\n              cardCvx: $('#dokan-mp-cccrypto').val(),\n              cardType: selectedCardType\n            };\n\n            if (!selectedCardType || !date_month || !date_year || !cardData.cardNumber || !cardData.cardCvx) {\n              $('#dokan-mp-card-registration-fields').show();\n              $('#dokan-mp-card-save-error').html(dokanMangopay.emptyFields);\n              $('#dokan-mp-card-save-error').show();\n              return;\n            }\n            /** Hide the form and show the waiting message **/\n\n\n            $('#dokan-mp-card-registration-fields').hide();\n            $('#dokan-mp-card-save-processing').show();\n            /** FIRSdokan-mp-saved-cards-listl **/\n\n            $.post(dokanMangopay.ajaxurl, data, function (response) {\n              if (response.success) {\n                /** If success go SECOND step, send data to MANGOPAY **/\n                dokanMangopayCheckout.payOptions.cards.register(response.data.CardRegistrationId, response.data.CardRegistrationURL, response.data.PreregistrationData, response.data.AccessKey, clientId, cardData);\n              } else {\n                /** We have an error **/\n                $('#dokan-mp-card-registration-fields').show();\n                $('#dokan-mp-card-save-error').html(response.error);\n                $('#dokan-mp-card-save-error').show();\n              }\n            });\n          }\n        },\n        register: function register(cardRegistrationId, cardRegistrationURL, preRegistrationData, accessKey, clientId, cardData) {\n          mangoPay.cardRegistration.baseURL = $('#dokan-mangopay-url').val();\n          mangoPay.cardRegistration.clientId = clientId;\n          /** Set data from previous form **/\n\n          mangoPay.cardRegistration.init({\n            cardRegistrationURL: cardRegistrationURL,\n            preregistrationData: preRegistrationData,\n            accessKey: accessKey,\n            Id: cardRegistrationId\n          });\n          /** Register **/\n\n          mangoPay.cardRegistration.registerCard(cardData, function (res) {\n            /** Update front list of cards **/\n            dokanMangopayCheckout.payOptions.cards.list();\n            $('#dokan-mp-card-save-processing').hide();\n            dokanMangopayCheckout.payOptions.cards.update(res.cardRegId, res.cardRegData);\n          }, function (res) {\n            /** We have an error **/\n            $('#dokan-mp-card-registration-fields').show();\n            $('#dokan-mp-card-save-error').html(dokanMangopay.regErrors['base_message'] + ': ' + dokanMangopay.regErrors[res.ResultCode]);\n            $('#dokan-mp-card-save-error').show();\n            $('#dokan-mp-card-save-processing').hide();\n          });\n        },\n        list: function list() {\n          $('#dokan-mp-saved-cards-list').html('').show();\n          var data = {\n            action: 'dokan_mangopay_get_registered_cards',\n            user_id: $('#user_id').val(),\n            _wpnonce: dokanMangopay.nonce\n          };\n          $.post(dokanMangopay.ajaxurl, data, function (response) {\n            $('#dokan-mp-saved-cards-list').html(response.data);\n            $('#dokan-mp-card-save-processing').hide();\n            /** look for data to know if we print or not the form and button of add card **/\n\n            setTimeout(function () {\n              if (parseInt($('#dokan-mp-card-saved').length) >= 1 && parseInt($('#dokan-mp-card-saved').val()) == 1) {\n                $(\"#dokan-mp-card-registration-fields\").hide();\n                $(\"#dokan-mp-add-card\").show();\n                $(\"#cancel_addcard\").show();\n              } else {\n                $(\"#dokan-mp-card-registration-fields\").show();\n                $(\"#dokan-mp-add-card\").hide();\n                $(\"#cancel_addcard\").hide();\n              }\n            }, 500);\n          });\n        },\n        update: function update(id, regData) {\n          var data = {\n            action: 'dokan_mangopay_update_card',\n            card_id: id,\n            reg_data: regData,\n            _wpnonce: dokanMangopay.nonce\n          };\n          console.log(data);\n          $.post(dokanMangopay.ajaxurl, data, function (response) {\n            if (response.success) {\n              dokanMangopayCheckout.payOptions.cards.list();\n              $('#dokan-mp-ccnickname').val('');\n              $('#dokan-mp-ccnumber').val('');\n              $('#dokan-mp-ccdate').val('');\n              $('#dokan-mp-cccrypto').val('');\n              $('#dokan-mp-card-save-processing').hide();\n              $('#dokan-mp-card-registration-fields').show();\n            }\n          });\n        }\n      }\n    }\n  };\n  $(document).ready(function () {\n    dokanMangopayCheckout.init();\n  });\n})(jQuery);\n\n//# sourceURL=webpack://dokan-pro/./modules/mangopay/assets/src/js/checkout.js?");

/***/ })

/******/ 	});
/************************************************************************/
/******/ 	
/******/ 	// startup
/******/ 	// Load entry module and return exports
/******/ 	// This entry module can't be inlined because the eval devtool is used.
/******/ 	var __webpack_exports__ = {};
/******/ 	__webpack_modules__["./modules/mangopay/assets/src/js/checkout.js"]();
/******/ 	
/******/ })()
;