FileMaster
Search
Toggle Dark Mode
Home
/
.
/
wp-content
/
plugins
/
sureforms
/
assets
/
js
/
minified
Edit File: payment.min.js
function getCurrencySymbol(e){return(window.srfmStripe?.currenciesData||{})[e?.toUpperCase()]?.symbol||e.toUpperCase()+" "}function validateThePaymentBlock(e){var t=e.querySelector(".srfm-block.srfm-payment-block:not(.hide-element)");if(!t)return{valid:!0,slug:"no-payment-block",message:""};var t=t.querySelector(".srfm-payment-input"),a=t.getAttribute("data-amount-type")||"fixed";if("fixed"===a){var n=parseFloat(t.getAttribute("data-fixed-amount"));if(!n||isNaN(n)||n<=0)return{valid:!1,slug:"invalid-fixed-amount",message:window.srfmPaymentUtility?.getStripeStrings("payment_amount_not_configured","Payment is currently unavailable. Please contact the site administrator to configure the payment amount.")}}else if("variable"===a){n=parseFloat(t.dataset.currentAmount||0);if(isNaN(n)||n<=0)return{valid:!1,slug:"invalid-variable-amount",message:window.srfmPaymentUtility?.getStripeStrings("invalid_variable_amount","Invalid payment amount")};a=parseFloat(t.getAttribute("data-minimum-amount")||0);if(0<a&&n<a)return n=getCurrencySymbol(t.getAttribute("data-currency")||"usd"),{valid:!1,slug:"amount-below-minimum",message:(window.srfmPaymentUtility?.getStripeStrings("amount_below_minimum","Payment amount must be at least {symbol}{amount}.")).replace("{symbol}",n).replace("{amount}",a.toFixed(2))}}n=t.getAttribute("data-customer-name-field"),a="subscription"===(t.getAttribute("data-payment-type")||"one-time");if(a&&(!n||""===n.trim()))return{valid:!1,slug:"payment-name-not-mapped",message:window.srfmPaymentUtility?.getStripeStrings("payment_name_not_mapped","Payment is currently unavailable. Please contact the site administrator to configure the customer name field.")};t=t.getAttribute("data-customer-email-field");if(!t||""===t.trim())return{valid:!1,slug:"payment-email-not-mapped",message:window.srfmPaymentUtility?.getStripeStrings("payment_email_not_mapped","Payment is currently unavailable. Please contact the site administrator to configure the customer email field.")};if(a&&n&&""!==n.trim()){a=e.querySelector(`.srfm-input-block.srfm-slug-${n} .srfm-input-common`),n=a?a.value.trim():"";if(!a||""===n)return{valid:!1,slug:"payment-name-required",message:window.srfmPaymentUtility?.getStripeStrings("payment_name_required","Please enter your name.")}}a=e.querySelector(`.srfm-email-block.srfm-slug-${t} .srfm-input-common`),n=a?a.value.trim():"";return a&&""!==n?{valid:!0,slug:"payment-valid",message:""}:{valid:!1,slug:"payment-email-required",message:window.srfmPaymentUtility?.getStripeStrings("payment_email_required","Please enter your email.")}}async function handleFormPayment(e){try{var t,a=validateThePaymentBlock(e);return a.valid&&"no-payment-block"===a.slug?{valid:!0,message:""}:a.valid?(t=e.querySelector(".srfm-block.srfm-payment-block"),await processAllPayments(e,t)):{valid:!1,message:a.message}}catch(e){return{valid:!1,message:window.srfmPaymentUtility?.getStripeStrings("payment_failed","Payment failed"),paymentResultOnCreateIntent:null}}}async function processAllPayments(e,t){try{var a=t.getAttribute("data-block-id"),n=window.srfmGetPaymentKey?window.srfmGetPaymentKey(e,a):a,i=window.srfmPaymentManagers?.[n];return i?await i.processPayment(e):await processStripePayment(e,t,n)}catch(e){return{valid:!1,message:window.srfmPaymentUtility?.getStripeStrings("payment_failed","Payment failed")}}}async function processStripePayment(e,t,a){var n,t=await window.StripePayment.createPaymentIntentsForForm(e,t);return t?.valid?(n=window.srfmPaymentElements?.[a])&&n.clientSecret?(a=await window.StripePayment.srfmConfirmPayment(a,n,e).catch(()=>null))?.valid?{valid:!0,message:window.srfmPaymentUtility?.getStripeStrings("payment_successful","Payment successful"),paymentResult:a}:{valid:!1,message:a?.message||"",paymentResult:null}:{valid:!1,message:"Payment data not found"}:{valid:!1,message:t.message}}export{handleFormPayment};
Save
Back