/home/blackyak/www/wordpress/wp-content/plugins/wp-travel-engine/dist/public/trip-checkout.js
(()=>{var e={2508:()=>{window.wptravelengine_load_gateway_scripts?.paypal_express&&window.addEventListener("DOMContentLoaded",(()=>{const{wptravelengineCheckoutEvent:e}=window;e.on("checkoutFragmentsOnUpdate",(async function(e){"paypalexpress_enable"===e.payment_method&&await async function(e){const{form:t}=e;if(window.paypal){const{paypal:e}=window;try{e.Buttons({onInit:function(e,n){jQuery(t).parsley().isValid()||n.disable(),window.Parsley.on("form:success",(function(e){n.enable()}))},onClick(){jQuery(t).parsley().validate()},createOrder:function(e,t){let n=document.getElementById("wte-paypal-express-payment-button")?.dataset.payment;return n&&(n=JSON.parse(n)),t.order.create({purchase_units:[{amount:{value:Math.round(100*n.amount)/100,currency_code:n.currency_code}}]})},onApprove:function(e,n){const a=document.getElementById("wte-PayPalExpress-button");a&&(a.style.pointerEvents="none"),a&&(a.style.opacity="0.5");const o=document.createElement("input");return o.type="hidden",o.name="wte_paypal_express_payment_token",o.value=e.orderID,t.append(o),n.order.capture().then((function(e){!function(e){const n=document.createElement("input");n.type="hidden",n.name="wte_paypal_express_payment_details",n.value=JSON.stringify(e),t.append(n),t.submit()}(e)}))},onCancel:function(e){console.log("checkout.js payment cancelled",JSON.stringify(e,0,2))},onError:function(e){console.error(e)}}).render("#wte-paypal-express-payment-button")}catch(e){}}}(e)}))}))},9171:()=>{window.wptravelengine_load_gateway_scripts?.authorize_net&&window.addEventListener("DOMContentLoaded",(()=>{const{wptravelengineCheckoutEvent:e}=window;e.on("checkoutFragmentsOnUpdate",(async function(e){if("authorize-net-payment"===e?.payment_method){const t=document.createElement("script"),n=e?.form,a=n.querySelector(".wte-authorize-net-payment-button");t.src=a?.getAttribute("data-acceptui-url")||"",document.head.appendChild(t),await async function(e){const{form:t}=e;window.anetResponseHandler=e=>{if(console.debug({response:e}),"Error"===e.messages.resultCode)for(var n=0;n<e.messages.message.length;)alert(e.messages.message[n].code+": "+e.messages.message[n].text),n+=1;else a=e.opaqueData,document.getElementById("dataDescriptor").value=a?.dataDescriptor,document.getElementById("dataValue").value=a?.dataValue,t.submit();var a}}(e)}}))}))}},t={};function n(a){var o=t[a];if(void 0!==o)return o.exports;var s=t[a]={exports:{}};return e[a](s,s.exports,n),s.exports}(()=>{"use strict";class e{constructor(){this.events={}}on(e,t){this.events[e]||(this.events[e]=[]),this.events[e].push(t)}off(e,t){this.events[e]&&(this.events[e]=this.events[e].filter((e=>e!==t)),0===this.events[e].length&&delete this.events[e])}dispatch(e,...t){this.events[e]&&this.events[e].forEach((e=>{e(...t)}))}once(e,t){const n=(...a)=>{t(...a),this.off(e,n)};this.on(e,n)}}(()=>{new MutationObserver((()=>{const e=document.querySelectorAll(".wpte-material-ui-input-control");e&&e.forEach((e=>{const t=e.querySelector('input:not([type="hidden"])')||e.querySelector("select")||e.querySelector("textarea");((e,t)=>{e.value?t.classList.add("focus"):t.classList.remove("focus")})(t,e),"date"===t.type?e.classList.add("focus"):(t.addEventListener("blur",(()=>{t.value?e.classList.add("focus"):e.classList.remove("focus")})),t.addEventListener("focus",(()=>{e.classList.add("focus")})))}))})).observe(document.body,{childList:!0,subtree:!0});const t=document.querySelectorAll(".wpte-checkout__box");t&&t.forEach((e=>{if(e.matches(".collapsible")){const t=e.querySelector(".wpte-checkout__box-toggle-button"),n=t?.parentElement;n?.addEventListener("click",(()=>{const t=e.querySelector(".wpte-checkout__box-content");if(e.matches(".open"))t.style.height=t.clientHeight+24+"px",setTimeout((()=>{t.style.height="0px",t.style.paddingTop="0px",t.addEventListener("transitionend",(()=>{e.classList.remove("open")}),{once:!0})}),0);else{e.classList.add("open"),t.style.height="auto";let n=t.clientHeight+24+"px";t.style.height="0px",setTimeout((()=>{t.style.height=n,t.style.paddingTop="24px"}),0)}}))}})),new MutationObserver((()=>{const e=e=>{e.querySelector('option[value=""]').selected?e.classList.add("empty"):e.classList.remove("empty")},t=document.querySelectorAll("select.wpte-checkout__input");t&&t.forEach((t=>{e(t),t.addEventListener("change",(()=>{e(t)}))}));const n=document.querySelectorAll(".wpte-checkout__file-control");n&&n.forEach((e=>{const t=e.querySelector("input"),n=e.querySelector("label");t.addEventListener("change",(e=>{const t=e.target.files[0];t&&(n.textContent=t.name)}))}));const a=document.querySelectorAll(".wpte-checkout__tooltip");a&&a.forEach((e=>{try{tippy(e,{content:e=>e.dataset.content})}catch(e){console.error("Error loading tippy:",e.message)}}))})).observe(document.body,{childList:!0,subtree:!0});const n=e=>{jQuery(e)?.parsley()&&jQuery(e).parsley().validate()};document.addEventListener("DOMContentLoaded",(function(){const e=document.getElementById("wptravelengine-checkout__form");e.addEventListener("focusout",(e=>{n(e.target)}),!0);const t=jQuery(e).parsley({errorsContainer:function(e){const t=e.element.parentElement.parentElement.className.split(" ")[0];return e.$element.closest(`.${t}`)}});t?.on("field:validated",(function(e){const t=document.querySelectorAll(".wpte-checkout__box");e.isValid()?e.element.parentElement.classList.remove("invalid"):e.element.parentElement.classList.add("invalid"),t.forEach((e=>{const t=e.querySelector(".wpte-checkout__box-content");t&&(t.style.height="auto")}))}))}));const a=document.querySelector(".wpte-checkout__payment-options");let o=a?.parentElement,s=a?.nextElementSibling,i=null;const c=e=>{document.querySelectorAll(`input[name="${e.name}"]`).forEach((e=>!e.checked&&e.parentNode.classList.remove("checked"))),e.checked&&(e.parentNode.classList.add("checked"),"booking_only"===document.querySelector('input[name="wpte_checkout_paymnet_method"]:checked')?.value?(i=a,i?i?.remove():a?.remove()):i&&(o.insertBefore(i,s),i.querySelector('input[name="wp_travel_engine_payment_mode"]:checked')))},r=document.querySelectorAll('input[type="radio"]');r&&r.forEach((e=>{c(e),i=a,e.addEventListener("change",(t=>{c(e)}))}));const l=document.getElementById("wpte-lead-traveller"),d=document.getElementById("wpte-copy-from-lead-travelers");if(l&&d){const t=d.closest(".wpte-checkout__box-content"),a=["fname","lname","email","address","city","country"],o=new e,s=e=>{o.dispatch("copyFromLeadTraveler",{changedElement:e.target,changedElementValue:e.target.value})};o.on("copyFromLeadTraveler",(function(e={}){const{changedElement:o=null,changedElementValue:s=null}=e;a.forEach((e=>{const a=l.querySelector(`[name*="[${e}]"]`),i=t.querySelector(`[name="billing[${e}]"]`);if(!a||!i)return;if(o&&!a.isSameNode(o))return;const c=null!=s?s:a.value;i.value=c,i.closest(".wpte-material-ui-input-control")?.classList.add("focus"),i.classList.remove("empty"),n(i)}))})),d.addEventListener("change",(()=>{d.checked?(o.dispatch("copyFromLeadTraveler"),l.addEventListener("input",s)):(l.removeEventListener("input",s),t.querySelectorAll("input, select").forEach((e=>{"select"===e.tagName.toLowerCase()?e.selectedIndex=0:e.value=""})))}))}})();const{wpxhr:{root:t,nonce:a}}=window.wteL10n,o={ajaxurl:t,nonce:a,async request(e={},t={},n={}){const a=Object.entries({_nonce:this.nonce,action:"wptravelengine_page_checkout",...t}).reduce(((e,[t,n])=>`${e}&${t}=${n}`),"");return(await fetch(`${this.ajaxurl}?${a}`,{method:"POST",body:JSON.stringify(e),...n})).json()},async getPaymentMethods(e={}){return this.request(e,{_action:"update_cart"})}};window.checkoutRequests=o;const s=o;async function i(e,t={}){const n=new FormData;n.append("action",e),Object.entries(t).forEach((([e,t])=>{n.append(e,t)}));const a=e=>{const t=document.querySelectorAll(`[name^="${e}["]`)||[],a={};return t.forEach((t=>{const o=t.name.match(new RegExp(`${e}\\[(\\d+)?\\]\\[(.*?)\\]|${e}\\[(.*?)\\]`));if(o){const s=o[1],i=o[2]||o[3];void 0!==s?(a[s]||(a[s]={}),a[s][i]=t.value,n.append(`${e}[${s}][${i}]`,t.value)):(a[i]=t.value,n.append(`${e}[${i}]`,t.value))}})),a},o=a("billing"),s=a("travellers"),i=a("emergency"),c=document.querySelector('[name="wptravelengine_additional_note"]')||"";c&&n.append("wptravelengine_additional_note",c.value),n.append("formData",JSON.stringify({billing:o,travellers:s,emergency:i}));try{const e=await fetch(wteL10n.wpxhr.root,{method:"POST",body:n});return{...await e.json(),billingData:o,travellersData:s,emergencyData:i}}catch(e){throw console.error("Error sending coupon request:",e),e}}const c=window.lodash;function r(e){const t={};for(const[n,a]of e.entries()){const e=n.replace(/\]/g,"").split(/\[/);(0,c.set)(t,e,a)}return t}window.addEventListener("DOMContentLoaded",(()=>{const{wptravelengineCheckoutEvent:e}=window;document.addEventListener("click",(e=>{const t=e.target;(t.matches("[data-apply-coupon]")||t.matches("[data-remove-coupon]")||e.target.closest("[data-remove-coupon]"))&&(e.preventDefault(),function(e){if("true"===e.dataset.processing)return;const t=e.hasAttribute("data-apply-coupon"),n=t?document.querySelector(e.getAttribute("data-coupon-source")):null,a=e.dataset.couponNonce;e.dataset.processing="true",e.disabled=!0;const o=()=>{const e=document.querySelector("[name=wpte_checkout_paymnet_method]:checked");e&&sessionStorage.setItem("wptravelengine_selected_checkout_payment",e.value)};t?async function(e,t={}){return t.CouponCode=e,i("wte_session_cart_apply_coupon",t)}(n?.value||"",{_nonce:a}).then((e=>{var t,n;if(!e.success)throw new Error(null!==(t=null!==(n=e.data.message)&&void 0!==n?n:e.data?.[0]?.message)&&void 0!==t?t:"Something went wrong");o(),window.location.reload()})).catch((t=>{n.parentElement.classList.add("invalid");const a=document.querySelector("[data-coupon-error-message]");a&&(a.style.removeProperty("display"),a.innerHTML=t.message),e.dataset.processing="false",e.disabled=!1})):async function(e={}){return i("wte_session_cart_reset_coupon",e)}({_nonce:a}).then((e=>{e.success&&e.data.url&&(window.location.href=e.data.url),o()})).catch((e=>{console.log(e)})).finally((()=>{e.dataset.processing="false",e.disabled=!1}))}(e.target.closest("[data-remove-coupon]")||t))}));const t=document.getElementById("wptravelengine-checkout__form");if(!t)return;const n=(e=":checked")=>t.querySelector(".wpte-checkout__payment-method [name=wpte_checkout_paymnet_method]"+e),a=(e=":checked")=>t.querySelector("[name=wp_travel_engine_payment_mode]"+e),o=e=>{e&&(e.checked=!0,e.dispatchEvent(new Event("change")))},c=t.querySelectorAll(".wpte-checkout__payment-methods [name=wpte_checkout_paymnet_method]");var l;c.forEach((e=>{e.addEventListener("click",(e=>{sessionStorage.setItem("wptravelengine_selected_checkout_payment",e.target.value)}))})),!n()&&c.length>0&&o(null!==(l=c[0])&&void 0!==l?l:n(":first-child"));const d=sessionStorage.getItem("wptravelengine_selected_checkout_payment");function u(e=!0,n=[]){const a=[document.querySelector("[data-cart-summary]"),t.querySelector("[data-checkout-payment-methods]"),t.querySelector("[type=submit]")];n.length>0&&a.push(...n),a.forEach((t=>{t&&(["button","input"].includes(t.tagName.toLowerCase())?t.disabled=e:t.classList.toggle("wpte-updating",e))}))}d&&(o(n(`[value="${d}"]`)),sessionStorage.removeItem("wptravelengine_selected_checkout_payment")),window.wteL10n={...window.wteL10n,checkout:{...window.wteL10n?.checkout,setLoading:u}},t.addEventListener("submit",(()=>{n()?.id&&u(!0),e.dispatch("proceedCheckoutForm",{form:t}),sessionStorage.removeItem("wptravelengine_selected_checkout_payment")}));const{direct_pay_gateways:p=["booking_only"],has_booking_ref:m=!1}=window.wptravelengineCart,h=e=>!t.querySelector("[data-checkout-payment-modes] .wpte-checkout__payment-options")||p.includes(e);let y=0;async function g(t,i){var c;const{form:l}=t;u(!0);const d=null!==(c=n()?.value)&&void 0!==c?c:"booking_only";let p=i||a()?.value||a(":first-child")?.value||(m?"due":"full_payment");p=++y>2?p||"full_payment":p,h(d)&&(p="full_payment");const v=await s.getPaymentMethods({payment_method:d,payment_mode:p,formData:r(new FormData(l))});if(v.reload&&window.location.reload(),v.success&&v.fragments){if(Object.entries(v.fragments).forEach((([e,t])=>{const n=document.querySelector(e);n&&(n.innerHTML=t)})),!p)return await g(t);if(!h(d)&&!a())return await g(t,a(":first-child")?.value);n()||o(n(":first-child")),e.dispatch("checkoutFragmentsOnUpdate",{payment_method:d,payment_mode:p,form:l,cart_totals:v?.cart_totals}),u(!1),y=0}l.querySelector(".wpte-checkout__box:last-child").scrollIntoView()}t&&setTimeout((()=>{document.dispatchEvent(new CustomEvent("checkoutFormOnReady",{detail:{form:t}}))}),400),t.addEventListener("change",(function(t){e.dispatch("checkoutFormOnChange",t)})),document.addEventListener("checkoutFormOnReady",(async function(e){await g(e.detail)})),e.on("checkoutFormOnChange",(async function(e){(e.target.matches("[name=wpte_checkout_paymnet_method]")||e.target.matches("[name=wp_travel_engine_payment_mode]")||"update"===e.target.dataset.onchange)&&await g({form:t})}))})),(()=>{if(window.wptravelengine_load_gateway_scripts?.stripe){class e{constructor(e){this.form=e;const{Stripe:t,wte_stripe:{publishable_key:n,hide_postal_code:a}}=window;this.settings={publishable_key:n,hide_postal_code:a},this.stripe=t(n,{betas:["custom_checkout_beta_5"]}),this.cardMounted=!1,this.createCard(),this.handleFormChange=this.handleFormChange.bind(this),this.form.addEventListener("submit",(e=>this.handleSubmit(e,this)))}createCard(){const e=this.stripe.elements(),t={base:{color:"#32325d",fontFamily:"'Helvetica Neue', Helvetica, sans-serif",fontSmoothing:"antialiased",fontSize:"16px","::placeholder":{color:"#aab7c4"},lineHeight:"24px"},invalid:{color:"#fa755a",iconColor:"#fa755a"}};this.card=e.create("card",{style:{...t,base:{...t.base}},hidePostalCode:1===parseInt(this.settings.hide_postal_code)})}mountCard(e=!0){const t=document.getElementById("stripe-payment-element");this.cardMounted||(this.card.mount("#stripe-payment-element"),this.cardMounted=!0),e?t.style.removeProperty("display"):t.style.display="none"}async init(){const{form:e}=this.data;window?.Stripe&&window?.wte_stripe?.publishable_key&&(this.callback&&this.callback({cleanup:()=>{this.card.unmount(),this.mounted=!1}}),document.getElementById("wte-stripe-payment-button"),document.getElementById("stripe-card-errors"),e.removeEventListener("click",this.handleSubmit.bind(this)),e.addEventListener("click",this.handleSubmit.bind(this)))}showMessage(e){const t=document.getElementById("stripe-card-errors");t.classList.remove("hidden"),t.textContent=e,t.style.color="red",setTimeout((()=>{t.classList.add("hidden"),t.textContent=""}),4e3)}setLoading(e){const t=document.getElementById("wte-stripe-payment-button");t&&(t.disabled=e)}async handleSubmit(e,t){var n;if("stripe_payment"===(null!==(n=t.form.querySelector("[name=wpte_checkout_paymnet_method]:checked")?.value)&&void 0!==n?n:"booking_only")){e.preventDefault(),this.setLoading(!0);try{const e=await s.request({_action:"stripe_create_payment_intent"});if(e.success){var a,o;const{client_secret:n}=e.data,s=await this.stripe.confirmCardPayment(n,{payment_method:{card:this.card,billing_details:{name:null!==(a=document.getElementById("billing_fname")?.value)&&void 0!==a?a:"",email:null!==(o=document.getElementById("billing_email")?.value)&&void 0!==o?o:""}}}),{error:i,paymentIntent:c}=s;if(i&&(this.showMessage(i.message),this.setLoading(!1)),"succeeded"===c?.status){const e=document.createElement("input");e.name="stripeToken",e.type="hidden",e.value=c.id,t.form.appendChild(e),this.form.removeEventListener("submit",this.handleSubmit),this.setLoading(!1),this.form.submit(),this.setLoading(!0)}}}catch(e){this.showMessage(e.message),this.setLoading(!1)}}}handleFormChange(){var e;const t=this.form,n=null!==(e=t.querySelector("[name=wpte_checkout_paymnet_method]:checked")?.value)&&void 0!==e?e:"booking_only";this.mountCard("stripe_payment"===n)}}window.addEventListener("DOMContentLoaded",(()=>{if(!window.Stripe)return;const t=window.wptravelengineCheckoutEvent;document.addEventListener("checkoutFormOnReady",(async function(n){var a;const o=new e(n.detail.form);"stripe_payment"===(null!==(a=o.form.querySelector("[name=wpte_checkout_paymnet_method]:checked")?.value)&&void 0!==a?a:"booking_only")&&o.mountCard(),t.on("checkoutFormOnChange",o.handleFormChange),t.on("checkoutFragmentsOnUpdate",(e=>o.handleFormChange))}))}))}})(),n(2508);const{__:l}=wp.i18n;(()=>{async function e(t){if(!window.snap)return;t.preventDefault();const{snap:n}=window,a=t.target,o=new FormData(a),i={};await o.forEach(((e,t)=>i[t]=e));const c=await s.request({_action:"midtrans_snap_token",...i});if(c.success){const{snap_token:t}=c.data;n.pay(t,{onSuccess:function(t){const n=document.createElement("input");n.type="hidden",n.name="midtrans_success_details",n.value=JSON.stringify(t),a.append(n),a.removeEventListener("submit",e),a.submit()},onPending:function(e){alert(l("wating your payment!","wp-travel-engine"))},onError:function(e){alert(l("payment failed!","wp-travel-engine")),console.log({result:e})},onClose:function(){alert(l("You closed the popup without finishing the payment.","wp-travel-engine")),a.removeEventListener("submit",e)}})}}window.wptravelengine_load_gateway_scripts?.midtrans&&window.addEventListener("DOMContentLoaded",(()=>{const{wptravelengineCheckoutEvent:t}=window;t.on("checkoutFragmentsOnUpdate",(async function(t){t.form.removeEventListener("submit",e),"midtrans_enable"===t?.payment_method&&t.form.addEventListener("submit",e)}))}))})(),n(9171),window.wptravelengine_load_gateway_scripts?.payu_money_bolt&&window.addEventListener("DOMContentLoaded",(()=>{const{wptravelengineCheckoutEvent:e}=window;e.on("checkoutFragmentsOnUpdate",(async function(e){"payu_money_enable"===e?.payment_method&&jQuery(e.form).parsley().isValid()&&await async function(e){var t,n,a,o,i,c;const{form:r}=e,l=new FormData(r),d={};await l.forEach(((e,t)=>d[t]=e));let u=document.getElementById("wte-payu-money-enable-button")?.dataset.payment;u&&(u=JSON.parse(u));var p={key:payu.settings.merchantKey,txnid:"1234567890",hash:"",amount:u.amount,firstname:null!==(t=d["billing[fname]"])&&void 0!==t?t:"",lastname:null!==(n=d["billing[lname]"])&&void 0!==n?n:"",phone:"",email:null!==(a=d["billing[email]"])&&void 0!==a?a:"",country:null!==(o=d["billing[country]"])&&void 0!==o?o:"",address1:null!==(i=d["billing[address]"])&&void 0!==i?i:"",productinfo:null!==(c=document.querySelector(".wpte-checkout__trip-name").innerText)&&void 0!==c?c:"",surl:"https://sucess-url.in",furl:"https://fail-url.in",udf5:""},m=Object.assign({},p),h={responseHandler:function(e){"SUCCESS"===e.response.txnStatus&&(r.append(['<input type="hidden" id="billing[payment][key]" name="billing[payment][key]" value="'+e.response.key+'" />','<input type="hidden" id="billing[payment][amount]" name="billing[payment][amount]" value="'+e.response.amount+'" />','<input type="hidden" id="billing[payment][productinfo]" name="billing[payment][productinfo]" value="'+e.response.productinfo+'" />','<input type="hidden" id="billing[payment][firstname]" name="billing[payment][firstname]" value="'+e.response.firstname+'" />','<input type="hidden" id="billing[payment][email]" name="billing[payment][email]" value="'+e.response.email+'" />','<input type="hidden" id="billing[payment][udf5]" name="billing[payment][udf5]" value="'+e.response.udf5+'" />','<input type="hidden" id="billing[payment][mihpayid]" name="billing[payment][mihpayid]" value="'+e.response.mihpayid+'" />','<input type="hidden" id="billing[payment][wte_payment_gateway]" name="billing[payment][wte_payment_gateway]" value="payu_money_bolt" />','<input type="hidden" id="billing[payment][txnid]" name="billing[payment][txnid]" value="'+e.response.txnid+'" />','<input type="hidden" id="billing[payment][status]" name="billing[payment][status]" value="'+e.response.txnStatus+'" />','<input type="hidden" id="billing[payment][hash]" name="billing[payment][hash]" value="'+e.response.hash+'" />'].join("")),document.getElementById("wte-payu-money-enable-button").click())},catchException:function(e){console.error(e.response.error)}};document.getElementById("wte-payu-money-enable-button").addEventListener("click",(async function(e){e.preventDefault(),e.stopPropagation();const t=await s.request({_action:"payu_money_bolt_generate_hash",...m});t.success?(p.hash=t.data.hash,bolt.launch(p,h)):console.error(t.message)}))}(e)}))})),window.wptravelengineCheckoutEvent=new e})()})();