';\r\n document.body.appendChild(element);\r\n\r\n // if a 3DS challenge UI kicks in then hide the overlay message\r\n // when the 3DS challenge goes away, show the message again \r\n const overlayHandler = (mutationList, observer) => {\r\n for (const mutation of mutationList) {\r\n if (mutation.type === 'childList') {\r\n if (Array.from(mutation.addedNodes).some(is3dsOverlay)) {\r\n this.hideOverlay();\r\n return;\r\n }\r\n if (Array.from(mutation.removedNodes).some(is3dsOverlay)) {\r\n this.showOverlay();\r\n return;\r\n }\r\n }\r\n if (this.areValidationErrors()) {\r\n this.destroyOverlay();\r\n }\r\n }\r\n function is3dsOverlay(e) {\r\n return e.tagName.toLowerCase() === \"div\" && e.id.startsWith(\"PayCentral-overlay-\");\r\n }\r\n };\r\n\r\n this.overlay = {\r\n element: element,\r\n observer: new MutationObserver(overlayHandler)\r\n };\r\n\r\n this.showOverlay();\r\n this.overlay.observer.observe(document.body, { childList: true });\r\n\r\n }\r\n\r\n showOverlay() {\r\n if (!this.overlay?.element) return;\r\n jQuery(this.overlay.element).modal({ backdrop: 'static', keyboard: false }, 'show');\r\n }\r\n\r\n hideOverlay() {\r\n if (!this.overlay?.element) return;\r\n jQuery(this.overlay.element).modal('hide');\r\n }\r\n\r\n destroyOverlay() {\r\n if (this.overlay?.element) {\r\n jQuery(this.overlay.element).modal('hide');\r\n this.overlay.element.remove();\r\n }\r\n if (this.overlay?.observer) {\r\n this.overlay.observer.disconnect();\r\n }\r\n this.overlay = null;\r\n }\r\n\r\n // detect scenarios where the iframe is loaded with content other than the widget whilst the overlay is being displayed\r\n // if this is detected, tear down the overlay\r\n async monitorFrameContent() {\r\n\r\n const frame = this.findFrame();\r\n if (!frame) return;\r\n\r\n const frameContentCounter = this.frameContentCounter;\r\n const valid = await this.ping();\r\n\r\n // if the frame changed whilst we were waiting for a response, then bail out\r\n // this would happen if the user changes payment method whilst waiting for a ping response\r\n if (this.findFrame() !== frame) return;\r\n\r\n // this.frameContentCounter gets incremented anytime new content is loaded into the frame\r\n // if the counter has changed since we awaited the ping then we have moved along in the process and we just exit out here\r\n // there will be more events queued up to check the newly loaded content\r\n if (frameContentCounter !== this.frameContentCounter) {\r\n return;\r\n }\r\n\r\n this.frameUnresponsive = !valid;\r\n\r\n // if we did not get a response from the ping, it would indicate that the widget is not loaded into the frame\r\n // if we are using an overlay then tear it down and display a message\r\n if (!valid && this.overlay) {\r\n console.warn(\"The PayCentral frame appears to contain something other than the payment widget. Tearing down the page overlay.\");\r\n this.handleFrameUnresponsive();\r\n }\r\n }\r\n\r\n handleFrameUnresponsive() {\r\n this.clearMessages();\r\n this.handleError(\"An error occurred while submitting the payment request. Please reload the page and try again. Reload\", true);\r\n }\r\n\r\n areValidationErrors() {\r\n try {\r\n const errors = jQuery(this.getMessageContainer()).text();\r\n return errors.length > 0;\r\n } catch (error) {\r\n return false;\r\n }\r\n }\r\n\r\n async ping() {\r\n\r\n const frame = this.findFrame();\r\n\r\n if (!frame?.contentWindow) {\r\n console.warn(\"The PayCentral frame has not been established. Unable to ping.\");\r\n return false;\r\n }\r\n\r\n const id = ++this.pingCounter;\r\n let timeout;\r\n\r\n try {\r\n\r\n return await new Promise((resolve, reject) => {\r\n this.registerPingHandler(id, () => resolve(true));\r\n frame.contentWindow.postMessage(\"ping-\" + id, \"*\");\r\n timeout = setTimeout(() => reject(\"ping timed out\"), 5000);\r\n });\r\n\r\n } catch (e) {\r\n console.warn(`Ping attempt failed with ${JSON.stringify(e)}`);\r\n return false;\r\n } finally {\r\n if (timeout) clearTimeout(timeout);\r\n this.destroyPingHandler(id);\r\n }\r\n\r\n }\r\n\r\n registerPingHandler(id, action) {\r\n this.destroyPingHandler(id);\r\n this.pingHandlers.push({\r\n id: id,\r\n action: action,\r\n active: true\r\n });\r\n }\r\n\r\n destroyPingHandler(id) {\r\n const i = this.pingHandlers.findIndex((h) => h.id === id);\r\n if (i !== -1) {\r\n this.pingHandlers[i].active = false;\r\n this.pingHandlers.splice(i, 1);\r\n }\r\n }\r\n\r\n handlePingResponse(response) {\r\n if (!response.startsWith(\"pong-\")) return;\r\n const id = Number(response.substring(5));\r\n if (isNaN(id)) return;\r\n const i = this.pingHandlers.findIndex((h) => h.id === id && h.active);\r\n if (i !== -1) {\r\n const handler = this.pingHandlers[i];\r\n handler.active = false;\r\n this.pingHandlers.splice(i, 1);\r\n handler.action(response);\r\n }\r\n }\r\n\r\n deepClone(o) {\r\n try {\r\n if (\"structuredClone\" in window && typeof window[\"structuredClone\"] === \"function\") {\r\n return window[\"structuredClone\"](o);\r\n }\r\n } catch (e) { }\r\n try {\r\n return JSON.parse(JSON.stringify(o));\r\n } catch (e) { }\r\n // it won't clone, unlikely\r\n return o;\r\n }\r\n\r\n}\r\n\r\nwindow.PayCentral = new PayCentralManager();\r\n\r\n// export for unit tests\r\nexport default PayCentralManager;\r\n "],"names":["addressList","defaultBillingAddress","addressLines","cityName","countryCode","countryName","countrySubEntityCode","countrySubEntityName","postalCode","updateStatus","instance","updated","setBillingDetails","address","name","instanceAddressHasUpdate","billingDetails","mapToSdkBillingDetails","console","log","JSON","stringify","push","updateBillingAddress","preferredBillingDetails","length","setInstanceAddressUpdateStatus","getBillingDetails","format","arguments","undefined","tryGetBillingDetailsFromUserInput","toPascalCase","_name$FirstName","_name$LastName","_name$FullName","_address$AddressLines","_address$CityName","_address$CountryCode","_address$CountryName","_address$CountrySubEn","_address$CountrySubEn2","_address$PostalCode","isEmpty","firstName","FirstName","lastName","LastName","fullName","FullName","getBillingFullName","AddressLines","CityName","CountryCode","CountryName","CountrySubEntityCode","CountrySubEntityName","PostalCode","_name$firstName","_name$lastName","_name$fullName","_address$addressLines","_address$cityName","_address$countryCode","_address$countryName","_address$countrySubEn","_address$countrySubEn2","_address$postalCode","Name","Address","allFirstName","document","querySelectorAll","allLastName","allAddressLines0","allAddressLines1","allAddressLines2","allCity","allPostalCode","allSubEntityName","allCountryDropdowns","allSubEntityDropdowns","userInputBillingDetails","index","countryOption","getDropdownOption","value","getInputValue","text","countrySubEntityOption","filter","line","isNameFull","isSdkBillingDetailsAllNullEverything","richestIndex","richestAmount","i","richnessOfCurrentBillingDetails","getAmountOfFilledFieldsRecursive","object","Object","values","reduce","s","v","_typeof","every","x","isAddressAllNullEverything","domainAddress","sdkBillingDetails","elementsNodeList","_elementsNodeList$ind","selectElement","result","options","selectedIndex","includes","_regeneratorRuntime","e","t","r","prototype","n","hasOwnProperty","o","defineProperty","Symbol","a","iterator","c","asyncIterator","u","toStringTag","define","enumerable","configurable","writable","wrap","Generator","create","Context","makeInvokeMethod","tryCatch","type","arg","call","h","l","f","y","GeneratorFunction","GeneratorFunctionPrototype","p","d","getPrototypeOf","g","defineIteratorMethods","forEach","_invoke","AsyncIterator","invoke","resolve","__await","then","callInvokeWithMethodAndArg","Error","done","method","delegate","maybeInvokeDelegate","sent","_sent","dispatchException","abrupt","return","TypeError","resultName","next","nextLoc","pushTryEntry","tryLoc","catchLoc","finallyLoc","afterLoc","tryEntries","resetTryEntry","completion","reset","isNaN","displayName","isGeneratorFunction","constructor","mark","setPrototypeOf","__proto__","awrap","async","Promise","keys","reverse","pop","prev","charAt","slice","stop","rval","handle","complete","finish","catch","_catch","delegateYield","asyncGeneratorStep","_asyncToGenerator","apply","_next","_throw","_createForOfIteratorHelper","Array","isArray","_unsupportedIterableToArray","_n","F","_toConsumableArray","_arrayWithoutHoles","_iterableToArray","_nonIterableSpread","_arrayLikeToArray","toString","from","test","_classCallCheck","_defineProperties","_toPropertyKey","key","_createClass","_defineProperty","_toPrimitive","toPrimitive","String","Number","billingDetailsHelper","PayCentralManager","containList","context","dataVaultJson","dataVaultResponseToken","frame","paymentMethod","paymentMethodSelector","validToken","commandButton","commandButtonOnClick","_this","overlay","frameContentCounter","frameUnresponsive","pingCounter","pingHandlers","src","lastOptionsData","addEventListener","window","PayCentral","sendPostMessage","fireSubmit","dvUrl","getTargetOrigin","origin","warn","receivePostMessage","paymentMethodChanged","pmInstance","setup","UseDatavault","HasFrame","HasPaymentMethod","DoEnrollment","HasRequiredFieldErrors","isUKDD","updateJson","dvurl","handleFrameUnresponsive","contentWindow","postMessage","disablePage","data","startsWith","handlePingResponse","clearMessages","message","parsePostMessageEventData","actionCode","json","TokenizationSuccessful","threeDSCode","threeDsTransId","dataVaultCaptureResult","toLowerCase","iatsIssuerChallenge","response","isAuthenticated","handle3dsComplete","handleError","errors","ThreeDsSdk","display3dsChallenge","threeDsId","enablePage","dataArray","split","contentArray","toUpperCase","parse","error","challenge","group","iats3ds","getChallenge","clientID","sdkChallengePayload","success","info","authId","errorMessage","groupEnd","querySelector","findFrame","setContext","obj","isCreditCard","cardholderNameFromInput","getCardholderNameFromInputField","payload","DvGatewayID","GatewayId","GatewayProvider","GatewayName","IsRecurring","getIsRecurring","AccountType","getBankAccountType","Amount","getAmount","Currency","IatsAgentCode","PayCentralUiUrl","supports3DS","supports3Ds","utilize3Ds","paymentRequestOptions","paymentRequestData","getPaymentRequestData","currency","provider","updateAddress","replace","addressInput","showValidation","msg","isHtml","messagecontainer","getMessageContainer","div","createElement","style","marginBottom","span","innerHTML","textContent","setAttribute","appendChild","concat","ModuleTarget","lastElementChild","remove","hasRequiredFieldErrors","ret","creditCardPanelVisible","jQuery","find","is","bankDraftPanelVisible","creditCardPanel","requiredElements","each","_x","bankDraftPanel","enableSubmitButton","saveButton","disabled","hasSelectedPaymentMehtod","HasUpdatedAddress","Type","handleEnrollmentSubmit","isUKDirectDebit","panel","select","selectedOption","getAttribute","threeDsCode","onclick","click","event","CustomEvent","bubbles","dispatchEvent","handleCommandButton","button","buttonOnClick","_this2","Page_ClientValidate","Page_BlockSubmit","status","tagName","selectedValue","selectedOptions","option","getSelectedPaymentInstrumentData","paymentMethodSelectorElement","pm","paymentInstrument","ProviderId","ProviderType","_this$supports3DS","Provider","Supports3Ds","Utilize3Ds","getDataVaultJsonElementValue","dataVaultJsonElement","attempt","_unused","amount","getElementById","innerText","indexOf","accountTypeDropdown","isRecurringElement","convertToBool","cardholderNameElement","selectedMethod","payer","BillingAddress","CardholderName","PaymentInstrument","Card","ContactName","MethodData","RetainOnSuccess","TransactionDetails","Payer","PayerEmail","PayerPhone","Total","CurrencyCode","Order","OrderId","OrderTotal","ProcessingModel","ShippingAddress","Merchant","TenantId","MerchantOrigin","location","Options","CaptureMode","PurchaseFlow","ProcessingFlow","Recurring","Request3DS","_this$findFrame","iframeurl","dvdomain","match","refreshOptions","dvJson","PartnerOrigin","buildTargetSrc","customCss","custom3DS","buildAndAddWidget","_this3","targetElement","iframe","id","width","height","marginLeft","border","display","hide","referrerPolicy","scrolling","addModule","monitorFrameContent","RemoveWidget","matchingElements","getElementsByName","iframeElement","prepend","CreateUI","optionsData","deepClone","useDisableCheckout","_jQuery","val","createOverlay","destroyOverlay","_this4","processingPaymentMessage","element","overlaySeq","className","body","overlayHandler","mutationList","observer","_iterator","_step","mutation","addedNodes","some","is3dsOverlay","hideOverlay","removedNodes","showOverlay","areValidationErrors","err","MutationObserver","observe","childList","_this$overlay","modal","backdrop","keyboard","_this$overlay2","_this$overlay3","_this$overlay4","disconnect","_monitorFrameContent","_callee","valid","_callee$","_context","ping","_ping","_callee2","_this5","timeout","_callee2$","_context2","reject","registerPingHandler","setTimeout","t0","clearTimeout","destroyPingHandler","action","active","findIndex","splice","substring","handler"],"sourceRoot":""}