| 1 |
!function(t){"use strict";function e(t,e,n,i=!0){let o={status:!0,errors:[]},a=function(t,e,n){let i={status:!0,errors:[]};for(var o in e)if(e.hasOwnProperty(o)&&-1===n.indexOf(o)){let n=r(t[o],e[o]);if(!n.status)return i.errors.push(void 0!==n.error?n.error:`${o} field is required!`),i.status=!1,i}return i}(n,e,["better_payment_page_id","better_payment_widget_id","return","action","security","cancel_return","payment_amount","primary_payment_amount"]);return o.status=void 0!==a.status?a.status:o.status,o.errors=void 0!==a.errors&&a.errors.constructor===Array?o.errors.concat(a.errors):o.errors,i&&!t.business_email&&(o.errors.push("Business Email is required"),o.status=!1),void 0!==e.primary_payment_amount&&""!==e.primary_payment_amount||(o.errors.push("Payment Amount field is required!"),o.status=!1),void 0!==e.primary_payment_amount&&parseFloat(e.primary_payment_amount)<1&&(o.errors.push("Minimum amount is 1!"),o.status=!1),o}function r(t,e,r=""){let n=function(t){let e=!1;return t.length>1||(e=!(null===t.getAttribute("required")||""===t.getAttribute("required")),e)}(t),i={error:"",status:!0};if(t.length>1)return i;if(n){let n=t.placeholder;n=n.replace(" *","");let o=r||`${n} field is required!`;void 0!==e&&""!==e||(i.error=o,i.status=!1)}return i}t(document).on("click",".better-payment-paypal-bt",(function(r){const n=t("#"+this.form.id),i=t(n);let o=e(t(this).data("paypal-info"),i.serializeObject(),this.form);if(t(this).attr("disabled",!0),void 0!==o.status&&!o.status)return r.preventDefault(),toastr.error(o.errors.length?o.errors[0]:"Something went wrong!"),this.disabled=!1,!1;t(this).attr("disabled",!1)})),t(document).on("click",".better-payment-stripe-bt",(function(r){r.preventDefault();const n=t("#"+this.form.id),i=t(n),o=t(this),a=i.data("better-payment"),s=i.serializeObject();let l=e("",s,this.form,!1);if(void 0!==l.status&&!l.status)return r.preventDefault(),toastr.error(l.errors.length?l.errors[0]:"Something went wrong!"),this.disabled=!1,!1;t(this).attr("disabled",!0),t.ajax({url:betterPayment.ajax_url,type:"post",data:{action:"better_payment_stripe_get_token",security:betterPayment.nonce,fields:s,setting_data:a},success:function(e){void 0!==e.data.stripe_data?(o.html('Redirecting <span class="elementor-control-spinner"> <i class="eicon-spinner eicon-animation-spin"></i> </span>'),Stripe(e.data.stripe_public_key).redirectToCheckout({sessionId:e.data.stripe_data}).then((function(t){}))):(o.html("Stripe"),toastr.error(e.data)),t(this).attr("disabled",!1)},error:function(){t(this).attr("disabled",!1),console.log("Something went wrong!")}})})),t(document).on("change",".bp-custom-payment-amount",(function(e){void 0===this.form.id&&toastr.error("Something went wrong!"),t(this).hasClass("bp-custom-payment-amount-el-integration")?console.log("el integration found!"):console.log("el integration not found!"),document.querySelectorAll("#"+this.form.id+' .bp-payment-amount-wrap input[type="radio"]').forEach((t=>{t.checked=!1})),t(".bp-transaction-details-amount-text").text(this.value)})),t(document).on("click",".bp-form_pay-radio",(function(e){void 0===this.form.id&&toastr.error("Something went wrong!");const r=t(this);let n=parseFloat(r.val());if(""==n)return!1;t("#"+this.form.id+" .bp-custom-payment-amount").val(n),t(".bp-transaction-details-amount-text").text(n)})),t(window).on("elementor/frontend/init",(()=>{const t=elementorModules.frontend.handlers.Base.extend({getDefaultSettings:function(){return{selectors:{form:".elementor-form"}}},getDefaultElements:function(){let t=this.getSettings("selectors"),e={};return e.$form=this.$element.find(t.form),e},bindEvents:function(){this.elements.$form.on("submit_success",this.handleFormAction)},handleFormAction:function(t,e){void 0!==e.data.better_stripe_data&&Stripe(e.data.better_stripe_data.stripe_public_key).redirectToCheckout({sessionId:e.data.better_stripe_data.stripe_data}).then((function(t){}))}});elementorFrontend.hooks.addAction("frontend/element_ready/form.default",(e=>{elementorFrontend.elementsHandler.addHandler(t,{$element:e})})),"undefined"!=typeof elementor&&elementor.hooks.addAction("panel/open_editor/widget/form",(function(t,e,r){elementor.hooks.addFilter("elementor_pro/forms/content_template/item",(function(t,e,r){let n="payment_amount",i="";if(void 0!==r.better_payment_payment_amount_enable&&(i=r.better_payment_payment_amount_enable),console,l,void 0!==t.field_type&&t.field_type==n&&"yes"===i){let e=t.field_label,i=void 0!==t.bp_placeholder?t.bp_placeholder:"",o="USD";r.submit_actions.includes("paypal")?o=void 0!==r.better_payment_form_paypal_currency?r.better_payment_form_paypal_currency:o:r.submit_actions.includes("stripe")&&(o=void 0!==r.better_payment_form_stripe_currency?r.better_payment_form_stripe_currency:o);let a=`<label for="form-field-${n}" class="elementor-field-label">${e}</label>`,s=` <div class="bp-input-group mb-2">\n <div class="bp-input-group-prepend">\n <div class="bp-input-group-text" title="${o}">${function(t="USD"){let e="$",r={AUD:"$",CAD:"$",CZK:"Kč",DKK:"kr",EUR:"€",HKD:"$",HUF:"ft",ILS:"₪",JPY:"¥",MXN:"$",NOK:"kr",NZD:"$",PHP:"₱",PLN:"zł",GBP:"£",RUB:"₽",SGD:"$",SEK:"kr",CHF:"CHF",TWD:"$",THB:"฿",TRY:"₺",USD:"$"};return t in r&&(e=r[t]),e}(o)}</div>\n </div>\n <input type="number" name="form_fields[${n}]" id="form-field-${n}" class="elementor-field elementor-size-sm elementor-field-textual bp-elementor-field-textual-amount" min="${t.bp_field_min}" max="${t.bp_field_max}" placeholder="${i}" >\n </div>\n `;t.field_type="html",t.field_html=a+s}return t}),10,3)}))})),t.fn.serializeObject=function(){var e={},r=this.serializeArray();return t.each(r,(function(){e[this.name]?(e[this.name].push||(e[this.name]=[e[this.name]]),e[this.name].push(this.value||"")):e[this.name]=this.value||""})),e},toastr.options={timeOut:"2000",toastClass:"font-size-md",maxOpened:1}}(jQuery); |