From f7c1c6412603bfacd104e3f20774c42c3747a779 Mon Sep 17 00:00:00 2001 From: Leah Schumann Date: Tue, 10 Oct 2023 15:07:14 -0400 Subject: [PATCH] Frontend method to call tax endpoint --- src/constants/endpoints.js | 4 + src/constants/store-actions.js | 1 + src/layouts/payment-method/payment-method.vue | 16 ++++ src/store/index.js | 86 +++++++++++++++++++ 4 files changed, 107 insertions(+) diff --git a/src/constants/endpoints.js b/src/constants/endpoints.js index 8f4116c83..eb318581a 100644 --- a/src/constants/endpoints.js +++ b/src/constants/endpoints.js @@ -138,6 +138,10 @@ const endpoints = { url: "/price/api/v1/price/order-items", method: "GET", }, + TaxOrderItems: { + url: "/price/api/v1/price/taxed-order-items", + method: "GET", + }, LogExperimentExposureIfAssigned: { url: "/experiments/api/v1/experiments/log-exposure", method: "POST", diff --git a/src/constants/store-actions.js b/src/constants/store-actions.js index 420e8a2de..1e77d64f3 100644 --- a/src/constants/store-actions.js +++ b/src/constants/store-actions.js @@ -41,6 +41,7 @@ const storeActions = { UPDATE_STORE_WITH_SAVE_SESSION_RESPONSE: "updateStoreWithSaveSessionResponse", VALIDATE_ZIP: "validateZip", PRICE_ORDER_ITEMS_AND_SAVE_SERVER_DATA: "priceOrderItemsAndSaveServerData", + TAX_ORDER_ITEMS_AND_SAVE_SERVER_DATA: "taxOrderItemsAndSaveServerData", LOG_EXPERIMENT_EXPOSURE: "logExperimentExposure", LOG_PAGE_VIEW: "logPageView", LOG_CUSTOM_EVENT: "logCustomEvent", diff --git a/src/layouts/payment-method/payment-method.vue b/src/layouts/payment-method/payment-method.vue index cc688ca27..b4f3583c0 100644 --- a/src/layouts/payment-method/payment-method.vue +++ b/src/layouts/payment-method/payment-method.vue @@ -150,12 +150,14 @@ export default { const clonedGlassParts = store.getters.order.lineItems.glassParts ? JSON.parse(JSON.stringify(store.getters.order.lineItems.glassParts)) : []; + const availableLineItems = [ resultMap.rainDefense, ...resultMap.supportingItems, ...resultMap.wipers, ...clonedGlassParts, ]; + const pricingResults = await baseMixin.methods.dispatchStoreActionWithLogging( storeActions.PRICE_ORDER_ITEMS_AND_SAVE_SERVER_DATA, { @@ -171,6 +173,20 @@ export default { ...storeLineItems.vaps, ]; + const taxingResults = await baseMixin.methods.dispatchStoreActionWithLogging( + storeActions.TAX_ORDER_ITEMS_AND_SAVE_SERVER_DATA, + { + billToAccountNumber: 87291, + providerNumber: store.getters.order.serviceLocation.provider.providerNumber, + appointmentType: store.getters.order.serviceLocation.appointmentType, + serviceLocationState: store.getters.order.serviceLocation.state, + serviceLocationZipCode: store.getters.order.serviceLocation.zipCode, + pricedLineItems: availableLineItems, + }, + "payment-method", + false + ); + // Call the "next" function to complete the transition to this page. next((vm) => { vm.setCmsContent(resultMap.cmsContent); diff --git a/src/store/index.js b/src/store/index.js index 431fce721..d30ff1708 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -2015,14 +2015,18 @@ export const actions = { const zipCodeToUse = serviceZipCode ? serviceZipCode : context.getters.order.serviceLocation.zipCode; + const ctuToUse = serviceZipCodeCtu ? serviceZipCodeCtu : context.getters.order.serviceLocation.zipCodeCtu; + const flattenedLineItemsWithChildParts = getFlattenedArrayOfLineItemsWithChildParts(availableLineItems); + const lineItemsWithOnlyPartNumbers = flattenedLineItemsWithChildParts.map((lineItem) => ({ partNumber: lineItem.partNumber, })); + const availableLineItemsFormattedForRequest = buildQueryStringParameterFromArrayOfComplexObjects( lineItemsWithOnlyPartNumbers, @@ -2061,6 +2065,68 @@ export const actions = { return availableLineItems; }, + // Tax order actions + async taxOrderItemsAndSaveServerData( + context, + { + payload: { + billToAccountNumber, + providerNumber, + appointmentType, + serviceLocationState, + serviceLocationZipCode, + pricedLineItems, + }, + pageNameToLog, + } + ) { + const flattenedLineItemsWithChildParts = + getFlattenedArrayOfLineItemsWithChildParts(pricedLineItems); + + const lineItemsWithOnlyPriceInfo = flattenedLineItemsWithChildParts.map((lineItem) => ({ + partNumber: lineItem.partNumber, + laborAmount: lineItem.laborAmount, + kitPrice: lineItem.kitPrice, + sellingPrice: lineItem.sellingPrice, + })); + + const pricedLineItemsFormattedForRequest = + buildQueryStringParameterFromArrayOfComplexObjects( + lineItemsWithOnlyPriceInfo, + "lineItems" + ); + + let queryString = + `ParentAccountNumber=${applicationConfig.CASH_PARENT_ACCOUNT_NUMBER}` + + `&BillToAccountNumber=${billToAccountNumber}` + + `&ProviderNumber=${providerNumber}` + + `&AppointmentType=${appointmentType}` + + `&ServiceLocation.State=${serviceLocationState}` + + `&ServiceLocation.ZipCode=${serviceLocationZipCode}` + + `&${pricedLineItemsFormattedForRequest}`; + + const lineItemServerData = context.getters.order.lineItems.serverData; + if (lineItemServerData) { + queryString += `&ServerData=${encodeURIComponent(lineItemServerData)}`; + } + + const response = await globalMethods.callHttpClient({ + method: endpoints.TaxOrderItems.method, + endpoint: `${endpoints.TaxOrderItems.url}?${queryString}`, + logApiCall: true, + pageNameToLog: pageNameToLog, + }); + + context.commit(storeMutations.UPDATE_LINE_ITEMS_SERVER_DATA, response.data.serverData); + + const taxedLineItems = addTaxesToPricedLineItems( + pricedLineItems, + response.data.taxedLineItems + ); + + return taxedLineItems; + }, + // Misc order actions saveSchedule(context, scheduleInfo) { context.commit(storeMutations.UPDATE_SCHEDULE, scheduleInfo); @@ -2270,14 +2336,34 @@ function addPricesToLineItems(lineItems, pricingLineItems) { let lineItemIndex = pricingLineItems.findIndex( (pricingLineItem) => pricingLineItem.partNumber === lineItem.partNumber ); + if (lineItem.childParts) { addPricesToLineItems(lineItem.childParts, pricingLineItems); } + let pricedLineItem = pricingLineItems.splice(lineItemIndex, 1)[0]; lineItem.laborAmount = pricedLineItem.laborAmount; lineItem.sellingPrice = pricedLineItem.sellingPrice; lineItem.kitPrice = pricedLineItem.kitPrice; }); + + return lineItems; +} + +function addTaxesToPricedLineItems(lineItems, taxingLineItems) { + lineItems.forEach((lineItem) => { + let lineItemIndex = taxingLineItems.findIndex( + (taxingLineItem) => taxingLineItem.partNumber === lineItem.partNumber + ); + + if (lineItem.childParts) { + addTaxesToPricedLineItems(lineItem.childParts, taxingLineItems); + } + + let taxedLineItem = taxingLineItems.splice(lineItemIndex, 1)[0]; + lineItem.SalesTax = taxedLineItem.SalesTax; + }); + return lineItems; }