{"version":3,"sources":["components/ShipTo/utils/index.js","components/ShipTo/Mutations/index.js"],"names":["constructShippingOptions","addresses","filter","address","isDisabled","map","label","name","fullName","fullAddress","getUserFullName","value","addressId","mapShippingContingency","errors","reduce","acc","errorKey","message","data","fields","length","code","pageLevelError","validationErrors","getSelectedShippingAddress","isSelected","selectShippingMethodById","id","shippingMethods","shippingMethod","__typename","amount","currencyFormatSymbolISOCurrency","sanitizeShippingMethod","selected","formatMethodsForDropdown","methods","buildOnShippingChangePayload","paymentId","cartBreakdownAmounts","cartTotalCurrencyCode","cartTotalCurrencyValue","selectedShippingMethod","userSelectedAddress","city","state","country","postalCode","orderID","getToken","formattedSelectedShippingMethod","isEmpty","currency_code","currencyCode","currencyValue","paymentToken","breakdown","item_total","subtotal","shipping","tax_total","tax","shipping_address","country_code","postal_code","selected_shipping_option","hasOnShippingChangeCallback","window","xprops","onShippingChange","hasNewShippingMethods","oldMethods","newMethods","every","Boolean","find","hasShippingMethodChanged","oldMethod","selectedMethod","hasAddressChanged","oldAddress","selectedAddress","makeShippingChangeCall","payload","rejected","actions","reject","then","resp","logger","cal","info","formatShippingTotals","onShippingChangePayload","Object","entries","total","lineItem","lineValue","parseFloat","tempTotal","toFixed","callOnShippingChange","Error","definitions","names","definition","kind","ADD_SHIPPING_ADDRESS_MUTATION","FundingOptionFragment","PaymentContingenciesFragment","ShippingAddressesFragment","REPLAN_SHIPPING_CHANGE_MUTATION","CreditOfferAsFIFragment","CreditOfferFragment","ShippingCartAmountFragment","UPDATE_SHIPPING_METHODS_MUTATION","ADD_PRIMARY_ADDRESS_MUTATION"],"mappings":"0uBAIO,IAAMA,EAA2B,SAAC,GAA6B,IAAD,cAAP,GAAO,GAA1BC,UAEzC,YAFmE,MAAd,GAAc,GAGhEC,QAAO,SAACC,GAAD,OAAcA,EAAQC,cAC7BC,KAAI,SAACF,GAAD,MAAc,CACjBG,MAAOH,EAAQI,KACRJ,EAAQI,KAAKC,SADb,MAC2BL,EAAQM,YACnCC,c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C,KAAK,yBAA0B,CAAEP,cAExCA,EAN8B,uBAOhCK,SAAOC,IAAIC,KAAK,4BACV,IAAIY,MAAM,2BARgB,iCAUzBd,SAAOC,IAAIC,KAAK,4BAVS,2C,+KAAH,uD,yMCvM/B,SAACa,GACC,IAAMC,EAAQ,GACd,OAAOD,EAAYvG,QAAO,SAAAyG,GACxB,GAAwB,uBAApBA,EAAWC,KACb,OAAO,EAET,IAAMrG,EAAOoG,EAAWpG,KAAKI,MAC7B,OAAI+F,EAAMnG,KAGRmG,EAAMnG,IAAQ,GACP,OAGFsG,EAA6B,0rKACtCC,wBADsC,YAEtCC,+BAFsC,YAGtCC,IAHsC,o+CAuD7BC,EAA+B,8jIACxCH,wBADwC,YAExCI,0BAFwC,YAGxCC,IAHwC,YAIxCC,6BAJwC,ipCAgD/BC,EAAgC,klFAsBhCC,EAA4B,s3JACrCR,wBADqC,YAErCC,+BAFqC,YAGrCC,IAHqC","file":"js/AddNormalizedAddress~SelectShippingInterstitial~ShipTo~8903af83.ca570335.js","sourcesContent":["import { getToken, getUserFullName } from '@paypalcorp/c3-shared-globals';\nimport { logger } from '@paypalcorp/c3-util-logger';\nimport { isEmpty } from '@paypalcorp/c3-util-lang';\n\nexport const constructShippingOptions = ({ addresses = [] } = {}) => {\n // don't show if an address is disabled\n return addresses\n .filter((address) => !address.isDisabled)\n .map((address) => ({\n label: address.name\n ? `${address.name.fullName} - ${address.fullAddress}`\n : `${getUserFullName()} - ${address.fullAddress}`,\n value: address.addressId,\n }));\n};\n\n/**\n * Normalize addShipping contingency into client consumable validation errors\n * @param {Array}\n * @return {Object}\n */\nexport const mapShippingContingency = (errors = []) =>\n errors.reduce(\n (acc, { message: errorKey, data: { fields = [] } = {} } = {}) => {\n if (errorKey === 'validationError' && fields.length > 0) {\n if (fields.length === 1) {\n const [{ code }] = fields;\n acc.pageLevelError = `VALIDATION_ERROR_${code}`;\n } else {\n acc.pageLevelError = 'VALIDATION_ERROR_SHIPPING_GENERIC_ERROR';\n }\n acc.validationErrors = fields;\n } else if (errorKey === 'ANS_RAPTOR_ADDRESS_COULD_NOT_BE_VALIDATED') {\n acc.pageLevelError = 'VALIDATION_ERROR_SHIPPING_GENERIC_ERROR';\n } else {\n acc.pageLevelError = errorKey;\n }\n\n return acc;\n },\n {\n validationErrors: [],\n pageLevelError: null,\n }\n );\n\n/**\n * @param {Array} addresses\n * @return {Array}\n */\nexport const getSelectedShippingAddress = (addresses = []) =>\n addresses.filter((address) => address.isSelected);\n\n// Removes attributes for UPDATE_SHIPPING_METHODS_MUTATION\nconst sanitizeShippingMethod = ({ __typename, ...shippingMethod }) => {\n const { __typename: _, currencyFormatSymbolISOCurrency, ...amount } = shippingMethod.amount || {};\n\n return {\n ...shippingMethod,\n amount\n };\n};\n\n// Change the selected item in the shippingMethods list\nexport const selectShippingMethodById = (id, shippingMethods) => (\n shippingMethods.map((shippingMethod) => (\n sanitizeShippingMethod({\n ...shippingMethod,\n selected: id === shippingMethod.id\n })\n ))\n);\n\nexport const formatMethodsForDropdown = (methods) => (\n methods.map(({ label, amount, id }) => ({\n label: `${label} - ${amount.currencyFormatSymbolISOCurrency}`,\n value: id\n }))\n);\n\nexport const buildOnShippingChangePayload = ({\n paymentId,\n cartBreakdownAmounts,\n cartTotalCurrencyCode,\n cartTotalCurrencyValue,\n selectedShippingMethod,\n userSelectedAddress = {}\n}) => {\n const { city, state, country, postalCode } = userSelectedAddress;\n const orderID = getToken();\n\n const formattedSelectedShippingMethod = !isEmpty(selectedShippingMethod)\n ? {\n ...selectedShippingMethod,\n amount: {\n currency_code: selectedShippingMethod?.amount?.currencyCode,\n value: selectedShippingMethod?.amount?.currencyValue\n }\n } : null;\n\n return {\n orderID,\n paymentToken: orderID,\n paymentId,\n amount: {\n breakdown: {\n item_total: {\n currency_code: cartBreakdownAmounts.subtotal?.currencyCode,\n value: cartBreakdownAmounts.subtotal?.currencyValue\n },\n shipping: {\n currency_code: cartBreakdownAmounts.shipping?.currencyCode,\n value: cartBreakdownAmounts.shipping?.currencyValue\n },\n tax_total: {\n currency_code: cartBreakdownAmounts.tax?.currencyCode,\n value: cartBreakdownAmounts.tax?.currencyValue\n }\n },\n currency_code: cartTotalCurrencyCode,\n value: cartTotalCurrencyValue\n },\n shipping_address: {\n city,\n state,\n country_code: country,\n postal_code: postalCode\n },\n selected_shipping_option: formattedSelectedShippingMethod\n };\n};\n\nexport const hasOnShippingChangeCallback = () => window?.xprops?.onShippingChange;\n\nexport const hasNewShippingMethods = (oldMethods, newMethods) => {\n if (!oldMethods) return false;\n \n return !newMethods.every(({ id }) => {\n return Boolean(oldMethods.find(({ id: oldId }) => oldId === id));\n });\n};\n\nexport const hasShippingMethodChanged = (oldMethod, selectedMethod = {}) => {\n if (!selectedMethod?.id) {\n return false;\n }\n\n return oldMethod?.id !== selectedMethod?.id;\n};\n\nexport const hasAddressChanged = (oldAddress, selectedAddress = {}) => {\n if (!selectedAddress?.addressId) {\n return false;\n }\n \n return oldAddress?.addressId !== selectedAddress?.addressId;\n};\n\n/**\n * how to use shipping callback\n * https://developer.paypal.com/docs/checkout/integration-features/shipping-callback/\n * https://developer.paypal.com/docs/checkout/integration-features/shipping-callback/#examples\n */\nconst makeShippingChangeCall = (payload) => {\n\n let rejected = false;\n\n const actions = {\n reject() {\n rejected = true;\n }\n }\n\n return window.xprops.onShippingChange(payload, actions)\n .then((resp) => {\n logger.cal.info('resp_of_onShippingChange', resp);\n return { rejected }\n })\n}\n\n// the new amount doesn't account for the shipping change just made when it gets sent to onShippingChange,\n// so it has to get applied here\nconst formatShippingTotals = (onShippingChangePayload) => {\n\n onShippingChangePayload.amount.breakdown.shipping = (onShippingChangePayload?.selected_shipping_option?.amount)\n ? onShippingChangePayload?.selected_shipping_option?.amount\n : onShippingChangePayload?.amount?.breakdown?.shipping;\n\n onShippingChangePayload.amount.value\n = Object.entries(onShippingChangePayload?.amount?.breakdown || {}).reduce((total, lineItem) => {\n\n const lineValue = parseFloat(lineItem[1].value);\n const tempTotal = parseFloat(total);\n\n return parseFloat(tempTotal + lineValue).toFixed(2);\n }, '0');\n\n return onShippingChangePayload;\n};\n\nexport const callOnShippingChange = async ( onShippingChangePayload ) => {\n logger.cal.info('called_on_shipping_change');\n\n const { rejected } = await makeShippingChangeCall(formatShippingTotals(onShippingChangePayload));\n logger.cal.info('shipping_change_called', { rejected });\n\n if (rejected) {\n logger.cal.info('shipping_change_rejected');\n throw new Error('shippingChange rejected');\n } else {\n return logger.cal.info('shipping_change_success');\n }\n};\n","import gql from 'graphql-tag';\nimport {\n FundingOptionFragment,\n PaymentContingenciesFragment,\n CreditOfferAsFIFragment,\n ShippingCartAmountFragment,\n} from '@paypalcorp/c3-graphql-fragments';\nimport { ShippingAddressesFragment } from '@/components/ShipTo';\nimport { CreditOfferFragment } from '@/components/CreditOffer';\n\n/**\n * NOTE: please make sure to take a look at `?\"\n * \"` and `ShipTo`\n * flow tests if there are new changes being introduced to `ADD_SHIPPING_ADDRESS_MUTATION`\n */\nexport const ADD_SHIPPING_ADDRESS_MUTATION = gql`\n ${FundingOptionFragment}\n ${PaymentContingenciesFragment}\n ${ShippingAddressesFragment}\n mutation AddShippingAddress(\n $city: String\n $country: CountryCodes!\n $experiences: [ThreeDSPaymentExperience]\n $familyName: String!\n $givenName: String!\n $line1: String!\n $line2: String\n $normalize: Boolean = false\n $postalCode: String\n $state: String\n $token: String!\n ) {\n addShippingAddress(\n token: $token\n givenName: $givenName\n familyName: $familyName\n line1: $line1\n line2: $line2\n city: $city\n state: $state\n postalCode: $postalCode\n countryCode: $country\n normalize: $normalize\n ) {\n merchant {\n name\n }\n shippingAddresses {\n ...ShippingAddressesFragment\n }\n flags {\n isChangeShippingAddressAllowed\n hideShipping\n blockNonDomesticShipping\n }\n # Same fundingOptions queried in PayWith, as shipping change causes a replan and may change the funding list.\n # TODO: Use a fragment, or update xobuyernodeserv to not require re-fetching the funding options\n fundingOptions(returnAllPlans: true, groupSourcesOnType: INCENTIVE) {\n ...FundingOptionFragment\n }\n paymentContingencies {\n ...PaymentContingenciesFragment\n threeDomainSecure(experiences: $experiences) {\n ...ThreeDomainSecureFields\n }\n }\n }\n }\n`;\n\nexport const REPLAN_SHIPPING_CHANGE_MUTATION = gql`\n ${FundingOptionFragment}\n ${CreditOfferAsFIFragment}\n ${CreditOfferFragment}\n ${ShippingCartAmountFragment}\n mutation ReplanShippingChange($token: String!, $areCookiesDisabled: Boolean, $isIframe: Boolean) {\n triggerReplan(token: $token) {\n fundingOptions(returnAllPlans: true, groupSourcesOnType: INCENTIVE) {\n ...FundingOptionFragment\n }\n creditAsFIOffers {\n ...CreditOfferAsFIFragment\n }\n creditPPCOffers(areCookiesDisabled: $areCookiesDisabled, isIframe: $isIframe) {\n ...CreditOfferFragment\n }\n cart {\n category\n intent\n paymentId\n amounts {\n ...ShippingCartAmountFragment\n }\n total {\n currencyCode\n currencyFormatSymbolISOCurrency\n currencyValue\n }\n items {\n details\n }\n noteToBuyer\n shippingMethods {\n id\n type\n label\n selected\n amount {\n currencyCode\n currencyValue\n currencyFormatSymbolISOCurrency\n }\n }\n }\n }\n }\n`;\n\nexport const UPDATE_SHIPPING_METHODS_MUTATION = gql`\n mutation UpdateShippingMethods($token: String!, $shippingMethods: [ShippingMethodInput]!) {\n updateShippingMethods(token: $token, shippingMethods: $shippingMethods) {\n cart {\n total {\n currencyFormatSymbolISOCurrency\n }\n shippingMethods {\n id\n type\n label\n selected\n amount {\n currencyValue\n currencyCode\n }\n }\n }\n }\n }\n`;\n\nexport const ADD_PRIMARY_ADDRESS_MUTATION = gql`\n ${FundingOptionFragment}\n ${PaymentContingenciesFragment}\n ${ShippingAddressesFragment}\n mutation addAddressToUser(\n $city: String\n $country: CountryCodes!\n $experiences: [ThreeDSPaymentExperience]\n $line1: String!\n $line2: String\n $normalize: Boolean = false\n $postalCode: String\n $primary: Boolean = true\n $state: String\n $token: String!\n ) {\n addAddressToUser(\n token: $token\n line1: $line1\n line2: $line2\n city: $city\n state: $state\n postalCode: $postalCode\n countryCode: $country\n normalize: $normalize\n primary: $primary\n ) {\n fundingOptions(returnAllPlans: true, groupSourcesOnType: INCENTIVE) {\n ...FundingOptionFragment\n }\n flags {\n isChangeShippingAddressAllowed\n hideShipping\n blockNonDomesticShipping\n is3DSecureRequired\n isIncentivePresent\n }\n shippingAddresses {\n ...ShippingAddressesFragment\n }\n paymentContingencies {\n ...PaymentContingenciesFragment\n threeDomainSecure(experiences: $experiences) {\n ...ThreeDomainSecureFields\n }\n }\n }\n }\n`;\n"],"sourceRoot":""}