1"use strict";(globalThis.webpackChunksuredonation=globalThis.webpackChunksuredonation||[]).push([[368],{957(e,t,a){a.d(t,{q:()=>r});var n=a(367);const o=["BIF","CLP","DJF","GNF","JPY","KMF","KRW","MGA","PYG","RWF","UGX","VND","VUV","XAF","XOF","XPF"],s=new Map;class r{constructor(e,t){this.block=e,this.form=t,this.currency=e.dataset.currency||"usd",this.currencySymbol=e.dataset.currencySymbol||"$",this.paymentType=e.dataset.paymentType||"one-time",this.paymentMode=e.dataset.paymentMode||"",this._readAmountConfig(),this.customerEmailField=e.dataset.customerEmailField||"",this.customerNameField=e.dataset.customerNameField||"",this.coverFeesChecked=!1,this.feePercentage=0,this.feeFixed=0,this.feeMode="all_gateways",this.gatewayFees={},this.gatewayName=""}async init(){throw new Error("init() must be implemented by gateway")}_readAmountConfig(){this.amountType=this.block.dataset.amountType||"fixed",this.fixedAmount=parseFloat(this.block.dataset.fixedAmount)||0,this.minimumAmount=parseFloat(this.block.dataset.minimumAmount)||0,this.variableAmountField=this.block.dataset.variableAmountField||""}refreshAmountConfig(){this._readAmountConfig()}async createPaymentIntent(e,t){throw new Error("createPaymentIntent() must be implemented by gateway")}async confirmPayment(){throw new Error("confirmPayment() must be implemented by gateway")}getAmount(){return"fixed"===this.amountType?this.toMinorUnits(this.fixedAmount):this.toMinorUnits(this.getVariableAmount())}getVariableAmount(){if(!this.variableAmountField)return 0;const e=this.form.querySelector(`.sd-block.sd-slug-${this.variableAmountField}`);if(e){const t=e.querySelector("input.sd-input-common");if(t){const e=parseFloat(t.value);if(!isNaN(e)&&e>0&&(0===this.minimumAmount||e>=this.minimumAmount))return e}}return 0}toMinorUnits(e){return o.includes(this.currency.toUpperCase())?Math.round(e):Math.round(100*e)}fromMinorUnits(e){return o.includes(this.currency.toUpperCase())?e:e/100}getCustomerEmail(){if(this.customerEmailField){const e=this.form.querySelector(`.sd-block.sd-slug-${this.customerEmailField}`);if(e){const t=e.querySelector("input.sd-input-common");if(t&&t.value)return t.value.trim()}}const e=this.form.querySelector('input[type="email"]');if(e&&e.value)return e.value.trim();const t=this.form.querySelector(".sd-email-block input");return t&&t.value?t.value.trim():""}getCustomerName(){if(this.customerNameField){const e=this.form.querySelector(`.sd-block.sd-slug-${this.customerNameField}`);if(e){const t=e.querySelector("input.sd-input-common");if(t&&t.value)return t.value.trim()}}const e=this.form.querySelector('.sd-input-block input[type="text"]');if(e&&e.value)return e.value.trim();const t=this.form.querySelector(".sd-input-block input");return t&&t.value?t.value.trim():""}appendHoneypot(e){const t=this.form.querySelector('input[name="suredonation_honeypot"]');t&&e.append("suredonation_honeypot",t.value)}isAnonymousDonation(){const e=this.form?.querySelector(".sd-anonymous-donation-block");if(!e)return!1;const t=e.querySelector('input[type="checkbox"]');return!!t&&t.checked}appendAnonymousFlag(e){this.isAnonymousDonation()&&e.append("is_anonymous","1")}appendPaymentMode(e){this.paymentMode&&e.append("payment_mode",this.paymentMode)}async loadGatewayConfig(){const e=this.block.dataset.formId||"";s.has(e)||s.set(e,r.fetchGatewayConfig(e));const t=await s.get(e);return t?(this.applyGatewayConfig(t),t):(s.delete(e),null)}static async fetchGatewayConfig(e){try{const t=window.suredonationPayment?.ajaxUrl||"/wp-admin/admin-ajax.php",a=new URL(t,window.location.href);a.searchParams.set("action","suredonation_gateway_config"),a.searchParams.set("form_id",e);const n=await fetch(a.toString(),{method:"GET",cache:"no-store"});if(!n.ok)return null;const o=await n.json();return o?.success&&o.data?o.data:null}catch{return null}}applyGatewayConfig(e){e.paymentMode&&(this.paymentMode=e.paymentMode)}collectFieldValues(){const e={};return this.form?(this.form.querySelectorAll("[data-slug]").forEach(t=>{const a=t.dataset.slug;if(!a)return;let n;if("checkbox"===t.type)n=t.checked?t.value||"on":"";else if("radio"===t.type)if(t.checked)n=t.value;else{if(a in e)return;n=""}else n=t.value;e[a]={label:this.getFieldLabel(t),value:n,group:this.getFieldGroup(t),multiple:"true"===t.dataset.multiple}}),e):e}getFieldLabel(e){const t=e.closest(".sd-block");if(!t)return"";const a=t.querySelector(".sd-label, .sd-block-legend")||(t.classList.contains("sd-checkbox-field")?t.querySelector(".sd-checkbox-text"):null);return a?(a.textContent||"").replace(/\s+/g," ").trim().replace(/\s*\*$/,""):""}getFieldGroup(e){const t=e.closest(".sd-block"),a=t?.parentElement?.closest(".sd-block");if(!a)return"";const n=a.querySelector(".sd-block-legend");return n?(n.textContent||"").replace(/\s+/g," ").trim().replace(/\s*\*$/,""):""}appendFieldValues(e){const t=this.collectFieldValues();Object.keys(t).forEach(a=>{e.append(`fields[${a}][value]`,t[a].value),e.append(`fields[${a}][label]`,t[a].label),e.append(`fields[${a}][group]`,t[a].group),t[a].multiple&&e.append(`fields[${a}][multiple]`,"true")})}displayServerFieldErrors(e){return(0,n.MO)(this.form,e)}onActivate(){}showError(e){const t=this.block.querySelector(".sd-payment-error");t&&(t.textContent=e,t.style.display="block")}hideError(){const e=this.block.querySelector(".sd-payment-error");e&&(e.style.display="none")}showLoading(){const e=this.form.querySelector('[type="submit"]');e&&(e.disabled=!0,e.classList.add("sd-loading"))}hideLoading(){const e=this.form.querySelector('[type="submit"]');e&&(e.disabled=!1,e.classList.remove("sd-loading"))}
1setupAmountListener(){if(this._amountListeners=[],"variable"!==this.amountType||!this.variableAmountField)return;this.updateAmountDisplay();const e=this.form.querySelector(`[name="${this.variableAmountField}"], [data-slug="${this.variableAmountField}"]`);if(e){const t=()=>{this.onAmountChange()};e.addEventListener("input",t),e.addEventListener("change",t),this._amountListeners.push({element:e,type:"input",handler:t},{element:e,type:"change",handler:t})}}onAmountChange(){this.updateCoverFeesDisplay(),this.updateAmountDisplay()}removeAmountListener(){if(this._amountListeners){for(const{element:e,type:t,handler:a}of this._amountListeners)e.removeEventListener(t,a);this._amountListeners=[]}}destroy(){if(this.removeAmountListener(),this._coverFeesListeners){for(const{element:e,type:t,handler:a}of this._coverFeesListeners)e.removeEventListener(t,a);this._coverFeesListeners=[]}}setupCoverFeesListener(){const e=this.form.querySelector(".sd-cover-fees-input");if(!e)return;const t=parseFloat(e.dataset.feePercentage),a=parseFloat(e.dataset.feeFixed);if(isNaN(t)||(this.feePercentage=t/100),isNaN(a)||(this.feeFixed=a),this.feeMode=e.dataset.feeMode||"all_gateways","per_gateway"===this.feeMode&&e.dataset.gatewayFees)try{this.gatewayFees=JSON.parse(e.dataset.gatewayFees)}catch(e){this.gatewayFees={}}this.coverFeesChecked=e.checked,this.updateCoverFeesVisibility(),this.updateCoverFeesDisplay(),this.updateAmountDisplay(),this._coverFeesListeners=this._coverFeesListeners||[];const n=()=>{this.coverFeesChecked=e.checked,this.onCoverFeesChange()};e.addEventListener("change",n),this._coverFeesListeners.push({element:e,type:"change",handler:n})}onCoverFeesChange(){this.updateCoverFeesDisplay(),this.updateAmountDisplay()}resolveFeeRates(){if("per_gateway"===this.feeMode&&this.gatewayFees){const e=this.gatewayFees[this.gatewayName];if(e)return!1===e.enabled?{feePercentage:0,feeFixed:0}:{feePercentage:parseFloat(e.fee_percentage)/100||0,feeFixed:parseFloat(e.fee_fixed)||0}}return{feePercentage:this.feePercentage,feeFixed:this.feeFixed}}calculateRawFee(e){if(e<=0)return 0;const{feePercentage:t,feeFixed:a}=this.resolveFeeRates();if(t>=1)return 0;const n=(e+a)/(1-t);return Math.round(100*(n-e))/100}calculateFee(e){const t=this.form.querySelector(".sd-cover-fees-input");return t&&(this.coverFeesChecked=t.checked),this.coverFeesChecked?this.calculateRawFee(e):0}getBaseAmountMajor(){return"fixed"===this.amountType?this.fixedAmount:this.getVariableAmount()}updateCoverFeesVisibility(){const e=this.form.querySelector(".sd-cover-fees-block");if(!e)return;const{feePercentage:t,feeFixed:a}=this.resolveFeeRates(),n=t>0||a>0;e.style.display=n?"":"none",n||(this.coverFeesChecked=!1)}formatWithCurrencyPosition(e,t){return function(e,t){switch(window.suredonationPayment?.currencySignPosition||"auto"){case"right":return`${t}${e}`;case"left_space":return`${e} ${t}`;case"right_space":return`${t} ${e}`;default:return`${e}${t}`}}(e,t.toFixed(2))}updateAmountDisplay(){const e=(this.block.querySelector(`.sd-payment-amount-block[data-payment-type="${CSS.escape(this.paymentType)}"]`)||this.block).querySelector(".sd-payment-value");if(!e)return;const t=this.getBaseAmountMajor();if("fixed"!==this.amountType&&t<=0)return void(e.textContent=window.suredonationPayment?.amountPlaceholder||"Complete the form to view the amount.");const a=this.calculateFee(t),n=t+a,o=this.currencySymbol||e.dataset.currencySymbol||"$",s=e.dataset.messageFormat||"{amount}",r=this.formatWithCurrencyPosition(o,n);let i=s.replace("{amount}",r);if(a>0){const e=this.formatWithCurrencyPosition(o,a);i+=" "+(window.suredonationPayment?.feeIncludesText||"(includes %s processing fee)").replace("%s",e)}e.textContent=i}updateCoverFeesDisplay(){const e=this.form.querySelector(".sd-cover-fees-amount");if(!e)return;const t=this.getBaseAmountMajor();if(t<=0)return void(e.textContent="");const a=this.calculateRawFee(t);e.textContent=a>0?" ("+this.formatWithCurrencyPosition(this.currencySymbol,a)+")":""}}},5368(e,t,a){a.r(t),a.d(t,{PayPalGateway:()=>l,default:()=>c});var n=a(957),o=a(367);const s="suredonationPayPal",r={capture:"suredonationPayPalCapture",subscription:"suredonationPayPalSubscription"},i=new Map;function d(e){if(e?.close)try{Promise.resolve(e.close()).catch(()=>{})}catch{}}
1class l extends n.q{async init(){this.gatewayName="paypal",this.formId=this.block.dataset.formId||"",this.blockId=this.block.dataset.blockId||"",this.donationId=null,this.orderId=null,this.paypalButtons=null,this.setupAmountListener(),this.setupCoverFeesListener(),await this.renderPayPalButtons()}async renderPayPalButtons(){const e=this.block.querySelector(".sd-paypal-button-container");if(!e)return;this._renderSeq=(this._renderSeq||0)+1;const t=this._renderSeq,a=await this.loadGatewayConfig();if(!this.block.isConnected)return;if(t!==this._renderSeq)return;if(a&&!a.paypal)return void this.showError(window.suredonationPayPalConfig?.errors?.unavailable||"PayPal is not available right now. Please choose another payment method.");const n=a?a.paypal:window.suredonationPayPalConfig,o=this.paymentType,{url:l,namespace:c}=function(e,t){const a="subscription"===t,n=e?.sdkUrls;if(n){const e=a?"subscription":"capture",t=n[e]||"";return t?{url:t,namespace:r[e]}:{url:"",namespace:""}}return{url:e?.sdkUrl||"",namespace:s}}(n,o),u=!(!l||!c)&&await function(e,t=s){if(window[t])return Promise.resolve(!0);let a="";try{a=new URL(e,window.location.href).origin}catch{a=""}return"https://www.paypal.com"!==a?Promise.resolve(!1):(i.has(t)||i.set(t,new Promise(a=>{const n=document.createElement("script");n.src=e,n.async=!0,n.setAttribute("data-namespace",t),n.onload=()=>{if(!window[t])return i.delete(t),n.remove(),void a(!1);void 0===window.paypal&&(window.paypal=window[t]),a(!0)},n.onerror=()=>{i.delete(t),n.remove(),a(!1)},document.head.appendChild(n)})),i.get(t))}(l,c);if(t!==this._renderSeq)return;if(!u)throw new Error(window.suredonationPayPalConfig?.errors?.notLoaded||"PayPal SDK failed to load.");this.paypal=window[c];const h="function"==typeof window.suredonationPayPalSubscriptionConfig?window.suredonationPayPalSubscriptionConfig:null,p="subscription"===o&&h?h(this):this.getOneTimeButtonConfig();let m;p.createSubscription&&delete p.createOrder;try{if(e.innerHTML="",m=this.paypal.Buttons(p),await m.render(e),t!==this._renderSeq)return void d(m);this.paypalButtons=m}catch(e){d(m),console.error("PayPal Buttons render error:",e),this.showError(e.message||"Failed to load PayPal buttons.")}}getOneTimeButtonConfig(){return{fundingSource:this.paypal.FUNDING.PAYPAL,style:{layout:"vertical",color:"gold",shape:"rect",label:"donate"},onClick:(e,t)=>(0,o.l)(this.form)?t.resolve():t.reject(),createOrder:async()=>(this.signalAttemptInFlight(!0),await this.createPayPalOrder()),onApprove:async e=>{if((e.subscriptionID?"subscription":"one-time")!==this.paymentType)return this.signalAttemptInFlight(!1),this.markPayPalOrderAbandoned(),void this.showError(window.suredonationPayPalConfig?.errors?.typeChanged||"The donation type changed while PayPal was open. Please reload the page and try again.");try{await this.verifyPayPalOrder(e.orderID)}catch(e){console.error("PayPal finalize failed after approval:",e)}finally{this.signalAttemptInFlight(!1)}},onError:e=>{console.error("PayPal error:",e),this.showError(window.suredonationPayPalConfig?.errors?.generic||"An error occurred with PayPal."),this.hideLoading(),this.signalAttemptInFlight(!1)},onCancel:()=>{this.hideLoading(),this.hideError(),this.signalAttemptInFlight(!1),this.markPayPalOrderAbandoned()}}}signalAttemptInFlight(e){this.block.dispatchEvent(new CustomEvent("suredonation/paymentAttempt",{detail:{inFlight:e}}))}async createPayPalOrder(){this.showLoading(),this.hideError();const e=this.getBaseAmountMajor(),t=e+this.calculateFee(e),a=this.form.querySelector('input[name="campaign_id"]'),n=a?a.value:"",o=new FormData;o.append("action","suredonation_create_paypal_order"),o.append("nonce",window.suredonationPayPalConfig?.nonce||this.block.dataset.nonce||""),o.append("amount",t),o.append("base_amount",e),o.append("campaign_id",n),o.append("donor_email",this.getCustomerEmail()),o.append("donor_name",this.getCustomerName()),o.append("cover_fees",this.coverFeesChecked?"true":"false"),o.append("form_id",this.formId),o.append("block_id",this.blockId),this.appendHoneypot(o),this.appendFieldValues(o),this.appendAnonymousFlag(o),this.appendPaymentMode(o);const s=window.suredonationPayPalConfig?.ajaxUrl||window.suredonationPayment?.ajaxUrl||"/wp-admin/admin-ajax.php",r=await fetch(s,{method:"POST",body:o});if(!r.ok)throw this.hideLoading(),new Error(`Server error: ${r.status}`);const i=await r.json();if(!i.success){this.hideLoading(),this.displayServerFieldErrors(i.data?.fieldErrors);const e=i.data?.message||"Failed to create PayPal order.";throw this.showError(e),new Error(e)}return this.orderId=i.data.orderID,this.donationId=i.data.donationId,this.orderId}markPayPalOrderAbandoned(){if(!this.donationId||!this.orderId)return;const e=new FormData;e.append("action","suredonation_abandon_paypal_order"),e.append("nonce",window.suredonationPayPalConfig?.nonce||this.block.dataset.nonce||""),e.append("order_id",this.orderId),e.append("donation_id",this.donationId);const t=window.suredonationPayPalConfig?.ajaxUrl||window.suredonationPayment?.ajaxUrl||"/wp-admin/admin-ajax.php";fetch(t,{method:"POST",body:e,keepalive:!0}
1).catch(()=>{})}async verifyPayPalOrder(e){this.showLoading();const t=new FormData;t.append("action","suredonation_verify_paypal_order"),t.append("nonce",window.suredonationPayPalConfig?.nonce||this.block.dataset.nonce||""),t.append("order_id",e),t.append("donation_id",this.donationId);const a=window.suredonationPayPalConfig?.ajaxUrl||window.suredonationPayment?.ajaxUrl||"/wp-admin/admin-ajax.php";try{const n=await fetch(a,{method:"POST",body:t});if(!n.ok)throw new Error(`Server error: ${n.status}`);const o=await n.json();if(!o.success)throw new Error(o.data?.message||"Failed to verify PayPal payment.");return this.form.dispatchEvent(new CustomEvent("sd-payment-success",{detail:{gateway:"paypal",donationId:this.donationId,orderId:e,captureId:o.data?.captureId||"",message:o.data?.message||""},bubbles:!0})),o.data}catch(e){throw this.showError(e.message),e}finally{this.hideLoading()}}async createPaymentIntent(){}async confirmPayment(){return{success:!0,donationId:this.donationId,orderId:this.orderId}}async updatePaymentType(e){const t="subscription"===e?"subscription":"one-time";t!==this.paymentType&&(this._renderSeq=(this._renderSeq||0)+1,this.paymentType=t,await this.closeButtons(),await this.renderPayPalButtons())}async closeButtons(){if(this.paypalButtons?.close)try{await this.paypalButtons.close()}catch{}this.paypalButtons=null;const e=this.block.querySelector(".sd-paypal-button-container");e&&(e.innerHTML="")}destroy(){super.destroy(),this._renderSeq=(this._renderSeq||0)+1;const e=this.paypalButtons;this.paypalButtons=null;const t=this.block.querySelector(".sd-paypal-button-container");t&&(t.innerHTML=""),d(e)}}const c=l}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.