PluginProbe
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 2.12.8
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v2.12.8
2.12.8 2.12.7 2.12.6 2.12.5 2.12.4 2.12.3 2.12.2 2.12.1 2.12.0 2.11.1 2.11.0 2.10.1 2.10.0 2.9.1 2.9.0 2.8.2 2.8.1 2.7.0 2.7.1 2.8.0 trunk 0.0.10 0.0.11 0.0.12 0.0.13 All 98 releases
sureforms / assets / js / minified / payment.min.js

payment.min.js in SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz 2.12.8, at assets/js/minified/payment.min.js

1 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 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){e.dataset.srfmPaymentInFlight="true";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}}finally{delete e.dataset.srfmPaymentInFlight}}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};