function PaymentInitialise(n,t){t=new AppViewModel(n,t);ko.applyBindings(t,document.getElementById("paymentSection"));n=new ReturnBarModel(n);ko.applyBindings(n,document.getElementById("returnBar"));$("#paymentSection").show();$("#surchargeDisplayModal").modal({show:!1});$("#whatiscvnModal").modal({show:!1});$("#instalmentsSummaryModal").modal({show:!1});$("#paymentReviewModal").modal({show:!1,backdrop:"static"})}function AppViewModel(n,t){var i=this;i.AppState=ko.observable(GetInitialState(n,t));i.HideBillerCode=n.HideBillerCode;i.IsPaymentPlan=void 0!=n.IsPaymentPlan?n.IsPaymentPlan:!1;i.MerchantTradingName=n.MerchantTradingName;i.RequiresSession=n.RequiresSession;i.IsFixed=n.IsFixed;i.Biller=ko.observable(new BillerViewModel(n,n.Biller));i.BillerList=ko.observableArray();i.MultipleBillers=!1;null!=n.BillerList&&1<n.BillerList.length&&(i.MultipleBillers=!0,t=ko.utils.arrayMap(n.BillerList,function(t){return new BillerViewModel(n,t)}),i.BillerList(t));i.Amount=new AmountViewModel(n);i.SurchargeAmount=new AmountViewModel(n,GetDefaultAmoutOverrides("SurchargeAmount","Surcharge Amount",!0));i.TotalAmount=new AmountViewModel(n,GetDefaultAmoutOverrides("TotalAmount","Total Amount (inc. surcharge)",!1));i.PaymentPlanAmount=new AmountViewModel(n,GetDefaultAmoutOverrides("PaymentPlanAmount","Total amount today",!1));i.IsPaymentPlanInstalment=ko.observable(!1);i.PaymentPlanNumOfPayments=ko.observable("");i.PaymentPlanNextAmount=new AmountViewModel(n,GetDefaultAmoutOverrides("PaymentPlanNextAmount","Next payment amount",!1));i.PaymentPlanNextPaymentDate=ko.observable("");i.PaymentPlanRemainingAmount=new AmountViewModel(n,GetDefaultAmoutOverrides("PaymentPlanRemainingAmt","Outstanding amount owing",!1));i.IsSurcharge=ko.observable(!1);i.SurchargeLastUpdate=ko.observable("");i.SurchargeLocal=ko.observableArray();i.SurchargeInternational=ko.observableArray();SetSurchargeDetails(i,n);i.MerchantCurrencySymbol=n.MerchantCurrencySymbol;i.PaymentOption=ko.observable("");i.PaymentPlanOptionId=ko.observable(0);i.PaymentPlanOptionKey=ko.observable("");i.PaymentPlanInterval=ko.observable(-1);i.PaymentPlanOptionName=ko.observable("");i.ModalNumOfRemainingPayments=ko.observable("");i.ModalFirstAmount=ko.observable("");i.ModalNextPaymentDate=ko.observable("");i.ModalRepaymentAmount=ko.observable("");i.AppState().Current===Constants.PaymentState.CardEntry&&i.PaymentOption("card");i.DeferredPaymentOption=ko.observable("");i.PayLaterDate=ko.observable("");i.PayLater=!1;i.HidePayLaterDate=ko.observable(!1);i.CardNumber=ko.observable("");i.ExpiryMonth=ko.observable(n.ExpiryMonth);i.ExpiryYear=ko.observable(n.ExpiryYear);i.DisplayExpiryDate=ko.observable(n.DisplayExpiryDate);i.CVN=ko.observable("");i.DisplayCardNumber=ko.observable("");i.IsTokenPayment=n.IsTokenPayment;i.TypedCardLogoName=ko.observable("");i.TypedCardLogo=ko.computed(function(){var n=Helpers.GetCardTypeDisplay(i.CardNumber());return Helpers.IsNullOrEmptyString(n)?(i.TypedCardLogoName(""),!1):(i.TypedCardLogoName(n),!0)});i.StoreCard=ko.observable(n.StoreCard);i.ShowStoreCard=ko.observable(n.ShowStoreCard);i.WalletDetails=ko.observable(null);i.SelectedWalletName=ko.observable("");i.HasApplepayWallet=ko.observable(!1);i.DirectDebitAllowed=!1;i.BankAccountVisible=n.BankAccountVisible;i.APCAUserId=n.APCAUserId;i.APCAUserName=n.APCAUserName;i.BSBNumber=ko.observable("");i.DEAccountNumber=ko.observable("");i.DisplayDEAccountNumber=ko.observable("");i.AccountName=ko.observable("");i.BSBName=ko.observable("");i.StoredBSBNumber=ko.observable("");i.PaymentPlanSummaries=ko.observableArray();i.SelectedPaymentPlanOption=ko.observable("");i.TermsAndConditionsCCUrl=n.TermsAndConditionsCCUrl;i.TermsAndConditionsBAUrl=n.TermsAndConditionsBAUrl;i.SelectedPaymentPlanOptionName=ko.observable(i.SelectedPaymentPlanOption()?i.SelectedPaymentPlanOption.PlanName:"");i.StoredCardBin="";i.ShowCaptcha=ko.observable(!1);i.KlarnaLoading=ko.observable(!1);i.KlarnaLoaded=ko.observable(!1);i.KlarnaCanProceed=ko.observable(!1);i.IsTokenPayment&&(i.CardNumber(n.DisplayCardNumber),i.SurchargeAmount.Value(n.SurchargeAmount),i.TotalAmount.Value(n.TotalAmount));n.IsWalletPayment&&(i.AppState().Current=Constants.PaymentState.CardEntry,i.PaymentOption("wallet"),n.Biller.DeferredPayment&&(i.DeferredPaymentOption("PayNow"),i.Biller().PayNow(!0)),ko.utils.arrayForEach(i.Biller().Crns(),function(n){n.ValueEntered(!0)}),GetWalletDetails(i),0>=$("#errorSection").children().length&&!1===n.IsWalletCancel&&ValidatePaymentAndProceed(i));i.EmailAddress=ko.observable("");i.EmailAddressConfirm=ko.observable("");i.EmailAddressDisabled=!this.IsPaymentPlan;i.AcceptPaymentPlanCCAgreement=ko.observable(!1);i.AcceptPaymentPlanBAAgreement=ko.observable(!1);i.IsPaymentPlan&&(i.Biller().DeferredPayment=!1,i.Biller().ShowWallets(!1),i.Biller().PayNow(!0),i.PayLater=!1,i.HasApplepayWallet=ko.computed(function(){return i.Biller().Wallets()&&0<i.Biller().Wallets().length&&i.Biller().Wallets().find(function(n){return"applepay"==n.Name})?!0:!1}));i.BackButtonUrl=n.BackButtonUrl;i.RetryPaymentUrl=$("#RetryPaymentUrl").val();i.AuthenticateTxn=InitialiseAuthenticateTxn();i.ValidateCrn=function(n,t){return Helpers.ButtonPressed(t)&&ValidateCrnAndProceed(i),!0};i.PaymentOptionSelection=function(n,t){return Helpers.ButtonPressed(t)&&(i.IsPaymentPlan?(Helpers.ClearFieldErrors(),ApplyNextState(i)):i.Biller().PayLater()?ValidatePayLaterDateAndProceed(i):(""!=i.PaymentOption()||i.BankAccountVisible||i.DirectDebitAllowed||i.Biller().ShowWallets()||i.PaymentOption("card"),ValidateAmountAndProceed(i))),!0};i.DeferredPaymentOptionSelection=function(n,t){return Helpers.ButtonPressed(t)&&ValidateAmountAndProceedToDPSelection(i),!0};i.GetPaymentPlanSummaries=function(n,t){return Helpers.ButtonPressed(t)&&ValidateAmountAndProceedToPPSelection(i),!0};i.PaymentPlanOptionSelection=function(n,t){return Helpers.ButtonPressed(t)&&(i.SelectedPaymentPlanOption(n),i.SelectedPaymentPlanOptionName=n.PlanName,i.PaymentPlanAmount.Value(n.FirstAmount),i.IsPaymentPlanInstalment(n.IsSchedule),i.PaymentPlanNumOfPayments(n.NumOfRemainingPayments),i.PaymentPlanNextAmount.Value(n.RepaymentAmount),i.PaymentPlanNextPaymentDate(n.NextPaymentDate),i.PaymentPlanRemainingAmount.Value(n.RemainingAmount),i.PaymentPlanOptionId(n.PlanOptionId),i.PaymentPlanOptionKey(n.PlanOptionKey),i.PaymentPlanInterval(n.Interval),i.PaymentPlanOptionName(n.PlanName),ApplyNextState(i)),!0};i.ShowPaymentPlans=ko.computed(function(){return"PaymentPlanEntry"==i.AppState().Current||"PaymentMethodEntry"==i.AppState().Current||"PaymentFormEntry"==i.AppState().Current});i.bankAccountAvailable=ko.computed(function(){return i.APCAUserId&&i.APCAUserName});i.BackButtonClick=function(n,t){return Helpers.ButtonPressed(t)&&(i.AppState().Initial===i.AppState().Current&&i.BackButtonUrl?UrlFactory.RedirectUrl(i.BackButtonUrl):ApplyPreviousState(i)),!0};i.PreventDefault=function(){return!1};i.ShowHelpText=ko.observable(!1);i.ToggleHelpText=function(n,t){return n=Helpers.ToggleToolTip(t),"boolean"==typeof n&&i.ShowHelpText(n),!0};i.ShowBSBName=function(){return GetBSB(i),!0};i.BackToBillerEntry=function(n,t){return Helpers.ButtonPressed(t)&&UrlFactory.RedirectUrl(window.location.href),!0};i.ShowInstalmentsSummaryModal=function(n,t){Helpers.ButtonPressed(t)&&(i.ModalNumOfRemainingPayments(parseInt(n.NumOfRemainingPayments)+1),i.ModalFirstAmount(i.MerchantCurrencySymbol+" "+n.FirstAmount),i.ModalNextPaymentDate(n.NextPaymentDate),i.ModalRepaymentAmount(i.MerchantCurrencySymbol+" "+n.RepaymentAmount),$("#instalmentsSummaryModal").modal("show"))};i.HideInstalmentsSummaryModal=function(n,t){Helpers.ButtonPressed(t)&&$("#instalmentsSummaryModal").modal("hide")};i.ShowSurchargeModal=function(){$("#surchargeDisplayModal").modal("show")};i.HideSurchargeModal=function(){$("#surchargeDisplayModal").modal("hide")};i.ShowCvnModal=function(){$("#whatiscvnModal").modal("show")};i.HideCvnModal=function(){$("#whatiscvnModal").modal("hide")};i.CalculateSurcharge=function(){if(i.CardNumber(i.CardNumber().replace(/\D/g,"")),!1===i.IsSurcharge())return!0;if(8<=i.CardNumber().length){var n=i.CardNumber().substring(0,8);if(i.StoredCardBin===n)return!0;i.StoredCardBin=n;GetSurchargeAmount(i)}else i.StoredCardBin="",i.SurchargeAmount.Value(""),i.TotalAmount.Value("")};i.CreditCardDetailsComplete=function(){i.CalculateSurcharge();InitiateAuthenticationTxn(i)};i.ProcessWalletCheckout=function(n,t){if(Helpers.ButtonPressed(t))switch(i.SelectedWalletName()){case"cup":i.ProcessUnionPay(n,t);break;case"masterpass":i.ProcessMasterPass(n,t);break;case"applepay":$("#paymentReviewModal").modal("show");break;case"amexwallet":$amex.aec.authorize();break;case"klarna":i.ProcessKlarnaCheckout(n,t)}return!0};i.ProcessMasterPass=function(n,t){return Helpers.ButtonPressed(t)&&($("#mask").show(),UrlFactory.RedirectUrl(i.WalletDetails().MasterPassUrl)),!0};i.ProcessUnionPay=function(n,t){return Helpers.ButtonPressed(t)&&ProcessUnionPayRequest(i),!0};i.ProcessKlarnaInit=function(n,t){return i.KlarnaLoading()?!0:(Helpers.ButtonPressed(t)&&(i.AppState(new StateModel(i.AppState().Initial,Constants.PaymentState.KlarnaCheckout)),InitiateKlarnaRequest(i)),!0)};i.ProcessKlarnaCheckout=function(n,t){return Helpers.ButtonPressed(t)&&KlarnaCheckout(i),!0};i.UpdateSessionForStoreCard=function(n,t){return Helpers.ButtonPressed(t)&&(n="storeCard="+n.StoreCard(),$.post({dataType:"json",url:UrlFactory.GetUrl(Constants.UrlName.UpdateSessionForStoreCard),data:n,beforeSend:function(){$("#btnProcessPayment").buttonState("loading")},success:function(){$("#btnProcessPayment").buttonState("reset")},error:function(){UrlFactory.RedirectToError()}})),!0};i.ReviewPayment=function(n,t){if(Helpers.ButtonPressed(t)){if("applepay"==this.PaymentOption())return ValidateApplepayPaymentAndProceed(i),GetWalletDetails(i),!0;ValidatePaymentAndProceed(i)}return!0};i.CancelReviewPayment=function(n,t){return Helpers.ButtonPressed(t)&&$("#paymentReviewModal").modal("hide"),!0};i.ProcessPayment=function(n,t){return Helpers.ButtonPressed(t)&&ProcessPayment(i),!0};SetDeviceInformation(i);window.addEventListener("message",function(n){var t=window.location.href.split("/");n.origin===t[0]+"//"+t[2]&&"ChallengeResponseReceived"===n.data&&(i.AuthenticateTxn.ShowChallengeIframe(!1),i.AuthenticateTxn.Stage=AuthenticateTxnStage.Complete,ProcessPayment(i))},!1)}function InitialiseAuthenticateTxn(){return{CardNumber:null,ExpiryDate:null,Stage:AuthenticateTxnStage.RequiresInitialise,InitialHtml:ko.observable(""),ChallengeHtml:ko.observable(""),ChallengeHtmlStaging:"",ShowChallengeIframe:ko.observable(!0),Initiating:!1,CallValidatePaymentAndProceedAfterInitiate:!1}}function ReturnBarModel(n){this.ReturnBar=n.ReturnBar}function GetInitialState(n,t){return t=Helpers.IsNullOrEmptyString(t)?Constants.PaymentState.CrnEntry:t,t=new StateModel(t,Constants.PaymentState.CrnEntry),null==n.BillerList&&AllCrnsSupplied(n)&&(t.Current=Constants.PaymentState.AmountEntry,t.Initial=Constants.PaymentState.AmountEntry,!n.AmountReadOnly||null!==n.Biller&&n.Biller.DeferredPayment||(t.Current=Constants.PaymentState.CardEntry,t.Initial=Constants.PaymentState.CardEntry)),t}function AllCrnsSupplied(n){var t=n.Biller.AcceptedCrns.length;return 1===t?n.Crn1Properties.ReadOnly:2===t?n.Crn1Properties.ReadOnly&&n.Crn2Properties.ReadOnly:3===t?n.Crn1Properties.ReadOnly&&n.Crn2Properties.ReadOnly&&n.Crn3Properties.ReadOnly:!1}function GetNextState(n){var i=n.AppState(),t=new StateModel(i.Initial,i.Current);switch(i.Current){case Constants.PaymentState.CrnEntry:t.Current=Constants.PaymentState.AmountEntry;n.IsPaymentPlan||!n.Amount.HideInput()||n.Biller().DeferredPayment||(n.PaymentOption("card"),t.Current=Constants.PaymentState.CardEntry);break;case Constants.PaymentState.AmountEntry:t.Current=n.IsPaymentPlan?Constants.PaymentState.PaymentPlanEntry:Constants.PaymentState.CardEntry;break;case Constants.PaymentState.PaymentPlanEntry:t.Current=Constants.PaymentState.PaymentMethodEntry;break;case Constants.PaymentState.PaymentMethodEntry:t.Current=Constants.PaymentState.PaymentFormEntry}return t}function ApplyNextState(n){var t=GetNextState(n);n.AppState(t)}function GetPreviousState(n){var i=n.AppState(),t=new StateModel(i.Initial,i.Current);switch(i.Current){case Constants.PaymentState.AmountEntry:""!==n.DeferredPaymentOption()?(ResetDeferredPaymentOptions(n),n.Amount.ValueEntered(!1)):(t.Current=Constants.PaymentState.CrnEntry,ResetCrnDetails(n));break;case Constants.PaymentState.PaymentPlanEntry:n.Amount.ValueEntered(!1);t.Current=Constants.PaymentState.AmountEntry;break;case Constants.PaymentState.PaymentMethodEntry:SetPaymentPlanSummaries(n);t.Current=Constants.PaymentState.PaymentPlanEntry;break;case Constants.PaymentState.PaymentFormEntry:t.Current=Constants.PaymentState.PaymentMethodEntry;ResetCardDetails(n);break;case Constants.PaymentState.CardEntry:t.Current=Constants.PaymentState.AmountEntry;n.Amount.ReadOnly&&!n.Biller().DeferredPayment&&(t.Current=Constants.PaymentState.CrnEntry,ResetCrnDetails(n));ResetCardDetails(n);ResetpayLaterDate(n);break;case Constants.PaymentState.KlarnaCheckout:t.Current=Constants.PaymentState.CardEntry}return t}function ApplyPreviousState(n){var t=GetPreviousState(n);n.AppState(t)}function ResetCrnDetails(n){ko.utils.arrayForEach(n.Biller().Crns(),function(n){n.ValueEntered(!1)})}function ResetCardDetails(n){n.PaymentOption("");""!==n.DeferredPaymentOption()||n.IsPaymentPlan||n.Amount.ValueEntered(!1);n.StoredCardBin="";n.SurchargeAmount.Value("");n.TotalAmount.Value("");n.CardNumber("");n.ExpiryMonth("");n.ExpiryYear("");n.CVN("")}function ResetBADetails(n){n.DEBsbNumber("");n.DEAccountNumber("");n.DisplayDEAccountNumber("");n.AccountName("");n.BSBName("");n.StoredBSBNumber("")}function ResetDeferredPaymentOptions(n){n.DeferredPaymentOption("");n.Biller().PayNow(!1);n.Biller().PayLater(!1);n.HidePayLaterDate(!1);n.Biller().ShowWallets(n.Biller().WalletsMoreThanZero);n.PayLaterDate("")}function BindPayLaterDate(){$("#PayLaterDate").billpayDatepicker({minDate:"+1d",maxDate:"+100y",clearOnInitialise:!0})}function ResetpayLaterDate(n){n.HidePayLaterDate(!1);BindPayLaterDate()}function ValidateCrnAndProceed(n){var t=[],i=n.Biller(),r;Helpers.ClearFieldErrors();ko.utils.arrayForEach(i.Crns(),function(n){n.Mandatory&&Helpers.IsNullOrEmptyString(n.Value())?t.push(new ErrorListObject("Please enter "+n.Name,"CRN"+n.Number)):!1===Helpers.IsValidReference(n.Value(),n.Mandatory)&&t.push(new ErrorListObject(n.Name+" is not valid","CRN"+n.Number))});Helpers.IsShowingErrors(t)||(r=GetPaymentModel(n),$.post({dataType:"json",url:UrlFactory.GetUrl(Constants.UrlName.CrnValidation),data:r,beforeSend:function(){$("#btnValidateCrn").buttonState("loading")},success:function(t){if($("#btnValidateCrn").buttonState("reset"),4===t.Response)window.location.href=t.Data;else if(1===t.Response){var r=t.Data;ko.utils.arrayForEach(i.Crns(),function(n){1===n.Number?n.Value(r.CRN1):2===n.Number?n.Value(r.CRN2):3===n.Number&&n.Value(r.CRN3);n.ValueEntered(!0)});n.ShowStoreCard(r.ShowStoreCard);SetSurchargeDetails(n,r);(r.IsAmountForced||r.IsDiscountPenaltyAmount)&&(r.IsDiscountPenaltyAmount?n.Amount.Value(r.OverrideAmount):n.Amount.Value(r.Amount),r.IsAmountForced&&n.Amount.ValueEntered(!0));ApplyNextState(n)}else Helpers.ShowFieldErrors(t)},error:function(){UrlFactory.RedirectToError()}}))}function ValidateAmountAndProceed(n){var i=n.Amount,t;if(n.AppState().Current===Constants.PaymentState.CardEntry){if("card"===n.PaymentOption()){ResetCardForm(n);ResetWalletForm(n);return}if("wallet"===n.PaymentOption()){n.WalletDetails()||GetWalletDetails(n);ApplyExtrLogicForWallet(n);return}}t=[];Helpers.ClearFieldErrors();Helpers.IsNullOrEmptyString(i.Value())?t.push(new ErrorListObject("Please enter payment amount","Amount")):!1===Helpers.IsValidAmount(i.Value())&&t.push(new ErrorListObject("The payment amount is invalid","Amount"));Helpers.IsShowingErrors(t)?n.PaymentOption(""):(t=GetPaymentModel(n),$.post({dataType:"json",url:UrlFactory.GetUrl(Constants.UrlName.AmountValidation),data:t,success:function(t){4===t.Response?window.location.href=t.Data:1===t.Response?(i.Value(t.Data),"wallet"===n.PaymentOption()?(GetWalletDetails(n),ApplyExtrLogicForWallet(n)):(i.ValueEntered(!0),ApplyNextState(n))):(Helpers.ShowFieldErrors(t),n.PaymentOption(""))},error:function(){UrlFactory.RedirectToError()}}))}function ValidatePayLaterDateAndProceed(n){if(n.AppState().Current===Constants.PaymentState.CardEntry&&"card"===n.PaymentOption())ResetCardForm(n);else{var t=[];Helpers.ClearFieldErrors();Helpers.IsNullOrEmptyString(n.PayLaterDate())&&t.push(new ErrorListObject("Please select Pay On Date","PayLaterDate"));Helpers.IsShowingErrors(t)||(t=GetPaymentModel(n),$.post({dataType:"json",url:UrlFactory.GetUrl(Constants.UrlName.PayLaterDateValidation),data:t,success:function(t){4===t.Response?window.location.href=t.Data:1===t.Response?(n.HidePayLaterDate(!0),ApplyNextState(n)):Helpers.ShowFieldErrors(t)},error:function(){UrlFactory.RedirectToError()}}))}}function InitiateAuthenticationTxn(n){if(Helpers.IsValidNumber(n.CardNumber())&&n.ExpiryMonth()&&n.ExpiryYear()&&n.CVN()){var t=GetPaymentModel(n);n.AuthenticateTxn.Initiating=!0;$.post({dataType:"json",url:UrlFactory.GetUrl(Constants.UrlName.InitiateAuthenticationTxn),data:t,success:function(t){n.AuthenticateTxn.Initiating=!1;4===t.Response?window.location.href=t.Data:(n.RequiresSession=t.Data.RequiresSession,ProcessThreeDSResponse(t.Data,n),n.AuthenticateTxn.CallValidatePaymentAndProceedAfterInitiate&&(n.AuthenticateTxn.CallValidatePaymentAndProceedAfterInitiate=!1,ValidatePaymentAndProceed(n)))},error:function(){UrlFactory.RedirectToError()}})}}function ApplyExtrLogicForWallet(n){n.SelectedWalletName("");var t=n.Biller().Wallets();t&&0<t.length&&(1==t.length&&"klarna"!=t[0].Name?n.SelectedWalletName(t[0].Name):t.find(function(n){return"applepay"==n.Name})&&n.SelectedWalletName("applepay"))}function GetWalletDetails(n){var t=GetPaymentModel(n);n.KlarnaLoaded(!1);n.KlarnaCanProceed(!1);$.post({dataType:"json",url:UrlFactory.GetUrl(Constants.UrlName.WalletDetails),data:t,success:function(t){4===t.Response?window.location.href=t.Data:1===t.Response?(n.WalletDetails(new WalletDetailsModel(t.Data)),n.RequiresSession=!0,n.Amount.ValueEntered(!0),ApplyNextState(n)):(Helpers.ShowFieldErrors(t),n.PaymentOption(""))},error:function(){UrlFactory.RedirectToError()}})}function GetSurchargeAmount(n){var t=n.Amount,i=[];Helpers.ClearFieldErrors();n.SurchargeAmount.Value("");n.TotalAmount.Value("");Helpers.IsNullOrEmptyString(t.Value())?i.push(new ErrorListObject("Please enter payment amount","Amount")):!1===Helpers.IsValidAmount(t.Value())&&i.push(new ErrorListObject("The payment amount is invalid","Amount"));!1===Helpers.IsValidNumber(n.StoredCardBin)&&i.push(new ErrorListObject("The card number is invalid","CardNumber"));Helpers.IsShowingErrors(i)||(t=GetPaymentModel(n),$.post({dataType:"json",url:UrlFactory.GetUrl(Constants.UrlName.CardSurcharge),data:t,success:function(t){4===t.Response?window.location.href=t.Data:1===t.Response?(t=t.Data,n.SurchargeAmount.Value(t.SurchargeAmountDisplay),n.TotalAmount.Value(t.TotalAmountDisplay)):Helpers.ShowFieldErrors(t)},error:function(){UrlFactory.RedirectToError()}}))}function ValidatePaymentAndProceed(n){if(Helpers.ClearFieldErrors(),null!=n.AuthenticateTxn&&n.AuthenticateTxn.Initiating)n.AuthenticateTxn.CallValidatePaymentAndProceedAfterInitiate=!0,$("#btnReviewPayment").buttonState("loading");else{var t=GetPaymentModel(n);$.post({dataType:"json",url:UrlFactory.GetUrl(Constants.UrlName.PaymentDetails),data:t,beforeSend:function(){$("#btnReviewPayment").buttonState("loading")},success:function(t){$("#btnReviewPayment").buttonState("reset");4===t.Response?window.location.href=t.Data:1===t.Response?(t=t.Data,n.DisplayDEAccountNumber(t.DisplayDEAccountNumber),n.DisplayCardNumber(t.DisplayCardNumber),n.IsPaymentPlan&&n.PaymentPlanAmount.Value(t.PaymentPlanAmount),n.IsPaymentPlanInstalment(t.IsPaymentPlanInstalment),n.IsPaymentPlan&&(n.PaymentPlanNumOfPayments(t.PaymentPlanNumOfPayments),n.PaymentPlanNextAmount.Value(t.PaymentPlanNextAmount),n.PaymentPlanNextPaymentDate(t.PaymentPlanNextPaymentDate),n.PaymentPlanRemainingAmount.Value(t.PaymentPlanRemainingAmount),n.PaymentPlanOptionId(t.PaymentPlanOptionId),n.PaymentPlanOptionKey(t.PaymentPlanOptionKey),n.PaymentPlanInterval(t.PaymentPlanInterval),n.PaymentPlanOptionName(t.PaymentPlanOptionName)),n.Amount.Value(t.Amount),n.SurchargeAmount.Value(t.SurchargeAmount),n.TotalAmount.Value(t.TotalAmount),n.ShowStoreCard(t.ShowStoreCard),n.IsPaymentPlan&&t.IsPaymentPlanInstalment&&n.ShowStoreCard(!1),n.RequiresSession=t.RequiresSession,n.ShowCaptcha(t.ShowCaptcha),ProcessThreeDSResponse(t,n),$("#paymentReviewModal").modal("show")):Helpers.ShowFieldErrors(t)},error:function(){UrlFactory.RedirectToError()}})}}function ValidateApplepayPaymentAndProceed(n){Helpers.ClearFieldErrors();var t=GetPaymentModel(n);$.post({dataType:"json",url:UrlFactory.GetUrl(Constants.UrlName.PaymentDetails),data:t,beforeSend:function(){$("#btnReviewPayment").buttonState("loading")},success:function(t){$("#btnReviewPayment").buttonState("reset");4===t.Response?window.location.href=t.Data:1===t.Response?(t=t.Data,n.ShowStoreCard(t.ShowStoreCard),n.IsPaymentPlan&&t.IsPaymentPlanInstalment&&n.ShowStoreCard(!1),$("#paymentReviewModal").modal("show")):Helpers.ShowFieldErrors(t)},error:function(){UrlFactory.RedirectToError()}})}function ProcessThreeDSResponse(n,t){if(n.AuthenticateTxn)switch(t.AuthenticateTxn.Stage=n.AuthenticateTxn.Stage,n.AuthenticateTxn.Stage){case AuthenticateTxnStage.AsyncHtml:t.AuthenticateTxn.InitialHtml(n.AuthenticateTxn.AsyncHtml);break;case AuthenticateTxnStage.Error:UrlFactory.RedirectToError();break;case AuthenticateTxnStage.ChallengeHtml:t.AuthenticateTxn.ChallengeHtmlStaging=n.AuthenticateTxn.ChallengeHtml;break;case AuthenticateTxnStage.Complete:break;default:UrlFactory.RedirectToError()}}function ProcessPayment(n){var t,i;"applepay"==n.SelectedWalletName()?ProcessApplePayRequest(n):"applepay"==n.PaymentOption()?ProcessApplePayRequest(n):(t=GetPaymentModel(n),t.DeviceFingerprint=$("#DeviceFingerprint").val(),i=$("#recaptcha_error"),i.hide(),n.ShowCaptcha()&&!t["h-captcha-response"]?i.show():n.AuthenticateTxn.Stage===AuthenticateTxnStage.ChallengeHtml?($("#paymentReviewModal").modal("hide"),$("#threeDSChallenge").modal("show"),n.AuthenticateTxn.ChallengeHtml(n.AuthenticateTxn.ChallengeHtmlStaging)):$.post({dataType:"json",url:UrlFactory.GetUrl(Constants.UrlName.ProcessPayment),data:t,beforeSend:function(){$("#btnProcessPayment").buttonState("loading")},success:PaymentProcessedSuccessfully,error:function(){UrlFactory.RedirectToError()}}))}function PaymentProcessedSuccessfully(n){0===n.Response?(Helpers.ShowFieldErrors(n),$("#paymentReviewModal").modal("hide"),$("#btnReviewPayment").buttonState("reset"),$("#btnProcessPayment").buttonState("reset")):4===n.Response?window.location.href=n.Data:1===n.Response?(n=new ReceiptViewModel(n.Data),ko.applyBindings(n,document.getElementById("receiptSection")),$("#threeDSChallenge").modal("hide"),$("#btnProcessPayment").buttonState("reset"),$("#paymentReviewModal").modal("hide"),$("#paymentSection").hide(),$("#designerText").hide(),$("#receiptSection").show()):UrlFactory.RedirectToError()}function SchedulePayment(n){n=GetPaymentModel(n);$.post({dataType:"json",url:UrlFactory.GetUrl(Constants.UrlName.SchedulePayment),data:n,beforeSend:function(){$("#btnSchedulePayment").buttonState("loading")},success:function(n){$("#btnSchedulePayment").buttonState("reset");4===n.Response?window.location.href=n.Data:1===n.Response?(n=new ReceiptViewModel(n.Data),ko.applyBindings(n,document.getElementById("receiptSection")),$("#paymentReviewModal").modal("hide"),$("#paymentSection").hide(),$("#designerText").hide(),$("#receiptSection").show()):UrlFactory.RedirectToError()},error:function(){UrlFactory.RedirectToError()}})}function GetPaymentModel(n){var i=n.Biller(),t={RequiresSession:n.RequiresSession,IsFixed:n.IsFixed,BillerCode:i.BillerCode,Amount:n.Amount.Value(),IsPaymentPlan:n.IsPaymentPlan,PaymentPlanAmount:n.PaymentPlanAmount.Value(),IsPaymentPlanInstalment:n.IsPaymentPlanInstalment,PaymentPlanNumOfPayments:n.PaymentPlanNumOfPayments,PaymentPlanNextAmount:n.PaymentPlanNextAmount.Value(),PaymentPlanNextPaymentDate:n.PaymentPlanNextPaymentDate,PaymentPlanRemainingAmount:n.PaymentPlanRemainingAmount.Value(),PaymentPlanOptionId:n.PaymentPlanOptionId,PaymentPlanOptionKey:n.PaymentPlanOptionKey,PaymentPlanInterval:n.PaymentPlanInterval,PaymentPlanOptionName:n.PaymentPlanOptionName,CardNumber:n.CardNumber(),ExpiryMonth:n.ExpiryMonth(),ExpiryYear:n.ExpiryYear(),EmailAddress:n.EmailAddress,EmailAddressConfirm:n.EmailAddressConfirm,AcceptPaymentPlanCCAgreement:n.AcceptPaymentPlanCCAgreement,AcceptPaymentPlanBAAgreement:n.AcceptPaymentPlanBAAgreement,CVC:n.CVN(),CRN1:"",CRN2:"",CRN3:"",DeviceInformation:n.DeviceInformation,PaymentOption:n.PaymentOption(),PayLaterDate:n.PayLaterDate(),PayLater:i.PayLater,RetryPaymentUrl:n.RetryPaymentUrl,"h-captcha-response":$("[name='h-captcha-response']").val(),StoreCard:n.StoreCard};return n.IsPaymentPlan&&"bankaccount"==n.PaymentOption()&&(t.CardNumber="",t.ExpiryMonth="",t.ExpiryYear="",t.CVN="",t.DEBsbNumber=n.BSBNumber,t.DEAccountNumber=n.DEAccountNumber,t.DisplayDEAccountNumber=n.DisplayDEAccountNumber,t.AccountName=n.AccountName),"applepay"==n.SelectedWalletName()&&(t.StoreCard=n.StoreCard),ko.utils.arrayForEach(i.Crns(),function(n){1===n.Number?t.CRN1=n.Value():2===n.Number?t.CRN2=n.Value():3===n.Number&&(t.CRN3=n.Value())}),t}function SetSurchargeDetails(n,t){var i,r,u;n.IsSurcharge(t.IsBillerSurcharge);n.SurchargeLastUpdate(t.SurchargeLastUpdate);n.SurchargeLocal([]);n.SurchargeInternational([]);t.IsBillerSurcharge&&(i=t.SurchargeDisplay,i&&(r=ko.utils.arrayMap(i.LocalCardsSurcharge,function(n){return new SurchargeDisplayViewModel(n,t.MerchantCurrencySymbol)}),u=ko.utils.arrayMap(i.InternationalCardsSurcharge,function(n){return new SurchargeDisplayViewModel(n,t.MerchantCurrencySymbol)}),n.MerchantCountry=i.MerchantCountry,n.SurchargeLocal(r),n.SurchargeInternational(u)))}function ResetCardForm(n){n.CardNumber("");n.ExpiryMonth("");n.ExpiryYear("");n.CVN("");n.SurchargeAmount.Value("");n.TotalAmount.Value("")}function ResetWalletForm(n){n.SelectedWalletName("")}function ValidateAmountAndProceedToDPSelection(n){var i=n.Amount,t=[];Helpers.ClearFieldErrors();Helpers.IsNullOrEmptyString(i.Value())?t.push(new ErrorListObject("Please enter payment amount","Amount")):!1===Helpers.IsValidAmount(i.Value())&&t.push(new ErrorListObject("The payment amount is invalid","Amount"));Helpers.IsShowingErrors(t)?n.DeferredPaymentOption(""):(t=GetPaymentModel(n),$.post({dataType:"json",url:UrlFactory.GetUrl(Constants.UrlName.AmountValidation),data:t,success:function(t){4===t.Response?window.location.href=t.Data:1===t.Response?(i.Value(t.Data),i.ValueEntered(!0),SetDeferredPaymentOptions(n)):(Helpers.ShowFieldErrors(t),n.DeferredPaymentOption(""))},error:function(){UrlFactory.RedirectToError()}}))}function ValidateAmountAndProceedToPPSelection(n){var i=n.Amount,t=[];Helpers.ClearFieldErrors();Helpers.IsNullOrEmptyString(i.Value())?t.push(new ErrorListObject("Please enter payment amount","Amount")):!1===Helpers.IsValidAmount(i.Value())&&t.push(new ErrorListObject("The payment amount is invalid","Amount"));Helpers.IsShowingErrors(t)||(t=GetPaymentModel(n),$.post({dataType:"json",url:UrlFactory.GetUrl(Constants.UrlName.AmountValidation),data:t,success:function(t){4===t.Response?window.location.href=t.Data:1===t.Response?(i.Value(t.Data),i.ValueEntered(!0),n.IsPaymentPlan&&(SetPaymentPlanSummaries(n),ApplyNextState(n))):Helpers.ShowFieldErrors(t)},error:function(){UrlFactory.RedirectToError()}}))}function SetPaymentPlanSummaries(n){var i=[],t;Helpers.ClearFieldErrors();t=n.Amount.Value();t=parseFloat(t.replace(",",""));t="billercode="+n.Biller().BillerCode()+"&amount="+t;$.post({dataType:"json",url:UrlFactory.GetUrl(Constants.UrlName.PaymentPlanSummaries),data:t,success:function(t){4===t.Response?window.location.href=t.Data:1===t.Response?t.Data.PaymentPlanSummaries?(n.PaymentPlanSummaries(t.Data.PaymentPlanSummaries),n.SelectedPaymentPlanOption("")):i.push(new ErrorListObject("Payment plan options are not properly set","PaymentPlan")):(Helpers.ShowFieldErrors(t),n.PaymentPlanSummaries(""))},error:function(){alert("!!");UrlFactory.RedirectToError()}})}function SetDeferredPaymentOptions(n){"PayNow"===n.DeferredPaymentOption()&&(n.Biller().PayNow(!0),n.Biller().PayLater(!1),n.Biller().ShowWallets(n.Biller().WalletsMoreThanZero),""!==n.PaymentOption()&&ApplyPreviousState(n));"PayLater"===n.DeferredPaymentOption()&&(n.Biller().PayLater(!0),n.Biller().PayNow(!1),n.Biller().ShowWallets(!1),""!==n.PaymentOption()&&ApplyPreviousState(n))}function ProcessUnionPayRequest(n){var t=GetPaymentModel(n);t.DeviceFingerprint=$("#DeviceFingerprint").val();$.post({dataType:"json",url:n.WalletDetails().UnionPayUrl,data:t,beforeSend:function(){$("#mask").show()},success:function(n){4===n.Response?window.location.href=n.Data:UrlFactory.RedirectToError()},error:function(){UrlFactory.RedirectToError()}})}function SetDeviceInformation(n){if(!n.DeviceInformation)try{var i=(new Date).getTimezoneOffset(),t=new ClientJS;n.DeviceInformation={Fingerprint:t.getFingerprint(),Browser:t.getBrowser(),BrowserVersion:t.getBrowserVersion(),Engine:t.getEngine(),EngineVersion:t.getEngineVersion(),Os:t.getOS(),OsVersion:t.getOSVersion(),Device:t.getDevice(),DeviceType:t.getDeviceType(),DeviceVendor:t.getDeviceVendor(),Cpu:t.getCPU(),IsMobile:t.isMobile(),ColorDepth:t.getColorDepth(),CurrentResolution:t.getCurrentResolution(),AvailableResolution:t.getAvailableResolution(),DeviceXDPI:t.getDeviceXDPI(),DeviceYDPI:t.getDeviceYDPI(),Plugins:t.getPlugins(),JavaVersion:t.getJavaVersion(),FlashVersion:t.getFlashVersion(),SilverlightVersion:t.getSilverlightVersion(),MimeTypes:t.getMimeTypes(),Fonts:t.getFonts(),IsLocalStorage:t.isLocalStorage(),IsSessionStorage:t.isSessionStorage(),IsCookie:t.isCookie(),TimeZone:t.getTimeZone(),TimeZoneOffset:i,Language:t.getLanguage(),SystemLanguage:t.getSystemLanguage(),IsJavaEnabled:t.isJava()}}catch(r){console.error(r);n.DeviceInformation={}}}function ProcessApplePayRequest(n){var i=GetPaymentModel(n),r=$.extend({},n.WalletDetails().ApplePayPaymentRequest),t;r.total.amount=n.IsPaymentPlan?i.PaymentPlanAmount.replace(",",""):i.Amount.replace(",","");window.ApplePaySession.supportsVersion(3);t=new window.ApplePaySession(2,r);t.onvalidatemerchant=function(n){n={ValidationUrl:n.validationURL};$.post({dataType:"json",url:UrlFactory.GetUrl(Constants.UrlName.StartApplePaySession),data:n,success:function(n){1===n.Response?t.completeMerchantValidation(JSON.parse(n.Data)):(t.abort(),Helpers.ClearFieldErrors(),Helpers.ShowFieldErrors(n))},error:function(){t.abort();UrlFactory.RedirectToError()}})};t.onpaymentauthorized=function(n){n=n.payment;$.post({dataType:"json",url:UrlFactory.GetUrl(Constants.UrlName.ReceiveApplePayEvent),data:{Payment:JSON.stringify(n)},success:function(n){1===n.Response||4===n.Response?(t.completePayment(window.ApplePaySession.STATUS_SUCCESS),PaymentProcessedSuccessfully(n)):(t.completePayment(window.ApplePaySession.STATUS_FAILURE),Helpers.ClearFieldErrors(),Helpers.ShowFieldErrors(n))},error:function(){t.completePayment(window.ApplePaySession.STATUS_FAILURE);UrlFactory.RedirectToError()}})};t.begin()}function LoadKlarnaJs(n){klarnaLoadedCallbacks?(klarnaLoadedCallbacks.push(n),klarnaIsLoading||(klarnaIsLoading=!0,$.getScript("https://x.klarnacdn.net/kp/lib/v1/api.js",function(){for(;klarnaLoadedCallbacks.length;)klarnaLoadedCallbacks.pop()();klarnaLoadedCallbacks=null}))):n()}function InitiateKlarnaRequest(n){n.KlarnaLoaded(!1);n.KlarnaCanProceed(!1);n.KlarnaLoading(!0);var t=GetPaymentModel(n);LoadKlarnaJs(function(){$.post({dataType:"json",url:UrlFactory.GetUrl(Constants.UrlName.InitiateKlarna),data:t,success:function(t){t.ClientToken?(n.KlarnaDetails=t,KlarnaInit(t,n)):UrlFactory.RedirectToError()},error:function(){UrlFactory.RedirectToError()}})})}function ProcessKlarnaRequest(){$.post({dataType:"json",url:UrlFactory.GetUrl(Constants.UrlName.ProcessKlarna),success:function(n){1===n.Response?PaymentProcessedSuccessfully(n):UrlFactory.RedirectToError()},error:function(){UrlFactory.RedirectToError()}})}function KlarnaInit(n,t){$("#btnProcessKlarna").buttonState("reset");try{Klarna.Payments.init({client_token:n.ClientToken});n.PaymentMethodCategories.filter(function(n){return"pay_later"===n.Indentifier})?(t.KlarnaLoading(!1),t.KlarnaLoaded(!0),Klarna.Payments.load({container:"#klarnaWidget",payment_method_category:"pay_later"},function(n){t.KlarnaLoaded(!0);t.KlarnaCanProceed(!!n.show_form)})):(console.error("Missing paymentMethodCategory of pay_later",n.PaymentMethodCategories),UrlFactory.RedirectToError())}catch(i){console.error(i);UrlFactory.RedirectToError()}}function KlarnaCheckout(n){$("#btnProcessKlarna").buttonState("loading");try{Klarna.Payments.authorize({payment_method_category:"pay_later"},function(t){t.approved?ProcessKlarnaRequest(n):t.show_form&&$("#btnProcessKlarna").buttonState("reset")})}catch(t){console.error(t);UrlFactory.RedirectToError()}}var $jscomp=$jscomp||{},klarnaIsLoading,klarnaLoadedCallbacks;$jscomp.scope={};$jscomp.findInternal=function(n,t,i){var f,r,u;for(n instanceof String&&(n=String(n)),f=n.length,r=0;r<f;r++)if(u=n[r],t.call(i,u,r,n))return{i:r,v:u};return{i:-1,v:void 0}};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(n,t,i){n!=Array.prototype&&n!=Object.prototype&&(n[t]=i.value)};$jscomp.getGlobal=function(n){return"undefined"!=typeof window&&window===n?n:"undefined"!=typeof global&&null!=global?global:n};$jscomp.global=$jscomp.getGlobal(this);$jscomp.polyfill=function(n,t,i,r){if(t){for(i=$jscomp.global,n=n.split("."),r=0;r<n.length-1;r++){var u=n[r];u in i||(i[u]={});i=i[u]}n=n[n.length-1];r=i[n];t=t(r);t!=r&&null!=t&&$jscomp.defineProperty(i,n,{configurable:!0,writable:!0,value:t})}};$jscomp.polyfill("Array.prototype.find",function(n){return n?n:function(n,t){return $jscomp.findInternal(this,n,t).v}},"es6","es3");klarnaIsLoading=!1;klarnaLoadedCallbacks=[]