芝麻web文件管理V1.00
编辑当前文件:/home/royashxg/public_html/wp-content/plugins/fluentformpro/public/js/payment_handler.js
(()=>{"use strict";const t=function(t,e){t||(t=0);var n=parseInt(t)/100,i=2;t%100==0&&0==e.decimal_points&&(i=0);var r=",",a=".";"dot_comma"!=e.currency_separator&&(r=".",a=",");var o,s,f,l,u,c,m,d,p,h,_=e.currency_sign||"",y=(o=n,s=i,f=a,l=r,u=isNaN(s)?2:Math.abs(s),c=f||".",m=void 0===l?",":l,d=o<0?"-":"",p=parseInt(o=Math.abs(o).toFixed(u))+"",h=(h=p.length)>3?h%3:0,d+(h?p.substr(0,h)+m:"")+p.substr(h).replace(/(\d{3})(?=\d)/g,"$1"+m)+(u?c+Math.abs(o-p).toFixed(u).slice(2):""));return"right"==e.currency_sign_position?y+""+_:"left_space"==e.currency_sign_position?_+" "+y:"right_space"==e.currency_sign_position?y+" "+_:_+""+y};function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e(t)}function n(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,i)}return n}function i(t){for(var e=1;e
",{id:"form_success",class:"ff-message-success"}).html(i.message).insertAfter(t.$form),t[i.actionName](i))})),jQuery(".ff_modal_btn").on("click",(function(){t.calculatePayments()})),this.calculatePayments(),this.$form.find(".ff_payment_item,.ff_quantity_item").on("change",(function(e){e.target.min&&+e.target.value<+e.target.min&&(e.target.value=e.target.min),e.target.max&&+e.target.value>+e.target.max&&(e.target.value=e.target.max),t.calculatePayments(),t.mayBeToggleSubscriptionRelatedThings(e)})),this.$form.on("change",".ff-custom-user-input",(function(e){t.handleCustomUserInputChange(e)})),this.$form.on("do_calculation",(function(){t.calculatePayments()})),this.initDiscountCode()}},{key:"calculatePayments",value:function(){var t=this,e=this.$form,n=this.getPaymentItems(),i=0;jQuery.each(n,(function(t,e){i+=e.line_total})),this.totalAmount=i;var r=this.getDiscounts();jQuery.each(r,(function(e,n){var r=n.amount;"percent"===n.coupon_type&&(r=n.amount/100*i),t.totalAmount-=r})),e.trigger("payment_amount_change",{amount:i,items:n,discounts:r,payment_handler:this}),e.find(".ff_order_total").html(this.getFormattedPrice(this.totalAmount)),e.data("payment_total",this.totalAmount);var a=!Object.keys(n).length;this.hasPaymentItems=a;var o=a?"hide":"show";this.$form.find(".ff_payment_method").closest(".ff-el-group:not(.ff_excluded)")[o](),e.find(".ff_dynamic_payment_summary").length&&this.generateSummaryTable(n,i,r,a)}},{key:"generateSummaryTable",value:function(t,e,n){var i=this,r=arguments.length>3&&void 0!==arguments[3]&&arguments[3];if(this.$form.find(".ff_dynamic_payment_summary .ff_payment_summary_fallback").hide(),r)return this.$form.find(".ff_dynamic_payment_summary .ff_payment_summary").html(""),void this.$form.find(".ff_dynamic_payment_summary .ff_payment_summary_fallback").show();var a='
';a+="
".concat(this.$t("item"),"
").concat(this.$t("price"),"
").concat(this.$t("qty"),"
").concat(this.$t("line_total"),"
"),a+="
",jQuery.each(t,(function(t,e){(0===e.price||e.price)&&(a+="
",a+="
".concat(e.label,"
"),a+="
".concat(i.getFormattedPrice(e.price),"
"),a+="
".concat(e.quantity,"
"),a+="
".concat(i.getFormattedPrice(e.line_total),"
"),a+="
")})),a+="
";var o="";n.length&&(o+='
'.concat(this.$t("Sub Total"),"
").concat(this.getFormattedPrice(e),"
"),jQuery.each(n,(function(t,n){var r=n.amount;"percent"===n.coupon_type&&(r=n.amount/100*e),r>=e&&(r=e),o+='
'.concat(i.$t("discount:")," ").concat(n.title,"
-").concat(i.getFormattedPrice(r),"
"),e-=r}))),o+='
'.concat(this.$t("total"),"
").concat(this.getFormattedPrice(e),"
"),a+="
".concat(o,"
"),a+="
",this.$form.find(".ff_dynamic_payment_summary .ff_payment_summary").html(a)}},{key:"getPaymentItems",value:function(){var t=this.$form,e=t.find(".ff-el-group:not(.ff_excluded)").find(".ff_payment_item"),n={},i=this;function r(t,e,r){t=t.replace("[","").replace("]","");var a=i.getQuantity(t);a&&(n[t]={label:e,price:r,quantity:a,line_total:a*r})}return e.each((function(e,n){var a=n.type,o=jQuery(n);if(!o.closest(".has-conditions.ff_excluded").length){var s=o.attr("name"),f=o.data("payment_label");if(f||(f=o.closest(".ff-el-group").find(".ff-el-input--label label").text()),"radio"===a){var l=t.find("input[name="+s+"]:checked"),u=l.val();i.maybeAddInventoryStockOutFailedValidation(o,l.data("quantity_remaining"),!l.length),i.maybeHandleSubscriptionItem(s,l,f,u,r)}else if("hidden"===a)i.maybeAddInventoryStockOutFailedValidation(o,o.data("quantity_remaining")),i.maybeHandleSubscriptionItem(s,o,f,"",r);else if("number"==a||"text"==a){var c=window.ff_helper.numericVal(jQuery(this));0!=c&&r(s,f,parseFloat(c))}else if("checkbox"==a){var m,d=o.data("group_id"),p=t.find('input[data-group_id="'+d+'"]:checked'),h=0,_=[];p.each((function(t,e){var n=jQuery(e).data("payment_value"),i=jQuery(e).data("quantity_remaining");void 0!==i&&(m=void 0===m||m>i?i:m),n&&(h+=parseFloat(n),_.push(jQuery(e).val()))})),_.length&&(f+='
',_.forEach((function(t){f+="
"+t+"
"})),f+="
"),h&&r(s,f,h),i.maybeAddInventoryStockOutFailedValidation(o,m,!h)}else if("select-one"===a){var y=t.find("select[name="+s+"] option:selected"),g=y.val();i.maybeAddInventoryStockOutFailedValidation(o,y.data("quantity_remaining"),!y.length),i.maybeHandleSubscriptionItem(s,y,f,g,r)}}})),n}},{key:"maybeAddInventoryStockOutFailedValidation",value:function(t,e,n){var i,r,a=t.attr("name").replace("[","").replace("]","");if(n)null===(r=this.formInstance)||void 0===r||r.removeFieldValidationRule(a,"force_failed");else if(void 0!==e){var o,s=this.getQuantity(a);s&&(e
'),jQuery.each(e,(function(e,n){var i=jQuery(n);i.find(".ff_input-group-append").on("click",(function(){var e=i.find("input.ff_coupon_item"),n=e.val();if(!n)return"";e.attr("disabled",!0),e.attr("name"),jQuery.post(window.fluentFormVars.ajaxUrl,{action:"fluentform_apply_coupon",form_id:t.formId,total_amount:t.totalAmount,coupon:n,other_coupons:t.$form.find(".__ff_all_applied_coupons").val()}).then((function(r){var a=r.coupon;if(!Object.keys(t.appliedCoupons).includes(a.code)){t.appliedCoupons[a.code]=a,t.$form.find(".__ff_all_applied_coupons").attr("value",JSON.stringify(Object.keys(t.appliedCoupons)));var o=a.amount+"%";"fixed"==a.coupon_type&&(o=t.getFormattedPrice(a.amount));var s=a.amount;"percent"===a.coupon_type&&(s=(a.amount/100*t.totalAmount).toFixed(2));var f=t.totalAmount-s,l=a.message||"{coupon.code}
-{coupon.amount}
",u={"{coupon.code}":a.code,"{coupon.amount}":o,"{total_amount}":t.totalAmount,"{discount_amount}":s,"{remain_amount}":f},c=t.replaceWords(l,u);t.recordCouponMessage(i,n,c,"success"),e.val("")}})).fail((function(e){t.recordCouponMessage(i,n,e.responseJSON.message,"error")})).always((function(){e.attr("disabled",!1),t.$form.trigger("do_calculation")}))}))}))}},{key:"recordCouponMessage",value:function(t,e,n,i){var r=this;t.find(".ff_coupon_responses").length||t.append('
');var a=t.find(".ff_coupon_responses");a.find(".ff_error, .ff_resp_item_"+e).remove();var o=jQuery("
",{class:"ff_".concat(i," ff_resp_item_").concat(e)}),s=jQuery("
",{class:"error-clear",html:"×",click:function(t){a.find(".ff_resp_item_"+e).remove(),delete r.appliedCoupons[e],r.$form.find(".__ff_all_applied_coupons").attr("value",JSON.stringify(Object.keys(r.appliedCoupons))),r.$form.trigger("do_calculation")}});a.append(o.append(s,n))}},{key:"mayBeToggleSubscriptionRelatedThings",value:function(t){var e=jQuery(t.target);if(e.hasClass("ff_subscription_item")){var n=e.val(),i=e.closest(".ff-el-input--content");i.find(".ff-custom-user-input-wrapper").addClass("hidden_field");var r=i.find(".ff-custom-user-input-wrapper-"+n);r.removeClass("hidden_field");var a=r.find("input").data("min")||0;r.find("input").attr("min",a),i.find(".ff_summary_container").addClass("hidden_field"),i.find(".ff_summary_container_"+n).removeClass("hidden_field"),i.find(".ff-custom-user-input-wrapper.hidden_field input").attr("min","0")}}},{key:"handleCustomUserInputChange",value:function(t){var e,n=jQuery(t.target),i=parseFloat(n.val())||0,r=n.data("parent_input_name"),a=n.data("parent_input_type"),o=n.data("plan_index");"select"===a?o=(e=this.$form.find("select[name="+r+"] option:selected")).val():e="radio"===a?this.$form.find("input[name="+r+"]:checked"):this.$form.find("input[name="+r+"]");var s=i+parseFloat(e.data("initial_amount")),f=parseFloat(e.attr("data-signup_fee"));e.attr("data-payment_value",s);var l=n.parent().parent().find(".ff_summary_container_"+o);l.find(".ffbs_subscription_amount").html(this.getFormattedPrice(i)),l.find(".ffbs_first_interval_total").html(this.getFormattedPrice(s+f)),this.calculatePayments()}},{key:"initStripeElement",value:function(){var t=this;if(this.$form.hasClass("ff_has_stripe_inline")){var e;this.stripe=new Stripe(this.formPaymentConfig.stripe.publishable_key),this.stripe.registerAppInfo(this.formPaymentConfig.stripe_app_info);var n=this.formPaymentConfig.stripe.custom_style.styles,i=this.stripe.elements().create("card",{style:n,hidePostalCode:!this.formPaymentConfig.stripe.inlineConfig.verifyZip,disableLink:this.formPaymentConfig.stripe.inlineConfig.disable_link}),r=this.$form.find(".ff_stripe_card_element").attr("id");if(!r)return void console.log("No Stripe Cart Element Found");i.mount("#"+r),i.addEventListener("change",(function(e){t.toggleStripeInlineCardError(e.error)})),this.stripeCard=i,this.$form.on("fluentform_submission_success",(function(){i.clear()})),this.$form.on("fluentform_submission_failed",(function(){t.stripeCard.update({disabled:!1})})),this.registerStripePaymentToken(r);var a=this;this.$form.on("fluentform_update_stripe_inline_element_style",(function(t,e){a.handleStripeStyleUpdate(e,n)}));var o=(null===(e=this.formPaymentConfig.stripe)||void 0===e||null===(e=e.inlineConfig)||void 0===e?void 0:e.inline_styles)||!1;this.handleStripeStyleUpdate(o,n)}}},{key:"getJsStylesFromStringStyle",value:function(t){if(!t)return null;var e={};return(t=t.split(";")).forEach((function(t){if(t){var n=(t=t.split(":"))[0].trim();n.includes("-")&&(n=(n=n.split("-"))[0]+n[1][0].toUpperCase()+n[1].slice(1)),e[n]=t[1].trim()}})),e}},{key:"handleStripeStyleUpdate",value:function(t,e){if(t){var n=this,r={error_msg:n.getJsStylesFromStringStyle(t.error_msg),input:n.getJsStylesFromStringStyle(t.input),focusInput:n.getJsStylesFromStringStyle(t.focusInput),placeholder:n.getJsStylesFromStringStyle(t.placeholder)},a=i({},e),o=["boxShadow","border","borderStyle","borderWidth","borderColor","borderRadius"];if(r.input){for(var s in r.input)e.base[s]||o.includes(s)&&delete r.input[s];a.base=i(i({},a.base),r.input)}if(r.placeholder&&(a.base["::placeholder"]=i(i({},a.base["::placeholder"]),r.placeholder)),r.focusInput){for(var f in r.focusInput)o.includes(f)&&delete r.focusInput[f];a.base[":focus"]=i(i({},a.base[":focus"]),r.focusInput)}r.error_msg&&(a.invalid=i(i({},a.invalid),r.error_msg),jQuery(".ff_card-errors").css(a.invalid)),this.stripeCard.update({style:a})}}},{key:"initPaymentMethodChange",value:function(){var t=this,e=this.$form.find(".ff_payment_method");e.length>1?this.paymentMethod=e.filter((function(t,e){return e.checked})).val():this.paymentMethod=e.val(),e.length>1&&e.change((function(e){t.paymentMethod=e.target.value;var n="stripe"===t.paymentMethod?"block":"none";jQuery(e.target).closest(".ff-el-input--content").find(".stripe-inline-wrapper").css({display:n})}))}},{key:"registerStripePaymentToken",value:function(t){var e=this;this.formInstance.addGlobalValidator("stripeInlinePayment",(function(n,i){if("stripe"===e.paymentMethod&&!e.hasPaymentItems&&!jQuery("#"+t).closest(".ff_excluded").length){e.formInstance.showFormSubmissionProgress(n),jQuery("
",{id:e.formId+"_success",class:"ff-message-success ff_msg_temp"}).html(e.$t("processing_text")).insertAfter(e.$form),e.toggleStripeInlineCardError();var r=jQuery.Deferred();return e.stripe.createPaymentMethod("card",e.stripeCard).then((function(t){t.error?e.toggleStripeInlineCardError(t.error):(e.stripeCard.update({disabled:!0}),e.formInstance.hideFormSubmissionProgress(n),jQuery("
",{id:e.formId+"_success",class:"ff-message-success ff_msg_temp"}).html(e.$t("processing_text")).insertAfter(e.$form),i.data+="&"+jQuery.param({__stripe_payment_method_id:t.paymentMethod.id}),r.resolve())})),r.promise()}}))}},{key:"toggleStripeInlineCardError",value:function(t){var e=this,n=this.$form.find(".ff_card-errors");t?(n.html(t.message),n.closest(".stripe-inline-wrapper").addClass("ff-el-is-error"),this.formInstance.hideFormSubmissionProgress(this.$form),this.stripeCard.update({disabled:!1})):(n.html(""),n.closest(".stripe-inline-wrapper").removeClass("ff-el-is-error")),setTimeout((function(){e.maybeRemoveSubmitError()}),500)}},{key:"stripeSetupIntent",value:function(t){var e=this;this.stripe.confirmCardPayment(t.client_secret,{payment_method:t.payment_method_id}).then((function(n){n.error?e.toggleStripeInlineCardError(n.error):e.handleStripePaymentConfirm({action:"fluentform_sca_inline_confirm_payment_setup_intents",form_id:e.formId,payment_method:n.paymentIntent.payment_method,payemnt_method_id:t.payemnt_method_id,payment_intent_id:n.paymentIntent.id,submission_id:t.submission_id,stripe_subscription_id:t.stripe_subscription_id,type:"handleCardSetup"})}))}},{key:"initStripeSCAModal",value:function(t){var e=this;this.formInstance.showFormSubmissionProgress(this.$form),this.stripe.handleCardAction(t.client_secret).then((function(n){n.error?(e.formInstance.hideFormSubmissionProgress(e.$form),e.toggleStripeInlineCardError(n.error)):e.handleStripePaymentConfirm({action:"fluentform_sca_inline_confirm_payment",form_id:e.formId,payment_method:n.paymentIntent.payment_method,payment_intent_id:n.paymentIntent.id,submission_id:t.submission_id,type:"handleCardAction"})}))}},{key:"handleStripePaymentConfirm",value:function(t){this.maybeRemoveSubmitError(),jQuery("
",{id:this.formId+"_success",class:"ff-message-success ff_msg_temp"}).html(this.$t("confirming_text")).insertAfter(this.$form),this.formInstance.showFormSubmissionProgress(this.$form),window.fluentFormApp(this.$form).sendData(this.$form,t)}},{key:"maybeRemoveSubmitError",value:function(){jQuery("#form_success").remove()}}],n&&a(e.prototype,n),r&&a(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,n,r}();(s=jQuery).each(s("form.fluentform_has_payment"),(function(){var t=s(this);t.on("fluentform_init_single",(function(e,n){new f(t,n).init()}))})),s(document).on("ff_reinit",(function(t,e){var n=s(e);n.attr("data-ff_reinit","yes");var i=fluentFormApp(n);if(!i)return!1;new f(n,i).init()}))})();