PluginProbe
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management / 1.6.1
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management v1.6.1
1.6.1 1.6.0 1.5.1 1.5.0 1.4.0 1.3.0 trunk 0.0.1 1.0.0 1.1.0 1.1.1 1.1.2 1.2.0
← All changes | assets/build/552.js +1 -1 1.3.0 → 1.6.1 View file →
@@ -1 +1 @@
1 -"use strict";(globalThis.webpackChunksuredonation=globalThis.webpackChunksuredonation||[]).push([[552],{957(e,t,s){s.d(t,{q:()=>a});var i=s(367);const n=["BIF","CLP","DJF","GNF","JPY","KMF","KRW","MGA","PYG","RWF","UGX","VND","VUV","XAF","XOF","XPF"];class a{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.amountType=e.dataset.amountType||"fixed",this.fixedAmount=parseFloat(e.dataset.fixedAmount)||0,this.minimumAmount=parseFloat(e.dataset.minimumAmount)||0,this.variableAmountField=e.dataset.variableAmountField||"",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")}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 n.includes(this.currency.toUpperCase())?Math.round(e):Math.round(100*e)}fromMinorUnits(e){return n.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)}collectFieldValues(){const e={};return this.form?(this.form.querySelectorAll("[data-slug]").forEach(t=>{const s=t.dataset.slug;if(!s)return;let i;if("checkbox"===t.type)i=t.checked?t.value||"on":"";else if("radio"===t.type)if(t.checked)i=t.value;else{if(s in e)return;i=""}else i=t.value;e[s]={label:this.getFieldLabel(t),value:i,group:this.getFieldGroup(t),multiple:"true"===t.dataset.multiple}}),e):e}getFieldLabel(e){const t=e.closest(".sd-block");if(!t)return"";const s=t.querySelector(".sd-label, .sd-block-legend");return s?(s.textContent||"").replace(/\s+/g," ").trim().replace(/\s*\*$/,""):""}getFieldGroup(e){const t=e.closest(".sd-block"),s=t?.parentElement?.closest(".sd-block");if(!s)return"";const i=s.querySelector(".sd-block-legend");return i?(i.textContent||"").replace(/\s+/g," ").trim().replace(/\s*\*$/,""):""}appendFieldValues(e){const t=this.collectFieldValues();Object.keys(t).forEach(s=>{e.append(`fields[${s}][value]`,t[s].value),e.append(`fields[${s}][label]`,t[s].label),e.append(`fields[${s}][group]`,t[s].group),t[s].multiple&&e.append(`fields[${s}][multiple]`,"true")})}displayServerFieldErrors(e){return(0,i.MO)(this.form,e)}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"))}setupAmountListener(){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()}destroy(){if(this._amountListeners){for(const{element:e,type:t,handler:s}of this._amountListeners)e.removeEventListener(t,s);this._amountListeners=[]}if(this._coverFeesListeners){for(const{element:e,type:t,handler:s}of this._coverFeesListeners)e.removeEventListener(t,s);this._coverFeesListeners=[]}}setupCoverFeesListener(){const e=this.form.querySelector(".sd-cover-fees-input");if(!e)return;const t=parseFloat(e.dataset.feePercentage),s=parseFloat(e.dataset.feeFixed);if(isNaN(t)||(this.feePercentage=t/100),isNaN(s)||(this.feeFixed=s),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 i=()=>{this.coverFeesChecked=e.checked,this.onCoverFeesChange()};e.addEventListener("change",i),this._coverFeesListeners.push({element:e,type:"change",handler:i})}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:s}=this.resolveFeeRates();if(t>=1)return 0;const i=(e+s)/(1-t);return Math.round(100*(i-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:s}=this.resolveFeeRates(),i=t>0||s>0;e.style.display=i?"":"none",i||(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-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 s=this.calculateFee(t),i=t+s,n=this.currencySymbol||e.dataset.currencySymbol||"$",a=e.dataset.messageFormat||"{amount}",r=this.formatWithCurrencyPosition(n,i);let o=a.replace("{amount}",r);if(s>0){const e=this.formatWithCurrencyPosition(n,s);o+=" "+(window.suredonationPayment?.feeIncludesText||"(includes %s processing fee)").replace("%s",e)}e.textContent=o}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 s=this.calculateRawFee(t);e.textContent=s>0?" ("+this.formatWithCurrencyPosition(this.currencySymbol,s)+")":""}}},4552(e,t,s){s.r(t),s.d(t,{OfflineGateway:()=>n,default:()=>a});var i=s(957);class n extends i.q{async init(){this.gatewayName="offline",this.formId=this.block.dataset.formId||"",this.blockId=this.block.dataset.blockId||"",this.setupAmountListener(),this.setupCoverFeesListener()}async createPaymentIntent(e,t){const s=this.fromMinorUnits(e),i=s+this.calculateFee(s),n=this.form.querySelector('input[name="campaign_id"]'),a=n?n.value:"",r=new FormData;r.append("action","suredonation_create_offline_donation"),r.append("nonce",this.block.dataset.nonce||""),r.append("amount",i),r.append("base_amount",s),r.append("cover_fees",this.coverFeesChecked?"true":"false"),r.append("campaign_id",a),r.append("donor_email",t.email),r.append("donor_name",t.name),r.append("form_id",this.formId),r.append("block_id",this.blockId),this.appendHoneypot(r),this.appendFieldValues(r);const o=await fetch(window.suredonationPayment?.ajaxUrl||"/wp-admin/admin-ajax.php",{method:"POST",body:r});if(!o.ok)throw new Error(`Server error: ${o.status}`);const l=await o.json();if(!l.success)throw this.displayServerFieldErrors(l.data?.fieldErrors),new Error(l.data?.message||"Failed to create offline donation");return this.donationId=l.data.donationId,this.confirmationMessage=l.data.message,l.data}async confirmPayment(){this.showLoading();try{return{success:!0,donationId:this.donationId,status:"pending",message:this.confirmationMessage}}finally{this.hideLoading()}}}const a=n}}]);
1 +"use strict";(globalThis.webpackChunksuredonation=globalThis.webpackChunksuredonation||[]).push([[552],{957(e,t,s){s.d(t,{q:()=>i});var n=s(367);const a=["BIF","CLP","DJF","GNF","JPY","KMF","KRW","MGA","PYG","RWF","UGX","VND","VUV","XAF","XOF","XPF"],o=new Map;class i{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 a.includes(this.currency.toUpperCase())?Math.round(e):Math.round(100*e)}fromMinorUnits(e){return a.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||"";o.has(e)||o.set(e,i.fetchGatewayConfig(e));const t=await o.get(e);return t?(this.applyGatewayConfig(t),t):(o.delete(e),null)}static async fetchGatewayConfig(e){try{const t=window.suredonationPayment?.ajaxUrl||"/wp-admin/admin-ajax.php",s=new URL(t,window.location.href);s.searchParams.set("action","suredonation_gateway_config"),s.searchParams.set("form_id",e);const n=await fetch(s.toString(),{method:"GET",cache:"no-store"});if(!n.ok)return null;const a=await n.json();return a?.success&&a.data?a.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 s=t.dataset.slug;if(!s)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(s in e)return;n=""}else n=t.value;e[s]={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 s=t.querySelector(".sd-label, .sd-block-legend")||(t.classList.contains("sd-checkbox-field")?t.querySelector(".sd-checkbox-text"):null);return s?(s.textContent||"").replace(/\s+/g," ").trim().replace(/\s*\*$/,""):""}getFieldGroup(e){const t=e.closest(".sd-block"),s=t?.parentElement?.closest(".sd-block");if(!s)return"";const n=s.querySelector(".sd-block-legend");return n?(n.textContent||"").replace(/\s+/g," ").trim().replace(/\s*\*$/,""):""}appendFieldValues(e){const t=this.collectFieldValues();Object.keys(t).forEach(s=>{e.append(`fields[${s}][value]`,t[s].value),e.append(`fields[${s}][label]`,t[s].label),e.append(`fields[${s}][group]`,t[s].group),t[s].multiple&&e.append(`fields[${s}][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"))}setupAmountListener(){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:s}of this._amountListeners)e.removeEventListener(t,s);this._amountListeners=[]}}destroy(){if(this.removeAmountListener(),this._coverFeesListeners){for(const{element:e,type:t,handler:s}of this._coverFeesListeners)e.removeEventListener(t,s);this._coverFeesListeners=[]}}setupCoverFeesListener(){const e=this.form.querySelector(".sd-cover-fees-input");if(!e)return;const t=parseFloat(e.dataset.feePercentage),s=parseFloat(e.dataset.feeFixed);if(isNaN(t)||(this.feePercentage=t/100),isNaN(s)||(this.feeFixed=s),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:s}=this.resolveFeeRates();if(t>=1)return 0;const n=(e+s)/(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:s}=this.resolveFeeRates(),n=t>0||s>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 s=this.calculateFee(t),n=t+s,a=this.currencySymbol||e.dataset.currencySymbol||"$",o=e.dataset.messageFormat||"{amount}",i=this.formatWithCurrencyPosition(a,n);let r=o.replace("{amount}",i);if(s>0){const e=this.formatWithCurrencyPosition(a,s);r+=" "+(window.suredonationPayment?.feeIncludesText||"(includes %s processing fee)").replace("%s",e)}e.textContent=r}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 s=this.calculateRawFee(t);e.textContent=s>0?" ("+this.formatWithCurrencyPosition(this.currencySymbol,s)+")":""}}},4552(e,t,s){s.r(t),s.d(t,{OfflineGateway:()=>a,default:()=>o});var n=s(957);class a extends n.q{async init(){this.gatewayName="offline",this.formId=this.block.dataset.formId||"",this.blockId=this.block.dataset.blockId||"",this.setupAmountListener(),this.setupCoverFeesListener()}async createPaymentIntent(e,t){const s=this.fromMinorUnits(e),n=s+this.calculateFee(s),a=this.form.querySelector('input[name="campaign_id"]'),o=a?a.value:"",i=new FormData;i.append("action","suredonation_create_offline_donation"),i.append("nonce",this.block.dataset.nonce||""),i.append("amount",n),i.append("base_amount",s),i.append("cover_fees",this.coverFeesChecked?"true":"false"),i.append("campaign_id",o),i.append("donor_email",t.email),i.append("donor_name",t.name),i.append("form_id",this.formId),i.append("block_id",this.blockId),this.appendHoneypot(i),this.appendFieldValues(i),this.appendAnonymousFlag(i);const r=await fetch(window.suredonationPayment?.ajaxUrl||"/wp-admin/admin-ajax.php",{method:"POST",body:i});if(!r.ok)throw new Error(`Server error: ${r.status}`);const c=await r.json();if(!c.success)throw this.displayServerFieldErrors(c.data?.fieldErrors),new Error(c.data?.message||"Failed to create offline donation");return this.donationId=c.data.donationId,this.confirmationMessage=c.data.message,c.data}async confirmPayment(){this.showLoading();try{return{success:!0,donationId:this.donationId,status:"pending",message:this.confirmationMessage}}finally{this.hideLoading()}}}const o=a}}]);