From eafd2e378faf3e506f788f6c7680835d48320afd Mon Sep 17 00:00:00 2001 From: pgilmore-phi Date: Wed, 16 Oct 2024 11:21:29 -0400 Subject: [PATCH] Salesforce Abandoned Cart: refactored payload (#239) * Merge Stage into Main (#228) * #181 Fix styles of pet-tags/tag-quote and pet-tags/tag-select (#182) * hotfix for change domain * adding additional environment entry to config * updated trusted site block * Menu links refactoring (#188) * merge stage into main * changed links decoration approach * PM-361 * PM-361 * updated document-based footer * added x icon for footer * removed external icon for petmicrochiplookup.org link * 24PW: Post Purchase Thank You Page - EDS Build (#201) * Add svg icons * Fix svg icon name * Fix svg icon * Fix svg icon * Added gray column * Added autocomplite functionality * Added fix for autocomplite functionality * Added validagtors for promocode and zipcode, added loader animation * Added some validators * Added some validators * Handlers/validators refactoring * enhanced for Canada * Canadian legal and Canadian icons * the beginning of the submit execution * the middle of the submit execution * the completion of the submit execution * fix JavaScript linting * Fix validators for subbmit button * allow for re-entering Step 1 * Fix validators for breed input * honor a query param of 'petId' when re-entering Step 1 * strengthen our client API * Fix validators for zipCode and async problem * Separate js for the first page * Fix zip code handler * Some part of summary-quote * Added button "Proceed to Payment" * Small css fixes * Small fixes for lpm-plus * Fixed svg classes and added the icon for lpm-plus * Added fragments with additional info to summary page * Added loader.js * Small refctoring * Move the form to form.js * Added the form to summary page * Remove wrong div * Fixed icons in fragments * Small cleaning * Form cleaning * Improved the chip number validator * Added isSummaryPage * Added isSummaryPage * Improve loader * Added loader to summary page * Added isSummaryPage to the form * Intermediate code for adding a pet on the summary page * Fix issue with styled icons * Added form functionality to summary page * Added pet removing functionality to summary page * Hide promocode field on summary page * Fix flow id * Fix css * Fix css * Fixes for CA * Fixes for linters * Added promo code functionality * Fixed parameter for payment url * Fix promo code functionality * Fix typo * Fix styles * Added header with only logo * Fix styles * Improvments for zip code handler * WIP on feature/post-purchase-thank-you-page * Fix zip code handler for CA * Promocode fixes * Promocode fixes * WIP on feature/post-purchase-thank-you-page * Added minus for discount * WIP on feature/post-purchase-thank-you-page * WIP on feature/post-purchase-thank-you-page * WIP on feature/post-purchase-thank-you-page * Remove a comment * Fixed birthday for pets * WIP on feature/post-purchase-thank-you-page * Fixed birthday for pets * Fixed birthday for pets --------- Co-authored-by: Bohdan Korablov Co-authored-by: Mike Weis Co-authored-by: Mike Weis * 24PW: Post Purchase Thank You Page - EDS Build - QA Feedback Updates (#203) * Add svg icons * Fix svg icon name * Fix svg icon * Fix svg icon * Added gray column * Added autocomplite functionality * Added fix for autocomplite functionality * Added validagtors for promocode and zipcode, added loader animation * Added some validators * Added some validators * Handlers/validators refactoring * enhanced for Canada * Canadian legal and Canadian icons * the beginning of the submit execution * the middle of the submit execution * the completion of the submit execution * fix JavaScript linting * Fix validators for subbmit button * allow for re-entering Step 1 * Fix validators for breed input * honor a query param of 'petId' when re-entering Step 1 * strengthen our client API * Fix validators for zipCode and async problem * Separate js for the first page * Fix zip code handler * Some part of summary-quote * Added button "Proceed to Payment" * Small css fixes * Small fixes for lpm-plus * Fixed svg classes and added the icon for lpm-plus * Added fragments with additional info to summary page * Added loader.js * Small refctoring * Move the form to form.js * Added the form to summary page * Remove wrong div * Fixed icons in fragments * Small cleaning * Form cleaning * Improved the chip number validator * Added isSummaryPage * Added isSummaryPage * Improve loader * Added loader to summary page * Added isSummaryPage to the form * Intermediate code for adding a pet on the summary page * Fix issue with styled icons * Added form functionality to summary page * Added pet removing functionality to summary page * Hide promocode field on summary page * Fix flow id * Fix css * Fix css * Fixes for CA * Fixes for linters * Added promo code functionality * Fixed parameter for payment url * Fix promo code functionality * Fix typo * Fix styles * Added header with only logo * Fix styles * Improvments for zip code handler * WIP on feature/post-purchase-thank-you-page * Fix zip code handler for CA * Promocode fixes * Promocode fixes * WIP on feature/post-purchase-thank-you-page * Added minus for discount * WIP on feature/post-purchase-thank-you-page * WIP on feature/post-purchase-thank-you-page * WIP on feature/post-purchase-thank-you-page * Remove a comment * Fixed birthday for pets * WIP on feature/post-purchase-thank-you-page * Fixed birthday for pets * Fixed birthday for pets * QA feedback updates * Fix lint issue --------- Co-authored-by: Bohdan Korablov Co-authored-by: Mike Weis Co-authored-by: Mike Weis * 24PW: Post Purchase Thank You Page - EDS Build - QA Feedback Updates (#204) * Add svg icons * Fix svg icon name * Fix svg icon * Fix svg icon * Added gray column * Added autocomplite functionality * Added fix for autocomplite functionality * Added validagtors for promocode and zipcode, added loader animation * Added some validators * Added some validators * Handlers/validators refactoring * enhanced for Canada * Canadian legal and Canadian icons * the beginning of the submit execution * the middle of the submit execution * the completion of the submit execution * fix JavaScript linting * Fix validators for subbmit button * allow for re-entering Step 1 * Fix validators for breed input * honor a query param of 'petId' when re-entering Step 1 * strengthen our client API * Fix validators for zipCode and async problem * Separate js for the first page * Fix zip code handler * Some part of summary-quote * Added button "Proceed to Payment" * Small css fixes * Small fixes for lpm-plus * Fixed svg classes and added the icon for lpm-plus * Added fragments with additional info to summary page * Added loader.js * Small refctoring * Move the form to form.js * Added the form to summary page * Remove wrong div * Fixed icons in fragments * Small cleaning * Form cleaning * Improved the chip number validator * Added isSummaryPage * Added isSummaryPage * Improve loader * Added loader to summary page * Added isSummaryPage to the form * Intermediate code for adding a pet on the summary page * Fix issue with styled icons * Added form functionality to summary page * Added pet removing functionality to summary page * Hide promocode field on summary page * Fix flow id * Fix css * Fix css * Fixes for CA * Fixes for linters * Added promo code functionality * Fixed parameter for payment url * Fix promo code functionality * Fix typo * Fix styles * Added header with only logo * Fix styles * Improvments for zip code handler * WIP on feature/post-purchase-thank-you-page * Fix zip code handler for CA * Promocode fixes * Promocode fixes * WIP on feature/post-purchase-thank-you-page * Added minus for discount * WIP on feature/post-purchase-thank-you-page * WIP on feature/post-purchase-thank-you-page * WIP on feature/post-purchase-thank-you-page * Remove a comment * Fixed birthday for pets * WIP on feature/post-purchase-thank-you-page * Fixed birthday for pets * Fixed birthday for pets * QA feedback updates * Fix lint issue * QA feedback updates --------- Co-authored-by: Bohdan Korablov Co-authored-by: Mike Weis Co-authored-by: Mike Weis * Fixes for the form issues (#205) * Feature/post purchase thank you page (#206) * Add svg icons * Fix svg icon name * Fix svg icon * Fix svg icon * Added gray column * Added autocomplite functionality * Added fix for autocomplite functionality * Added validagtors for promocode and zipcode, added loader animation * Added some validators * Added some validators * Handlers/validators refactoring * enhanced for Canada * Canadian legal and Canadian icons * the beginning of the submit execution * the middle of the submit execution * the completion of the submit execution * fix JavaScript linting * Fix validators for subbmit button * allow for re-entering Step 1 * Fix validators for breed input * honor a query param of 'petId' when re-entering Step 1 * strengthen our client API * Fix validators for zipCode and async problem * Separate js for the first page * Fix zip code handler * Some part of summary-quote * Added button "Proceed to Payment" * Small css fixes * Small fixes for lpm-plus * Fixed svg classes and added the icon for lpm-plus * Added fragments with additional info to summary page * Added loader.js * Small refctoring * Move the form to form.js * Added the form to summary page * Remove wrong div * Fixed icons in fragments * Small cleaning * Form cleaning * Improved the chip number validator * Added isSummaryPage * Added isSummaryPage * Improve loader * Added loader to summary page * Added isSummaryPage to the form * Intermediate code for adding a pet on the summary page * Fix issue with styled icons * Added form functionality to summary page * Added pet removing functionality to summary page * Hide promocode field on summary page * Fix flow id * Fix css * Fix css * Fixes for CA * Fixes for linters * Added promo code functionality * Fixed parameter for payment url * Fix promo code functionality * Fix typo * Fix styles * Added header with only logo * Fix styles * Improvments for zip code handler * WIP on feature/post-purchase-thank-you-page * Fix zip code handler for CA * Promocode fixes * Promocode fixes * WIP on feature/post-purchase-thank-you-page * Added minus for discount * WIP on feature/post-purchase-thank-you-page * WIP on feature/post-purchase-thank-you-page * WIP on feature/post-purchase-thank-you-page * Remove a comment * Fixed birthday for pets * WIP on feature/post-purchase-thank-you-page * Fixed birthday for pets * Fixed birthday for pets * QA feedback updates * Fix lint issue * QA feedback updates * QA feedback updates --------- Co-authored-by: Bohdan Korablov Co-authored-by: Mike Weis Co-authored-by: Mike Weis * Sync develop into stage (#207) * 24PW: Membership V2 Paid Page - EDS Build (#208) * WIP on feature/membership-v2-paid-page * WIP on feature/membership-v2-paid-page * WIP on feature/membership-v2-paid-page * WIP on feature/membership-v2-paid-page * Datalayer updates for feature/membership-v2-paid-page * Datalayer updates for feature/membership-v2-paid-page * Fix lint issues on feature/membership-v2-paid-page * 24PW: Membership V2 Paid Page - QA Updates (#209) * WIP on feature/membership-v2-paid-page * WIP on feature/membership-v2-paid-page * WIP on feature/membership-v2-paid-page * WIP on feature/membership-v2-paid-page * Datalayer updates for feature/membership-v2-paid-page * Datalayer updates for feature/membership-v2-paid-page * Fix lint issues on feature/membership-v2-paid-page * QA feedback updates on feature/membership-v2-paid-page * QA feedback updates on feature/membership-v2-paid-page * Add page /paid/lost-pet-protection (#194) * WIP on feature/lost-pet-protection-paid-page * WIP on feature/lost-pet-protection-paid-page * WIP on feature/lost-pet-protection-paid-page * WIP on feature/lost-pet-protection-paid-page * WIP on feature/lost-pet-protection-paid-page * 24PW: Membership V2 Paid Page - QA Updates (#211) * WIP on feature/membership-v2-paid-page * WIP on feature/membership-v2-paid-page * WIP on feature/membership-v2-paid-page * WIP on feature/membership-v2-paid-page * Datalayer updates for feature/membership-v2-paid-page * Datalayer updates for feature/membership-v2-paid-page * Fix lint issues on feature/membership-v2-paid-page * QA feedback updates on feature/membership-v2-paid-page * QA feedback updates on feature/membership-v2-paid-page * QA feedback updates on feature/membership-v2-paid-page * QA feedback updates on feature/membership-v2-paid-page * Fix config matching (#212) * 24PW: Lost Pet Recovery Paid Page - EDS Build (#210) * WIP on feature/lost-pet-recovery-paid-page * WIP on feature/lost-pet-recovery-paid-page * WIP on feature/lost-pet-recovery-paid-page * WIP on feature/lost-pet-recovery-paid-page * Fix lint issue * Sync develop into stage (#213) * Sync develop into stage (#213) (#214) * Fix css (#216) * Sync develop into stage (#220) * 24PW: New Template - Paid Blog (#219) * 24PW: Pawpack Page - EDS Build (#215) * Added Shipping of Tag to the summary page (#221) --------- Co-authored-by: Bohdan Korablov * Sync develop into stage (#223) * 24PW: New Template - Paid Blog (#219) * WIP on feature/paid-blog-landing-page * WIP on feature/paid-blog-landing-page * WIP on feature/paid-blog-landing-page * WIP on feature/paid-blog-landing-page * WIP on feature/paid-blog-landing-page * WIP on feature/paid-blog-landing-page * WIP on feature/paid-blog-landing-page * WIP on feature/paid-blog-landing-page * WIP on feature/paid-blog-landing-page * WIP on feature/paid-blog-landing-page * WIP on feature/paid-blog-landing-page * 24PW: Pawpack Page - EDS Build (#215) * WIP on feature/pawpack-page * WIP on feature/pawpack-page * Fix lint issues on feature/pawpack-page * WIP on feature/pawpack-page * Added Shipping of Tag to the summary page (#221) * 24PW: Pawpack Page - EDS Build - QA Feedback (#222) * WIP on feature/pawpack-page * WIP on feature/pawpack-page * Fix lint issues on feature/pawpack-page * WIP on feature/pawpack-page * QA feedback on feature/pawpack-page * QA feedback on feature/pawpack-page * QA feedback on feature/pawpack-page * QA feedback on feature/pawpack-page * WIP on bugfix/mobile-nav-redirect-visibility (#224) --------- Co-authored-by: Bohdan Korablov * Sync develop into stage (#227) * 24PW: New Template - Paid Blog (#219) * WIP on feature/paid-blog-landing-page * WIP on feature/paid-blog-landing-page * WIP on feature/paid-blog-landing-page * WIP on feature/paid-blog-landing-page * WIP on feature/paid-blog-landing-page * WIP on feature/paid-blog-landing-page * WIP on feature/paid-blog-landing-page * WIP on feature/paid-blog-landing-page * WIP on feature/paid-blog-landing-page * WIP on feature/paid-blog-landing-page * WIP on feature/paid-blog-landing-page * 24PW: Pawpack Page - EDS Build (#215) * WIP on feature/pawpack-page * WIP on feature/pawpack-page * Fix lint issues on feature/pawpack-page * WIP on feature/pawpack-page * Added Shipping of Tag to the summary page (#221) * 24PW: Pawpack Page - EDS Build - QA Feedback (#222) * WIP on feature/pawpack-page * WIP on feature/pawpack-page * Fix lint issues on feature/pawpack-page * WIP on feature/pawpack-page * QA feedback on feature/pawpack-page * QA feedback on feature/pawpack-page * QA feedback on feature/pawpack-page * QA feedback on feature/pawpack-page * WIP on bugfix/mobile-nav-redirect-visibility (#224) * 24PW: Pet Insurance - Aggregator Widget (#225) * Adding widget aggregator block from petplace to 24petwatch * updating css media query at point iframe size changes, updated id refs * Revert decorateButtons function, apply callout cta styling (#226) --------- Co-authored-by: Bohdan Korablov Co-authored-by: pgilmore-phi --------- Co-authored-by: miakobchuk Co-authored-by: Bohdan Korablov Co-authored-by: hero-dokane <46008504+hero-dokane@users.noreply.github.com> Co-authored-by: Mike Weis Co-authored-by: Mike Weis Co-authored-by: Felix Delval * Changes from the feature/PM-56724-dl-thank-you (#232) * Adding SalesForce API call to trigger abandoned cart journey * fix eslint issues * adding salesforce proxy config * updated species id to name conversion * refactor code * updated refactored code * adding contactkey and eventdefinitionkey to summary quote payload --------- Co-authored-by: miakobchuk Co-authored-by: Bohdan Korablov Co-authored-by: hero-dokane <46008504+hero-dokane@users.noreply.github.com> Co-authored-by: Mike Weis Co-authored-by: Mike Weis Co-authored-by: Felix Delval --- blocks/plans-quote/summary-quote.js | 75 ++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 23 deletions(-) diff --git a/blocks/plans-quote/summary-quote.js b/blocks/plans-quote/summary-quote.js index 455699c..302ecb8 100644 --- a/blocks/plans-quote/summary-quote.js +++ b/blocks/plans-quote/summary-quote.js @@ -74,33 +74,62 @@ export default async function decorateSummaryQuote(block, apiBaseUrl) { // eslint-disable-next-line no-console console.log('Failed to get the purchase summary for owner:', ownerData.id, ' status:', status); } + } + Loader.hideLoader(); - // Send data for abandoned cart journey - try { - await fetch(salesforceProxyEndpoint, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - data: { - ContactKey: ownerData.email, - EmailAddress: ownerData.email, - OrderCompleted: false, - OwnerId: ownerData.id, - PetId: selectedProducts.petID, - PetName: petsList[0].petName, - SiteURL: 'https://24petwtach.com', - Species: petsList[0].speciesId === 1 ? 'Dog' : 'Cat', - }, - }), - }); - } catch (error) { + async function sendDataToSalesforce(owner, products, pets) { + if (!owner || !owner.email || !owner.id) { + // eslint-disable-next-line no-console + console.error('invalid owner data'); + return; + } + + if (!products || !products[0] || !products[0].petID) { + // eslint-disable-next-line no-console + console.error('Invalid selected products data'); + return; + } + + if (!pets || !pets[0] || !pets[0].petName || !pets[0].speciesId === undefined) { // eslint-disable-next-line no-console - console.error('There was an error when sending the data to Salesforce:'); + console.error('Invalid pets list data'); + return; } + + const payload = { + payload: { + Data: { + ContactKey: ownerData.email, + EmailAddress: ownerData.email, + OrderCompleted: false, + OwnerId: ownerData.id, + PetId: selectedProducts[0].petID, + PetName: petsList[0].petName, + SiteURL: 'https://24petwtach.com', + Species: petsList[0].speciesId === 1 ? 'Dog' : 'Cat', + }, + EventDefinitionKey: 'APIEvent-6723a35b-b066-640c-1d7b-222f98caa9e1', + ContactKey: ownerData.email, + }, + }; + + const options = { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(payload), + }; + await fetch(salesforceProxyEndpoint, options); + } + + // Send data for abandoned cart journey + try { + await sendDataToSalesforce(ownerData, selectedProducts, petsList); + } catch (error) { + // eslint-disable-next-line no-console + console.error('There was an error sending the data to Salesforce', error); } - Loader.hideLoader(); function getSelectedProduct(petId) { return selectedProducts.find((item) => item.petID === petId);