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","webpack://app/./app/javascript/packs/payment-form-due.js"],"sourcesContent":["\nimport { computed, defineComponent, onMounted, reactive, toRefs } from 'vue';\n\nexport default defineComponent({\n el: '#payment-form-due',\n setup() {\n const organization_address = $('#organization-address').data('address');\n const ONLY_CREDITS_PAYMENT_TYPE = \"accrued_credits\"\n\n const state = reactive({\n achAccountName: null,\n achAccountType: null,\n achToken: null,\n bridgeTerms: false,\n poNumber: null,\n Notes:null,\n ccToken: null,\n ccExp: null,\n cvv: null,\n paymentType: 'credit',\n appliedCredit: 0,\n creditAmount: null,\n billing_address: true,\n referenceNo: null,\n address1: organization_address?.street1 ?? \"\",\n city: organization_address?.city ?? \"\",\n state: organization_address?.state ?? \"\",\n zip: organization_address?.zip ?? \"\",\n extra_fee: 0,\n total_with_credit_card_fee: 0,\n total_without_credit_card_fee: 0,\n });\n\n onMounted(() => {\n window.addEventListener('message', handleTokenizingResponse);\n calculateTotalWithCreditCardFee();\n });\n\n const handleTokenizingResponse = (event) => {\n // Next line doesn't allow us to stub this message out in the user tests\n // if (event.origin !== \"https://fts.cardconnect.com\") return;\n try {\n var payload = JSON.parse(event.data);\n if (payload.hasOwnProperty('ccToken')) {\n console.log('Received Token (cc)');\n state.ccToken = payload.ccToken;\n document.getElementById('credit_card_token').value = state.ccToken;\n } else if (payload.hasOwnProperty('achToken')) {\n console.log('Received Token (ach)');\n state.achToken = payload.achToken;\n document.getElementById('ach_token').value = state.achToken;\n }\n } catch (e) {\n return false;\n }\n }\n\n const disableForm = computed(() => {\n const termsFieldExists = document.querySelector('input#payment_terms_and_conditions');\n const baseDataInvalid = (!state.bridgeTerms && termsFieldExists) ||\n !state.address1 ||\n !state.city ||\n !state.state ||\n !(/(^\\d{5}$)|(^\\d{5}-\\d{4}$)/).test(state.zip);\n const achDataInvalid = !state.achAccountName ||\n !state.achToken ||\n !state.achAccountType;\n\n const ccDataInvalid = !state.ccToken ||\n !state.ccExp ||\n !state.cvv;\n\n if (state.paymentType == ONLY_CREDITS_PAYMENT_TYPE && creditsCoverTotalCost() && ((termsFieldExists && state.bridgeTerms) || !termsFieldExists) ) {\n return false;\n }else if (state.paymentType == 'credit') {\n return baseDataInvalid || ccDataInvalid;\n }else if(state.paymentType == 'ach'){\n return baseDataInvalid || achDataInvalid;\n }else{\n return true;\n }\n });\n\n const payingWithCredit = computed(() => {\n return state.paymentType == 'credit';\n });\n\n const payingWithACH = computed(() => {\n return state.paymentType == 'ach';\n });\n\n const unableToAddCredit = () => {\n if(isNaN(state.creditAmount) || Number(state.creditAmount) <= 0 || !isNumberUntilTwoDecimalPlaces(state.creditAmount)){\n return true;\n }\n\n let amount = Number(state.creditAmount);\n return amount > availableCredits() || amount + totalPaid() + state.appliedCredit > totalPurchasedWithLateFee();\n }\n\n const isNumberUntilTwoDecimalPlaces = (value) => {\n // Obs: All the conversions below are necessary because sometimes in JS: \"17.1 * 100 = 1710.0000000000002\"\n let number = parseFloat((Number(value) * 100).toFixed(3));\n return Number.isSafeInteger(number);\n }\n\n const addCredit = () => {\n if (unableToAddCredit()) return true;\n state.appliedCredit += Number(state.creditAmount);\n state.creditAmount = null;\n if (creditsCoverTotalCost()){\n setClassesFromElement(\"credit_card\", \"btn disabled\");\n setClassesFromElement(\"e_check\", \"btn disabled\");\n setNewPaymentMethod(ONLY_CREDITS_PAYMENT_TYPE);\n }\n calculateTotalWithoutCreditCardFee();\n }\n \n const setClassesFromElement = (idElement, classes) => {\n let eCheckButton = document.getElementById(idElement);\n if(eCheckButton){\n eCheckButton.className = classes;\n }\n }\n\n const deleteCredit = () => {\n state.appliedCredit = 0;\n setClassesFromElement(\"credit_card\", \"btn\");\n setClassesFromElement(\"e_check\", \"btn\");\n setNewPaymentMethod(null);\n calculateTotalWithoutCreditCardFee();\n }\n\n const availableCredits = () => {\n var currentCredits = $(\"#total-credits\").data('creditsAvailable');\n return (currentCredits - state.appliedCredit);\n }\n \n const creditsCoverTotalCost = () => {\n return (state.appliedCredit > 0 && calculateTotalWithoutCreditCardFee() == 0);\n }\n\n const setNewPaymentMethod = (newMethod) => {\n state.paymentType = newMethod;\n }\n\n const selectCreditCard = () => {\n calculateTotalWithCreditCardFee();\n setNewPaymentMethod('credit');\n state.billing_address = true;\n }\n\n const formattedTotalWithCreditCard = () => {\n return formatUSAMoneyValue(calculateTotalWithCreditCardFee());\n }\n\n const calculateTotalWithCreditCardFee = () => {\n return (state.total_with_credit_card_fee = calculateTotalWithoutCreditCardFee() + calculateCreditCardFee());\n }\n\n const formattedTotalWithoutCreditCard = () => {\n return formatUSAMoneyValue(calculateTotalWithoutCreditCardFee());\n }\n\n const calculateTotalWithoutCreditCardFee = () => {\n return (state.total_without_credit_card_fee = totalPurchasedWithLateFeeMinusTotalPaid() - state.appliedCredit);\n }\n\n const totalPurchasedWithLateFeeMinusTotalPaid = () => {\n return totalPurchasedWithLateFee() - totalPaid();\n }\n\n const totalPurchasedWithLateFee = () => {\n let totalPurchased = Number(document.getElementById(\"total_charges_with_fees\").value);\n let lateFee = Number(document.getElementById(\"late_fee\").value);\n return totalPurchased + lateFee;\n }\n\n const totalPaid = () => {\n let creditsAppliedBefore = Number(document.getElementById(\"credits_applied_before\").value);\n let cashPayment = Number(document.getElementById(\"paid_amount\").value);\n return creditsAppliedBefore + cashPayment;\n }\n\n const calculateCreditCardFee = () => {\n let percent_fee = Number(document.getElementById(\"extra_fee\").value);\n return (state.extra_fee = calculateTotalWithoutCreditCardFee() * percent_fee);\n }\n\n const creditCardFeeFormated = () => {\n return formatUSAMoneyValue(calculateCreditCardFee());\n }\n\n const formatUSAMoneyValue = (value) => {\n return value.toLocaleString(\"en-US\", { minimumFractionDigits: 2, maximumFractionDigits: 2 });\n }\n\n const selectACHAccount = () => {\n setNewPaymentMethod('ach');\n state.billing_address = true\n }\n\n const selectCredits = () => {\n state.billing_address = false\n setNewPaymentMethod(creditsCoverTotalCost() ? ONLY_CREDITS_PAYMENT_TYPE : null); \n }\n\n return {\n ...toRefs(state),\n handleTokenizingResponse,\n disableForm,\n payingWithCredit,\n payingWithACH,\n unableToAddCredit,\n isNumberUntilTwoDecimalPlaces,\n addCredit,\n setClassesFromElement,\n deleteCredit,\n availableCredits,\n creditsCoverTotalCost,\n setNewPaymentMethod,\n selectCreditCard,\n formattedTotalWithCreditCard,\n calculateTotalWithCreditCardFee,\n formattedTotalWithoutCreditCard,\n calculateTotalWithoutCreditCardFee,\n totalPurchasedWithLateFee,\n totalPaid,\n calculateCreditCardFee,\n creditCardFeeFormated,\n formatUSAMoneyValue,\n selectACHAccount,\n selectCredits,\n }\n }, \n beforeDestroy() {\n window.removeEventListener('message', handleTokenizingResponse);\n },\n});\n","/* eslint no-console: 0 */\n\nimport { createApp } from 'vue'\nimport PaymentForm from '../payment/form-due.js'\n\ndocument.addEventListener('turbolinks:load', () => {\n let formDueDefined = document.getElementById(\"payment-form-due\");\n if(formDueDefined){\n const app = createApp(PaymentForm, {el: '#payment-form-due'});\n app.mount('#payment-form-due');\n }\n});\n\n"],"names":["defineComponent","el","setup","organization_address","$","data","ONLY_CREDITS_PAYMENT_TYPE","state","reactive","achAccountName","achAccountType","achToken","bridgeTerms","poNumber","Notes","ccToken","ccExp","cvv","paymentType","appliedCredit","creditAmount","billing_address","referenceNo","address1","street1","city","zip","extra_fee","total_with_credit_card_fee","total_without_credit_card_fee","onMounted","window","addEventListener","handleTokenizingResponse","calculateTotalWithCreditCardFee","event","payload","JSON","parse","hasOwnProperty","console","log","document","getElementById","value","e","disableForm","computed","termsFieldExists","querySelector","baseDataInvalid","test","achDataInvalid","ccDataInvalid","creditsCoverTotalCost","payingWithCredit","payingWithACH","unableToAddCredit","isNaN","Number","isNumberUntilTwoDecimalPlaces","amount","availableCredits","totalPaid","totalPurchasedWithLateFee","number","parseFloat","toFixed","isSafeInteger","setClassesFromElement","idElement","classes","eCheckButton","className","calculateTotalWithoutCreditCardFee","setNewPaymentMethod","newMethod","calculateCreditCardFee","totalPurchasedWithLateFeeMinusTotalPaid","percent_fee","formatUSAMoneyValue","toLocaleString","minimumFractionDigits","maximumFractionDigits","toRefs","addCredit","deleteCredit","selectCreditCard","formattedTotalWithCreditCard","formattedTotalWithoutCreditCard","creditCardFeeFormated","selectACHAccount","selectCredits","beforeDestroy","removeEventListener","createApp","PaymentForm","mount"],"sourceRoot":""}