STRATUS.registerNamespace("STRATUS.Payment");STRATUS.Payment=function(){var n=function(){var n;return $.ajax({method:"GET",url:STRATUS.Config.SiteUrl+"/Giving/GetPaymentsInjectionToken",headers:{"Cache-Control":"no-cache"},cache:!1,async:!1,success:function(t){n=t.RequestToken}}),n};return{getRequestToken:n}}();STRATUS.registerNamespace("STRATUS.Payment.PaymentMethod");STRATUS.Payment.PaymentMethod=function(){let n;const u=function(n){return $.ajax({url:STRATUS.Config.SiteUrl+"/Giving/GetPaymentMethods",data:n})},f=function(n){return $.ajax({url:STRATUS.Config.SiteUrl+"/Giving/GetPaymentMethodsById",data:n})},e=function(n){return $.when(STRATUS.Payment.PaymentMethod.getPaymentMethods(n)).then(function(n){let t=[];if(n.length>1)t.push({Text:"Select a saved account",Value:"",Selected:!0});n.forEach(function(n){let i={Text:n.Description,Value:n.PaymentMethodId,Selected:t.length===0,Data:{PaymentMethodType:n.PaymentMethodType}};t.push(i)});let i=$("#payment-method-list");return i.after('<a id="add-payment-method-link" href="javascript:void(0);" data-allow-null="false">+ Add New Payment Method<\/a>'),i.data("list",t).data("placeholder","No saved accounts").selectList(),n})},i=function(n){let t=[],i=n.val();return n.children("option").each(function(){let n=$(this);t.push({Value:n.val(),Text:n.text(),Selected:i===n.val()})}),t.length>0&&!i&&(t[0].Selected=!0),t},o=function(n){let t=$($.trim(n));return $("*",t).removeAttr("style"),$("#AcsPayments_submitAndCancel",t).hide(),$(".AcsPayments-inputGroup",t).each(function(){$(this).wrapAll("<li />")}),$(".AcsPayments-inputGroup > label",t).each(function(){$(this).nextAll().wrapAll('<div class="fields" />')}),$("#AcsPayments_billingProvince, #AcsPayments_billingCountryCode",t).addClass("required"),s(t),h(t),t},s=function(n){$("#AcsPayments_CheckingRoutingNumberInfoHoverDetail,  #AcsPayments_CheckingAccountNumberInfoHoverDetail",n).addClass("hidden");$("#AcsPayments_CheckingRoutingNumberInfoHover",n).remove();$("#AcsPayments_creditCardLogos",n).addClass("fields-aside").insertAfter($("#AcsPayments_accountNumber > .fields",n));$("#AcsPayments_CheckingAccountNumberInfoHover",n).insertAfter($("#AcsPayments_accountNumber > label",n));$("#AcsPayments_CheckingAccountNumberInfoHoverPopup",n).insertAfter($("#AcsPayments_vanco_accountnumber_iFrame",n));$(".AcsPayments-hoverCloseButton",n).addClass("button button-secondary")},h=function(n){$("#ch",n).change(function(){$("#AcsPayments_vanco_name",n).val($("#ch",n).val())});let t=$("#AcsPayments_vanco_accounttype",n);t.change(function(){switch($(this).val()){case"CC":$("#AcsPayments_name",n).closest("li").addClass("hidden");$("AcsPayments_billingCountryCode, #AcsPayments_billingProvince",n).closest("li").removeClass("hidden");break;case"C":case"S":$("#AcsPayments_CheckingAccountNumberInfoHover",n).css({display:"inline-block","margin-left":"10px"});$("#AcsPayments_name",n).parent().removeClass("hidden");$("AcsPayments_billingCountryCode, #AcsPayments_billingProvince",n).closest("li").addClass("hidden")}});let i=$("#AcsPayments_vanco_billingcountrycode",n);i.change(function(){$("#AcsPayments_vanco_billingaddr1, #AcsPayments_vanco_billingaddr2, #AcsPayments_billingState, #AcsPayments_vanco_billingzip, #AcsPayments_billingProvince",n).closest("li").addClass("hidden");switch($(this).val()){case"US":$("#AcsPayments_vanco_billingaddr1, #AcsPayments_vanco_billingaddr2, #AcsPayments_billingState, #AcsPayments_vanco_billingzip",n).closest("li").removeClass("hidden");break;case"CA":$("#AcsPayments_vanco_billingaddr1, #AcsPayments_vanco_billingaddr2, #AcsPayments_vanco_billingzip, #AcsPayments_billingProvince",n).closest("li").removeClass("hidden");default:$("#AcsPayments_vanco_billingcity",n).closest("li").removeClass("hidden")}});t.trigger("change");i.trigger("change")},c=function(t){let i=n.IndividualModel;t.find("#AcsPayments_vanco_addedByStaff").val(n.AddedByStaff);i?($("#ch",t).val(i.Label),$("#AcsPayments_vanco_name",t).val(i.Label),i.PrimaryAddress!=null&&($("#AcsPayments_vanco_billingcountrycode",t).selectList("setValue",i.PrimaryAddress.Country),$("#AcsPayments_vanco_billingaddr1",t).val(i.PrimaryAddress.Address1),$("#AcsPayments_vanco_billingaddr2",t).val(i.PrimaryAddress.Address2),$("#AcsPayments_vanco_billingcity",t).val(i.PrimaryAddress.City),$("#AcsPayments_vanco_billingstate",t).val(i.PrimaryAddress.Region),$("#visible_AcsPayments_vanco_billingstate",t).selectList("setValue",i.PrimaryAddress.Region),$("#AcsPayments_vanco_billingzip",t).val(i.PrimaryAddress.PostalCode),$("#AcsPayments_vanco_billingprovince",t).val(i.PrimaryAddress.Region)),$("#AcsPayments_vanco_email",t).val(i.PrimaryEmail),$("#AcsPayments_vanco_savepaymentmethod",t).prop("checked",!0)):$("#AcsPayments_savedAccountSection",t).hide()},l=function(t){STRATUS.Helpers.hideProcessingMessage();t&&!t.IsDemoMerchant&&t.Success&&t.Data&&t.Data.PaymentMethodId?(t.Data.PaymentTypeEnum=a(t),STRATUS.Helpers.executeCallback(function(){n.paymentMethodAddedCallback(t)})):(v(),t.Data&&t.Data.ErrorMessage?STRATUS.Validation.setMessage(t.Data.ErrorMessage):t.Data&&t.Data.ExceptionMessage?STRATUS.Validation.setMessage(t.Data.ExceptionMessage):t.IsDemoMerchant||STRATUS.Validation.setMessage("An error has occurred."))},a=function(n){let t;switch(n.Data.PaymentMethodType){case"Checking":t=0;break;case"Savings":t=1;break;case"Credit":t=2;break;case"Debit":t=3;break;default:t=0}return t},v=function(){let t={url:n.PaymentInjectionUrl+"/PaymentMethod/AddPaymentMethodFormVariables",beforeAjaxCallback:function(){return{userName:n.PaymentInjectionUserName,requestToken:STRATUS.Payment.getRequestToken(),merchantId:n.MerchantId}},afterInjectedCallback:function(n){$("#AcsPayments_vanco_nvpvar").val(n.Data.Nvpvar);$("#AcsPayments_vanco_acsrequestid").val(n.Data.AcsRequestId)}};$("#addVariables").inject(t)},t=function(n,t){n=$(n,t).addClass("hidden");let r=n.attr("id"),u="visible_"+r;n.after('<div id="'+u+'" class="select-list field-list AcsPayments-input" data-allow-null="false"><\/div>');$("#"+u,t).data("list",i(n)).data("changeCallback",function(n){$("select#"+r).val(n).change()}).selectList()},y=function(n){let t=$("select#cxm",n).addClass("hidden"),r=$("select#cxy",n).addClass("hidden");t.addClass("js-expiration-month").after('<div id="visible_expireMonth" class="select-list field-list AcsPayments-input js-expiration-month field-width-50" data-allow-null="false"><\/div>');$("#visible_expireMonth",n).data("list",i(t)).data("fixed",!0).data("changeCallback",function(){$("select#cxm").val($(this).selectList("getValue")).change()}).selectList();$("#visible_expireMonth",n).next(".dropdown").addClass("js-expiration-month");r.addClass("js-expiration-year").after('<div id="visible_expireYear" class="select-list field-list AcsPayments-input js-expiration-year field-width-75" data-allow-null="false"><\/div>');$("#visible_expireYear",n).data("list",i(r)).data("fixed",!0).data("changeCallback",function(){$("#cxy").val($(this).selectList("getValue")).change()}).selectList();$("#visible_expireYear",n).next(".dropdown").addClass("js-expiration-year");$("span.controls",n).wrapInner('<ul class="horizontal-fields expiration-date-row"><\/ul>');$(".js-expiration-month",n).wrapAll("<li><\/li>");$(".horizontal-fields.expiration-date-row",n).contents().filter(function(){return this.nodeType===3}).wrap('<li class="field-text"><\/li>');$(".js-expiration-year",n).wrapAll("<li><\/li>");t.closest("li",n).prev("li.field-text").remove();r.closest("li",n).next("li.field-text").remove()},p=function(n){t("select#AcsPayments_vanco_accounttype",n);t("select#AcsPayments_vanco_billingstate",n);t("select#AcsPayments_vanco_billingprovince",n);t("select#AcsPayments_vanco_billingcountrycode",n);y(n)},w=function(){return{cancelUrl:STRATUS.Config.SiteUrl,userName:n.PaymentInjectionUserName,requestToken:STRATUS.Payment.getRequestToken(),solutionId:n.PaymentSolutionId,merchantId:n.MerchantId,customerId:n.IndividualModel?n.IndividualModel.MintCustomerId:null,isDebitOnly:n.IsDebitOnly,allowCreditCard:n.AllowCreditCard,allowAch:n.AllowAch,validateOnSubmitOnly:!0,errorValidationClass:"field-validation-error",includeFieldNamesInValidation:!0,requireBillingFields:!1,defaultExpirationDate:!1}},r=function(){d()&&(STRATUS.Helpers.showProcessingMessage(),AcsPayments.AddPaymentMethodForm.SubmitToVancoAjax(l))},b=function(){$(n.addButtonId).unbind("click").click(function(){r()})},k=function(t){n=t;$(n.formWrapperId).html("");let i={url:n.PaymentInjectionUrl+"/PaymentMethod/AddPaymentMethodForm",beforeAjaxCallback:function(){return w()},beforeInjectedCallback:function(t){let i=n.beforeInjected?n.beforeInjected(t):o(t);return p(i),c(i),i},afterAjaxFailureCallback:function(n){STRATUS.Validation.setMessage(n.Message)},afterInjectedCallback:function(){AcsPayments&&AcsPayments.AddPaymentMethodForm&&AcsPayments.AddPaymentMethodForm.StyleAccountNumber&&AcsPayments.AddPaymentMethodForm.StyleAccountNumber({border:"0 !important",margin:"0 !important","box-shadow":"none !important",outline:"none !important"});b();$("#AcsPayments_vanco_nickname").focus();STRATUS.Helpers.executeCallback(n.formReadyCallback)}};$(n.formWrapperId).inject(i)},d=function(){if(STRATUS.Validation.clearMessage(),!STRATUS.Validation.validateRequiredFields("#AcsPayments_container"))return!1;if(!AcsPayments.AddPaymentMethodForm.ValidateForm()){let n=$("span.AcsPayments-validation").first();return STRATUS.Validation.setMessage(n.text(),{field:n.closest("li")}),n.remove(),!1}let n=$("#staff-understand-agree");return n.length>0&&!n.prop("checked")?(STRATUS.Validation.setMessage("You must agree to the requirements before continuing.",{field:n.closest("div")}),!1):!0};return{getPaymentMethods:u,getPaymentMethodsById:f,getAddPaymentMethodForm:k,getPaymentMethodsAsSelectList:e,submitNewPaymentForm:r}}()