/*
 =======================================================================*\
|| ###################################################################### ||
|| # vBulletin 6.2.3
|| # ------------------------------------------------------------------ # ||
|| # Copyright 2000-2026 MH Sub I, LLC dba vBulletin. All Rights Reserved.  # ||
|| # This file may not be redistributed in whole or significant part.   # ||
|| # ----------------- VBULLETIN IS NOT FREE SOFTWARE ----------------- # ||
|| # http://www.vbulletin.com | http://www.vbulletin.com/license.html   # ||
|| ###################################################################### ||
\*========================================================================*/
vBulletin.precache("paymentapi payment_api_error paymentapi_paymentsubmitted paypal2_paymentsuccess paypal2_paymentsuccess_reg paypal2_waitingforwebhook".split(" "),[]);vBulletin.ensureObj("paypal2");
((l,h,e)=>{function u(a,q,n){function p(c,m,v,w){c={style:{tagline:!1},onError(d){g()}};let t=r;f.data("recurring")?(c.createSubscription=function(d,k){return f.data("subscriptionid")},c.onApprove=async function(d){await m.AJAX({call:"/ajax/api/paidsubscription/completePaypalSubscription",data:{order_id:d.orderID,subscription_id:d.subscriptionID},success(k,x,y){k.success&&(m.dialogtools.alert("paymentapi_paymentsubmitted","paypal2_waitingforwebhook"),t())}})}):(c.createOrder=async function(d,k){d=
await m.AJAX({call:"/ajax/api/paidsubscription/preparePayPalOrder",data:b.serializeArray()});if(d.id)return d.id},c.onApprove=async function(d){await m.AJAX({call:"/ajax/api/paidsubscription/completePayPalOrder",data:{order_id:d.orderID},success(k,x,y){console.log(k);k.success&&(m.dialogtools.alert("paymentapi_paymentsubmitted",isRegistration?"paypal2_paymentsuccess_reg":"paypal2_paymentsuccess"),t())}})});v.Buttons(c).render(w)}const f=l(n),b=f.closest("form"),g=()=>{h.dialogtools.alert("paymentapi",
"payment_api_error","error")};isRegistration="registration"===f.data("context");let r;if(isRegistration){let c=b.closest(".js-dialog");c.find(".js-button-primary").hide();r=()=>{f.hide();c.dialog("close");h.ensureMethod(e,"regfinal")()}}else b.find(":submit:enabled").hide(),r=()=>{f.hide()};h.ready("paypal2").then(()=>z(h,a,q)).then(c=>p(jQuery,h,window[c],n)).catch(c=>{console.log(c);g()})}function z(a,q,n){return new Promise((p,f)=>{let b="paypal2_"+q.toUpperCase()+(n?"_recurring":"_onetime");a.ensureObj("urls",
{},e);a.ensureObj("urls_loaded",{},e);if(e.urls.hasOwnProperty(b))if(e.urls_loaded.hasOwnProperty(b))p(b);else{e.urls_loaded[b]=!0;let g=document.createElement("script");g.onload=()=>p(b);g.onerror=()=>f("Failed to load PayPal JS for "+b+" :"+e.urls[b]);g.setAttribute("src",e.urls[b]);g.setAttribute("data-namespace",b);document.head.appendChild(g)}else f("Failed to find JS URL cache for "+b)})}l(document).on("vb-instrument",a=>{a=l(a.target).find(".js-paypal2-btn-container");0<a.length&&!a.data("paypal2-initialized")&&
(a.data("paypal2-initialized",!0),u(a.data("currency"),a.data("recurring"),"#"+a.attr("id")))});l(()=>{let a=l(".js-paypal2-urls");0<a.length&&(e.urls=a.data("paypalUrls"),h.ready("paypal2").resolve())})})(jQuery,vBulletin,vBulletin.paypal2);
