@whop/checkout
Version:
Embed Whop checkout on any website
1 lines • 12 kB
JavaScript
function e(e,t){if(t==null||t>e.length)t=e.length;for(var r=0,o=new Array(t);r<t;r++)o[r]=e[r];return o}function t(e){if(Array.isArray(e))return e}function r(t){if(Array.isArray(t))return e(t)}function o(e,t,r,o,n,a,i){try{var d=e[a](i);var s=d.value}catch(e){r(e);return}if(d.done){t(s)}else{Promise.resolve(s).then(o,n)}}function n(e){return function(){var t=this,r=arguments;return new Promise(function(n,a){var i=e.apply(t,r);function d(e){o(i,n,a,d,s,"next",e)}function s(e){o(i,n,a,d,s,"throw",e)}d(undefined)})}}function a(e,t){if(t!=null&&typeof Symbol!=="undefined"&&t[Symbol.hasInstance]){return!!t[Symbol.hasInstance](e)}else{return e instanceof t}}function i(e){if(typeof Symbol!=="undefined"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function d(e,t){var r=e==null?null:typeof Symbol!=="undefined"&&e[Symbol.iterator]||e["@@iterator"];if(r==null)return;var o=[];var n=true;var a=false;var i,d;try{for(r=r.call(e);!(n=(i=r.next()).done);n=true){o.push(i.value);if(t&&o.length===t)break}}catch(e){a=true;d=e}finally{try{if(!n&&r["return"]!=null)r["return"]()}finally{if(a)throw d}}return o}function s(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function u(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function l(e,r){return t(e)||d(e,r)||f(e,r)||s()}function h(e){return t(e)||i(e)||f(e)||s()}function c(e){return r(e)||i(e)||f(e)||u()}function p(e){"@swc/helpers - typeof";return e&&typeof Symbol!=="undefined"&&e.constructor===Symbol?"symbol":typeof e}function f(t,r){if(!t)return;if(typeof t==="string")return e(t,r);var o=Object.prototype.toString.call(t).slice(8,-1);if(o==="Object"&&t.constructor)o=t.constructor.name;if(o==="Map"||o==="Set")return Array.from(o);if(o==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o))return e(t,r)}function w(e,t){var r,o,n,a={label:0,sent:function(){if(n[0]&1)throw n[1];return n[1]},trys:[],ops:[]},i=Object.create((typeof Iterator==="function"?Iterator:Object).prototype);return i.next=d(0),i["throw"]=d(1),i["return"]=d(2),typeof Symbol==="function"&&(i[Symbol.iterator]=function(){return this}),i;function d(e){return function(t){return s([e,t])}}function s(d){if(r)throw new TypeError("Generator is already executing.");while(i&&(i=0,d[0]&&(a=0)),a)try{if(r=1,o&&(n=d[0]&2?o["return"]:d[0]?o["throw"]||((n=o["return"])&&n.call(o),0):o.next)&&!(n=n.call(o,d[1])).done)return n;if(o=0,n)d=[d[0]&2,n.value];switch(d[0]){case 0:case 1:n=d;break;case 4:a.label++;return{value:d[1],done:false};case 5:a.label++;o=d[1];d=[0];continue;case 7:d=a.ops.pop();a.trys.pop();continue;default:if(!(n=a.trys,n=n.length>0&&n[n.length-1])&&(d[0]===6||d[0]===2)){a=0;continue}if(d[0]===3&&(!n||d[1]>n[0]&&d[1]<n[3])){a.label=d[1];break}if(d[0]===6&&a.label<n[1]){a.label=n[1];n=d;break}if(n&&a.label<n[2]){a.label=n[2];a.ops.push(d);break}if(n[2])a.ops.pop();a.trys.pop();continue}d=t.call(e,a)}catch(e){d=[6,e];o=0}finally{r=n=0}if(d[0]&5)throw d[1];return{value:d[0]?d[1]:void 0,done:true}}}import{b as v,c as C}from"./chunk-V6AIUOX7.mjs";import{c as y,e as m,f as k,g as g,h as b,i as A,j as S,k as P,m as I,n as T,r as E,s as L,u as x,v as j}from"./chunk-VM3BGBF7.mjs";var O="data-whop-checkout-style-";function H(e){var t={};var r=true,o=false,n=undefined;try{for(var a=e.attributes[Symbol.iterator](),i;!(r=(i=a.next()).done);r=true){var d=i.value;if(d.name.startsWith(O)){var s=d.name.slice(O.length),u=d.value,l=h(s.split("-")),c=l[0],p=l.slice(1);if(c&&p.length>0){var f=p.reduce(function(e,t,r){if(r===0)return t;var o=h(t),n=o[0],a=o.slice(1);return"".concat(e).concat(n.toUpperCase()).concat(a.join(""))},"");var w;(w=t[c])!==null&&w!==void 0?w:t[c]={},t[c][f]=u}}}}catch(e){o=true;n=e}finally{try{if(!r&&a.return!=null){a.return()}}finally{if(o){throw n}}}return t}function N(e){var t={};return e.dataset.whopCheckoutThemeAccentColor&&(t.accentColor=e.dataset.whopCheckoutThemeAccentColor),e.dataset.whopCheckoutThemeHighContrast&&(t.highContrast=e.dataset.whopCheckoutThemeHighContrast==="true"),e.dataset.whopCheckoutThemeBackgroundColor&&(t.backgroundColor=e.dataset.whopCheckoutThemeBackgroundColor),e.dataset.whopCheckoutThemeBorderRadius&&(t.borderRadius=e.dataset.whopCheckoutThemeBorderRadius),t}function M(e){var t={};var r,o,n,a,i,d,s,u,l,h,c,p,f,w;return e.dataset.whopCheckoutPrefillEmail&&(t.email=e.dataset.whopCheckoutPrefillEmail),e.dataset.whopCheckoutPrefillName&&((r=t.address)!==null&&r!==void 0?r:t.address={},t.address.name=e.dataset.whopCheckoutPrefillName),e.dataset.whopCheckoutPrefillAddressLine1&&((o=t.address)!==null&&o!==void 0?o:t.address={},t.address.line1=e.dataset.whopCheckoutPrefillAddressLine1),e.dataset.whopCheckoutPrefillAddressLine2&&((n=t.address)!==null&&n!==void 0?n:t.address={},t.address.line2=e.dataset.whopCheckoutPrefillAddressLine2),e.dataset.whopCheckoutPrefillAddressCity&&((a=t.address)!==null&&a!==void 0?a:t.address={},t.address.city=e.dataset.whopCheckoutPrefillAddressCity),e.dataset.whopCheckoutPrefillAddressCountry&&((i=t.address)!==null&&i!==void 0?i:t.address={},t.address.country=e.dataset.whopCheckoutPrefillAddressCountry),e.dataset.whopCheckoutPrefillAddressState&&((d=t.address)!==null&&d!==void 0?d:t.address={},t.address.state=e.dataset.whopCheckoutPrefillAddressState),e.dataset.whopCheckoutPrefillAddressPostalCode&&((s=t.address)!==null&&s!==void 0?s:t.address={},t.address.postalCode=e.dataset.whopCheckoutPrefillAddressPostalCode),e.dataset.whopCheckoutPrefillShippingName&&((u=t.shippingAddress)!==null&&u!==void 0?u:t.shippingAddress={},t.shippingAddress.name=e.dataset.whopCheckoutPrefillShippingName),e.dataset.whopCheckoutPrefillShippingAddressLine1&&((l=t.shippingAddress)!==null&&l!==void 0?l:t.shippingAddress={},t.shippingAddress.line1=e.dataset.whopCheckoutPrefillShippingAddressLine1),e.dataset.whopCheckoutPrefillShippingAddressLine2&&((h=t.shippingAddress)!==null&&h!==void 0?h:t.shippingAddress={},t.shippingAddress.line2=e.dataset.whopCheckoutPrefillShippingAddressLine2),e.dataset.whopCheckoutPrefillShippingAddressCity&&((c=t.shippingAddress)!==null&&c!==void 0?c:t.shippingAddress={},t.shippingAddress.city=e.dataset.whopCheckoutPrefillShippingAddressCity),e.dataset.whopCheckoutPrefillShippingAddressCountry&&((p=t.shippingAddress)!==null&&p!==void 0?p:t.shippingAddress={},t.shippingAddress.country=e.dataset.whopCheckoutPrefillShippingAddressCountry),e.dataset.whopCheckoutPrefillShippingAddressState&&((f=t.shippingAddress)!==null&&f!==void 0?f:t.shippingAddress={},t.shippingAddress.state=e.dataset.whopCheckoutPrefillShippingAddressState),e.dataset.whopCheckoutPrefillShippingAddressPostalCode&&((w=t.shippingAddress)!==null&&w!==void 0?w:t.shippingAddress={},t.shippingAddress.postalCode=e.dataset.whopCheckoutPrefillShippingAddressPostalCode),t}function U(e,t){var r="whopCheckout"+t.split("-").map(function(e){return e[0].toUpperCase()+e.slice(1)}).join("");return e.dataset[r]}function B(e){var t;var r,o;if(e.dataset.whopCheckoutMounted)return;var n=e.dataset.whopCheckoutPlanId,a=e.dataset.whopCheckoutSession;if(!n&&!a)return;var i=n||a;i&&j(i);var d;var s=T(n,e.dataset.whopCheckoutTheme,a,e.dataset.whopCheckoutOrigin,e.dataset.whopCheckoutHidePrice==="true",e.dataset.whopCheckoutSkipRedirect==="true"||!!e.dataset.whopCheckoutOnComplete,e.dataset.whopCheckoutSkipUtm==="true"?void 0:x(),H(e),M(e),N(e),e.dataset.whopCheckoutHideSubmitButton==="true",e.dataset.whopCheckoutHideTos==="true",e.dataset.whopCheckoutHideEmail==="true",e.dataset.whopCheckoutDisableEmail==="true",e.dataset.whopCheckoutHideAddress==="true",e.dataset.whopCheckoutAffiliateCode,P(e.dataset.whopCheckoutSetupFutureUsage),(d=e.dataset.whopCheckoutReturnUrl)!==null&&d!==void 0?d:e.dataset.whopCheckoutRedirectUrl,e.dataset.whopCheckoutStateId,e.dataset.whopCheckoutPromoCode,I(e.dataset.whopCheckoutEnvironment),e.dataset.whopCheckoutWuid,e.dataset.whopCheckoutAdaptivePricing==="true",e.dataset.whopCheckoutCollectPhoneNumbers==="true"?!0:e.dataset.whopCheckoutCollectPhoneNumbers==="false"?!1:void 0,e.dataset.whopCheckoutLocale),u=document.createElement("iframe");u.src=s,u.style.width="100%",u.style.height="480px",u.style.border="none",u.style.overflow="hidden",u.style.background="transparent",u.style.colorScheme="normal",(t=u.sandbox).add.apply(t,c(E)),u.allow=L,e.dataset.whopCheckoutMounted="true",e.appendChild(u);var l=e.id;l&&((r=window.wco)===null||r===void 0?void 0:r.identifiedFrames.set(l,u),u.dataset.whopCheckoutIdentifier=l);var h=v(u,{getCallback:function(t){return U(e,t)},getOverlayContext:function(){return{theme:e.dataset.whopCheckoutTheme,origin:e.dataset.whopCheckoutOrigin,environment:I(e.dataset.whopCheckoutEnvironment),locale:e.dataset.whopCheckoutLocale}},onOverlayClose:function(){try{var e;var t=new URL(u.src).origin;(e=u.contentWindow)===null||e===void 0?void 0:e.postMessage({__scope:"whop-embedded-checkout",event:"overlay-closed"},t)}catch(e){}}});(o=window.wco)===null||o===void 0?void 0:o.frames.set(u,h)}if((typeof window==="undefined"?"undefined":p(window))<"u"&&window.wco&&!window.wco.listening){var R=function e(e){var t;var r=(t=window.wco)===null||t===void 0?void 0:t.identifiedFrames.get(e);if(!r)throw new Error("No embed with identifier ".concat(e," found."));return r};X=R,C(),window.wco.submit=function(e,t){return n(function(){return w(this,function(r){switch(r.label){case 0:return[4,S(R(e),t)];case 1:r.sent();return[2]}})})()},window.wco.getEmail=function(e,t){return k(R(e),t)},window.wco.setEmail=function(e,t,r){return m(R(e),t,r)},window.wco.getAddress=function(e,t){return A(R(e),t)},window.wco.setAddress=function(e,t,r){return g(R(e),t,r)},window.wco.setDisplayCurrency=function(e,t,r){return b(R(e),t,r)},window.wco.getAvailableCurrencies=function(e){var t;var r;return(r=(t=window.wco)===null||t===void 0?void 0:t.availableCurrencies.get(e))!==null&&r!==void 0?r:null};var F=new MutationObserver(function(e){var t=true,r=false,o=undefined;try{for(var n=e[Symbol.iterator](),i;!(t=(i=n.next()).done);t=true){var d=i.value;var s,u,h,c;var p=true,f=false,w=undefined;try{for(var v=d.addedNodes[Symbol.iterator](),C;!(p=(C=v.next()).done);p=true){var m=C.value;if(a(m,HTMLElement)){(m.dataset.whopCheckoutPlanId||m.dataset.whopCheckoutSession)&&B(m);var k=true,g=false,b=undefined;try{for(var A=m.querySelectorAll("[data-whop-checkout-plan-id], [data-whop-checkout-session]")[Symbol.iterator](),S;!(k=(S=A.next()).done);k=true){var P=S.value;a(P,HTMLElement)&&B(P)}}catch(e){g=true;b=e}finally{try{if(!k&&A.return!=null){A.return()}}finally{if(g){throw b}}}}}}catch(e){f=true;w=e}finally{try{if(!p&&v.return!=null){v.return()}}finally{if(f){throw w}}}var I=Array.from(d.removedNodes);var T;var E=true,L=false,x=undefined;try{var j=function(){var e=l(H.value,2),t=e[0],r=e[1];I.some(function(e){return a(e,Node)&&e.contains(t)})&&(t.dataset.whopCheckoutIdentifier&&((u=window.wco)===null||u===void 0?void 0:u.identifiedFrames.delete(t.dataset.whopCheckoutIdentifier),(h=window.wco)===null||h===void 0?void 0:h.availableCurrencies.delete(t.dataset.whopCheckoutIdentifier)),y.remove(t),r(),(c=window.wco)===null||c===void 0?void 0:c.frames.delete(t))};for(var O=((T=(s=window.wco)===null||s===void 0?void 0:s.frames)!==null&&T!==void 0?T:[])[Symbol.iterator](),H;!(E=(H=O.next()).done);E=true)j()}catch(e){L=true;x=e}finally{try{if(!E&&O.return!=null){O.return()}}finally{if(L){throw x}}}}}catch(e){r=true;o=e}finally{try{if(!t&&n.return!=null){n.return()}}finally{if(r){throw o}}}});var W=true,q=false,D=undefined;try{for(var G=document.querySelectorAll("[data-whop-checkout-plan-id], [data-whop-checkout-session]")[Symbol.iterator](),V;!(W=(V=G.next()).done);W=true){var _=V.value;a(_,HTMLElement)&&B(_)}}catch(e){q=true;D=e}finally{try{if(!W&&G.return!=null){G.return()}}finally{if(q){throw D}}}F.observe(document.body,{childList:!0,subtree:!0}),window.wco.listening=!0}var X;