(()=>{function e(){return!!$("#payment_type").length&&($("#payment_type").select2({placeholder:selectPaymentTypeLang}),!!$("#payment_mode").length&&void $("#payment_mode").select2({placeholder:selectPaymentModeLang}))}"invoice-show-url"!=currentRouteName?Livewire.hook("element.init",(function(){e(),$(".amount").hide();var t=window.location.toString();if(t.indexOf("?")>0){var n=t.substring(0,t.indexOf("?"));window.history.replaceState({},document.title,n)}})):document.addEventListener("DOMContentLoaded",e),listenChange("#payment_mode",(function(){1==$(this).val()?$(".payment-attachment").removeClass("d-none"):$(".payment-attachment").addClass("d-none")})),listenChange("#payment_mode",(function(){1==$(this).val()?$("#transaction").show():$("#transaction").hide()})),listenChange("#payment_type",(function(){var e=$(this).val(),t=$("#payable_amount").val();"2"==e?($(".amount").hide(),$("#amount").val(t),$("#amount").prop("readonly",!0)):"3"==e?($(".amount").show(),$("#amount").val(""),$("#amount").prop("readonly",!1)):($(".amount").hide(),$("#amount").prop("readonly",!1))})),listenKeyup("#amount",(function(){var e=parseFloat($("#payable_amount").val()),t=parseFloat($("#amount").val()),n=parseInt($("#payment_type").val());3===n&&e<t||2===n&&e<t?($("#error-msg").text("Amount should be less than payable amount"),$("#btnPay").addClass("disabled")):($("#error-msg").text(""),$("#btnPay").removeClass("disabled"))})),listenSubmit("#clientPaymentForm",(function(){if(""!==$("#error-msg").text())return!1})),listenChange("#payment_mode",(function(){paymentMode=$(this).val(),parseInt(paymentMode)})),listenSubmit("#clientPaymentForm",(function(e){var t=this;if(0==$("#payment_note").val().trim().length)return displayErrorMessage("Note field is Required"),!1;e.preventDefault();var n=$(this).find("#btnPay");setAdminBtnLoader(n);var a={amount:parseFloat($("#amount").val()),invoiceId:parseInt($("#invoice_id").val()),notes:$("#payment_note").val()};1==paymentMode?$.ajax({url:route("client.payments.store"),type:"POST",data:new FormData(this),processData:!1,contentType:!1,success:function(e){e.success&&(displaySuccessMessage(e.message),Livewire.dispatch("refreshDatatable"),Livewire.dispatch("resetPageTable"),window.location.href=route("client.invoices.index"))},error:function(e){displayErrorMessage(e.responseJSON.message)},complete:function(){setAdminBtnLoader(n)}}):2==paymentMode?$.post(invoiceStripePaymentUrl,a).done((function(e){var t=e.data.sessionId;stripe.redirectToCheckout({sessionId:t}).then((function(e){$(this).html("Make Payment").removeClass("disabled"),manageAjaxErrors(e)}))})).catch((function(e){$(t).html("Make Payment").removeClass("disabled"),manageAjaxErrors(e)})):3==paymentMode?$.ajax({type:"GET",url:route("client.paypal.init"),data:{amount:a.amount,invoiceId:a.invoiceId,notes:a.notes},success:function(e){if("CREATED"==e.status){var t="";$.each(e.links,(function(e,n){"approve"==n.rel&&(t=n.href)})),location.href=t}else location.href=e.url},error:function(e){displayErrorMessage(e.responseJSON.message)},complete:function(){setAdminBtnLoader(n)}}):5==paymentMode?$.ajax({type:"GET",url:route("razorpay.init"),data:$(this).serialize(),success:function(e){if(e.success){$("#clientPaymentModal").modal("hide");var t=e.data,n=t.id,a=t.amount,o=t.name,i=t.email,s=t.invoiceId,r=t.invoice_id,l=t.notes;options.description=JSON.stringify({invoice_id:r,notes:l}),options.order_id=n,options.amount=a,options.prefill.name=o,options.prefill.email=i,options.prefill.invoiceId=s;var m=new Razorpay(options);m.open(),m.on("payment.failed")}},error:function(e){displayErrorMessage(e.responseJSON.message)},complete:function(){setAdminBtnLoader(n)}}):6==paymentMode&&window.location.replace(route("paystack.init",{invoiceId:a.invoiceId,amount:a.amount,note:a.notes}))}))})();