Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@moneyhash/js-sdk

Package Overview
Dependencies
Maintainers
0
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@moneyhash/js-sdk - npm Package Compare versions

Comparing version 1.4.3-beta.0 to 1.4.3

dist/warnIf-08c3effc.cjs

2

dist/headless.cjs.js

@@ -1,1 +0,1 @@

"use strict";var ne=Object.defineProperty,ie=Object.defineProperties;var se=Object.getOwnPropertyDescriptors;var O=Object.getOwnPropertySymbols;var oe=Object.prototype.hasOwnProperty,de=Object.prototype.propertyIsEnumerable;var q=(o,e,t)=>e in o?ne(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,E=(o,e)=>{for(var t in e||(e={}))oe.call(e,t)&&q(o,t,e[t]);if(O)for(var t of O(e))de.call(e,t)&&q(o,t,e[t]);return o},z=(o,e)=>ie(o,se(e));var w=(o,e,t)=>(q(o,typeof e!="symbol"?e+"":e,t),t),ce=(o,e,t)=>{if(!e.has(o))throw TypeError("Cannot "+t)};var P=(o,e,t)=>{if(e.has(o))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(o):e.set(o,t)};var v=(o,e,t)=>(ce(o,e,"access private method"),t);var g=(o,e,t)=>new Promise((i,r)=>{var n=a=>{try{s(t.next(a))}catch(d){r(d)}},l=a=>{try{s(t.throw(a))}catch(d){r(d)}},s=a=>a.done?i(a.value):Promise.resolve(a.value).then(n,l);s((t=t.apply(o,e)).next())});const m=require("./warnIf-6822cba3.cjs");function le(){return typeof window!="undefined"}const y=class{constructor(){le()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=m.getIframeUrl(),t=new URL(`${e}/embed/headless-sdk`);t.searchParams.set("sdk","true"),t.searchParams.set("parent",window.location.origin),t.searchParams.set("version","js@1.4.3-beta.0");const i=document.createElement("iframe");i.id="moneyhash-headless-sdk",i.src=t.toString(),i.hidden=!0,document.body.appendChild(i),y.messagingService=new m.MessagingService({target:i.contentWindow,targetOrigin:e}),y.isCommunicationReady=new Promise(r=>{var l;const n=s=>{var a;s.data.type==="headlessSDK:init"&&(r(),(a=y.messagingService)==null||a.removeListener(n))};(l=y.messagingService)==null||l.onReceive(n)})}request(i){return g(this,arguments,function*({api:e,payload:t}){return yield y.isCommunicationReady,new Promise((r,n)=>{var s,a;(s=y.messagingService)==null||s.send({type:e,data:t});const l=d=>{var u;const{type:c,data:h}=d.data;c===e&&(h.status==="resolved"?r(h.payload):n(h.payload),(u=y.messagingService)==null||u.removeListener(l))};(a=y.messagingService)==null||a.onReceive(l)})})}};let S=y;w(S,"messagingService",null),w(S,"isCommunicationReady");class J{constructor(){w(this,"promise");w(this,"resolve");w(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function he(){var e;return(e=window.MONEYHASH_VAULT_API_URL)!=null?e:"https://vault.moneyhash.io"}function N(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function K(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}function me(o){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!o.includes(t))return t;return null}function ue(o){return(Array.isArray(o)?o.length:Object.keys(o).length)===0}function pe(o,e){return new Promise((t,i)=>{if(document.getElementById(e)){t(void 0);return}const n=document.createElement("script");n.src=o,n.id=e,n.addEventListener("load",()=>{t(void 0)}),n.addEventListener("error",()=>{i(new Error("Script failed to load"))}),document.body.appendChild(n)})}function ge(o){return new Promise(e=>{setTimeout(()=>{e("done")},o*1e3)})}const G=new Set(["method","customerBalance","savedCard"]);var A,Q,C,X,U,Z,L,V,R,ee,_,te,$,re,M,ae;class fe{constructor(e){P(this,A);P(this,C);P(this,U);P(this,L);P(this,R);P(this,_);P(this,$);P(this,M);w(this,"options");w(this,"sdkApiHandler",new S);w(this,"sdkEmbed");w(this,"vaultSubmitListener",{current:null});w(this,"mountedCardElements",[]);this.options=e,this.sdkEmbed=new m.SDKEmbed(z(E({},e),{headless:!0})),v(this,_,te).call(this,this.vaultSubmitListener)}getIntentDetails(e){return this.sdkApiHandler.request({api:"sdk:getIntentDetails",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}getIntentMethods(e){return this.sdkApiHandler.request({api:"sdk:getIntentMethods",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}proceedWith({intentId:e,type:t,id:i,metaData:r}){return m.throwIf(!G.has(t),`type must be a valid one (${[...G].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:i,lang:this.sdkEmbed.lang,metaData:r}})}resetSelectedMethod(e){return this.sdkApiHandler.request({api:"sdk:resetSelectedMethod",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}deleteCard({cardId:e,intentSecret:t}){return m.throwIf(this.options.type==="payout","deleteCard is allowed only for payment intent!"),this.sdkApiHandler.request({api:"sdk:deleteCard",payload:{cardId:e,intentSecret:t,lang:this.sdkEmbed.lang}})}payWithApplePay(d){return g(this,arguments,function*({intentId:e,currency:t,amount:i,countryCode:r,onCancel:n=()=>{},onError:l,onComplete:s,billingData:a={}}){if(yield pe("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)return;const c=new ApplePaySession(3,{countryCode:r,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${i}`}}),{state:h,intent:u}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(h==="INTENT_FORM"){if(ue(a))throw new Error("Billing data is missing while calling payWithApplePay");yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"APPLE_PAY",lang:this.sdkEmbed.lang,billingData:a}})}}catch(f){throw yield this.resetSelectedMethod(e),f}c.onvalidatemerchant=f=>{fetch(`${K()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:u.secret,validation_url:f.validationURL})}).then(p=>p.ok?p.json():Promise.reject()).then(p=>c.completeMerchantValidation(p)).catch(l)},c.onpaymentauthorized=f=>{fetch(`${K()}/api/v1/providers/applepay/token/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({token_data:f.payment.token,secret:u.secret})}).then(p=>p.ok?p.json():Promise.reject()).then(()=>{c.completePayment(ApplePaySession.STATUS_SUCCESS),s()}).catch(()=>{c.completePayment(ApplePaySession.STATUS_FAILURE),l()})},c.oncancel=n,c.begin()})}renderForm({selector:e,intentId:t}){return m.throwIf(!e,"selector is required for renderForm"),m.throwIf(!t,"intentId is required for renderForm"),this.sdkEmbed.render({selector:e,intentId:t})}setLocale(e){m.warnIf(!!e&&!m.supportedLanguages.has(e),`Invalid locale. Supported languages (${[...m.supportedLanguages].join(" | ")})`);const t=m.supportedLanguages.has(e)?e:"en";return this.sdkEmbed.setLocale(t)}removeEventListeners(){return this.sdkEmbed.abortService()}updateIntentDiscount({intentId:e,discount:t}){return m.throwIf(!t.title.en,"English discount title is required!"),this.sdkApiHandler.request({api:"sdk:updateIntentDiscount",payload:{intentId:e,discount:t,lang:this.sdkEmbed.lang}})}updateIntentFees({intentId:e,fees:t}){return t.forEach(i=>{m.throwIf(!i.title.en,"English fee title is required!")}),this.sdkApiHandler.request({api:"sdk:updateIntentFees",payload:{intentId:e,fees:t,lang:this.sdkEmbed.lang}})}elements({styles:e,classes:t,fontSourceCss:i}){const r=[],n={},l=new Map;let s=!1;return v(this,R,ee).call(this,r),{create:({elementType:a,elementOptions:d})=>{var H,j;const c=new Map,h=document.querySelector(d.selector);m.throwIf(!h,`Couldn't find an element with selector ${d.selector}!`),h.classList.add("MoneyHashElement");const u=E(E({},t),d.classes),f=((H=u==null?void 0:u.focus)==null?void 0:H.split(" "))||["MoneyHashElement--focus"],p=((j=u==null?void 0:u.error)==null?void 0:j.split(" "))||["MoneyHashElement--error"];return r.push(I=>{var D,T,W,x,B,Y;const{type:b,data:k}=I.data;if(b===`${a}:init`&&(n[a]=k.isValid),b===`${a}@focus`){h.classList.add(...f),(D=c.get(`${a}@focus`))==null||D();return}if(b===`${a}@blur`){h.classList.remove(...f),(T=c.get(`${a}@blur`))==null||T();return}if(b===`${a}@error`){k.isValid?h.classList.remove(...p):h.classList.add(...p),(W=c.get(`${a}@error`))==null||W(k);return}if(b===`${a}@changeInput`){if((x=c.get(`${a}@changeInput`))==null||x(),n[a]=k.isValid,l.get("validityChange")){const F=Object.values(n).every(Boolean);F!==s&&((B=l.get("validityChange"))==null||B(F),s=F)}return}b===`${a}@cardNumberChange`&&((Y=c.get(`${a}@cardNumberChange`))==null||Y(k))}),{mount:()=>{this.mountedCardElements.push(a),v(this,$,re).call(this,{container:h,elementType:a,elementOptions:d,styles:E(E({},e),d.styles),fontSourceCss:i})},on:(I,b)=>{c.set(`${a}@${I}`,b)},off:I=>c.delete(`${a}@${I}`)}},on:(a,d)=>{l.set(a,d)}}}submitForm(l){return g(this,arguments,function*({intentId:e,accessToken:t,billingData:i,shippingData:r,saveCard:n}){const s=me(this.mountedCardElements);m.throwIf(!!s,`You must mount ${s} element!`);const a=new J;let d,c;t&&(this.vaultSubmitListener.current=u=>{const{type:f,data:p}=u.data;f==="vaultSubmit:success"&&a.resolve(p),f==="vaultSubmit:error"&&a.reject(p)},c=v(this,M,ae).call(this,{accessToken:t,saveCard:n}),d=yield a.promise);const h=yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"CARD",lang:this.sdkEmbed.lang,billingData:i,shippingData:r,cardEmbed:d}});return c&&c.remove(),h})}submitCvv(i){return g(this,arguments,function*({intentId:e,cvv:t}){return this.sdkApiHandler.request({api:"sdk:submitCardCvv",payload:{intentId:e,cvv:t,lang:this.sdkEmbed.lang}})})}renderUrl(n){return g(this,arguments,function*({intentId:e,url:t,renderStrategy:i,options:r}){switch(i){case"IFRAME":return v(this,A,Q).call(this,{url:t,intentId:e});case"POPUP_IFRAME":return v(this,C,X).call(this,{url:t,intentId:e,options:r});case"REDIRECT":return v(this,U,Z).call(this,{url:t,options:r});default:return null}})}onExpiration(e,t){const i=new Date(e),r=setInterval(()=>g(this,null,function*(){const n=new Date;i<n&&(clearInterval(r),t())}),1e3);return()=>clearInterval(r)}}A=new WeakSet,Q=function(i){return g(this,arguments,function*({intentId:e,url:t}){const r=document.querySelector("#rendered-url-iframe-container");m.throwIf(!r,"Couldn't find an element with id rendered-url-iframe-container to render the iframe!");const n=document.createElement("iframe");n.src=t,n.style.setProperty("border","0","important"),n.style.setProperty("width","100%","important"),n.style.setProperty("height","100%","important"),r==null||r.replaceChildren(n),yield v(this,L,V).call(this,e),n.remove()})},C=new WeakSet,X=function(r){return g(this,arguments,function*({intentId:e,url:t,options:i={}}){const{width:n=600,height:l=400,left:s=200,top:a=200}=i.window||{},d=window.open(t,"",`width=${n},height=${l},left=${s},top=${a}`);m.throwIf(!d,"Popup blocked by browser!"),setTimeout(()=>{window.xx=d,console.log(d==null?void 0:d.closed)},1e3),yield v(this,L,V).call(this,e),d==null||d.close()})},U=new WeakSet,Z=function(i){return g(this,arguments,function*({url:e,options:t}){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},L=new WeakSet,V=function(e){return g(this,null,function*(){const t=new J,i=r=>g(this,null,function*(){var l,s,a,d;if(r.origin!==m.getIframeUrl())return;const{type:n}=r.data;if(n==="intentResult"){const[c]=yield Promise.all([this.getIntentDetails(e),ge(1)]),h=c.transaction.status.split(".")[1];h==="successful"||h.startsWith("pending")?(s=(l=this.options).onComplete)==null||s.call(l,E({type:this.options.type},c)):(d=(a=this.options).onFail)==null||d.call(a,E({type:this.options.type},c)),t.resolve(()=>null),window.removeEventListener("message",i)}});return window.addEventListener("message",i),t.promise})},R=new WeakSet,ee=function(e){const t=i=>{i.origin===N()&&e.forEach(r=>{r(i)})};window.addEventListener("message",t)},_=new WeakSet,te=function(e){const t=i=>{e.current&&e.current(i)};window.addEventListener("message",t)},$=new WeakSet,re=function({container:e,elementType:t,elementOptions:i,styles:r,fontSourceCss:n}){var d,c,h,u;const l=N(),s=new URL(`${l}/vaultField/vaultField.html`);n&&s.searchParams.set("fontSourceCss",n),s.searchParams.set("host",btoa(window.location.origin)),s.searchParams.set("type",t),((d=i.validation)==null?void 0:d.required)!==void 0&&s.searchParams.set("required",`${(c=i.validation)==null?void 0:c.required}`),s.searchParams.set("placeholder",(h=i.placeholder)!=null?h:""),s.searchParams.set("lang",this.sdkEmbed.lang),s.searchParams.set("direction",(r==null?void 0:r.direction)||""),s.searchParams.set("color",JSON.stringify(r!=null&&r.color?r.color:"#000")),s.searchParams.set("placeholderColor",(r==null?void 0:r.placeholderColor)||"#ccc"),s.searchParams.set("backgroundColor",(r==null?void 0:r.backgroundColor)||"transparent"),s.searchParams.set("fontSize",(r==null?void 0:r.fontSize)||""),s.searchParams.set("fontFamily",(r==null?void 0:r.fontFamily)||""),s.searchParams.set("fontWeight",`${r==null?void 0:r.fontWeight}`),s.searchParams.set("fontStyle",(r==null?void 0:r.fontStyle)||""),s.searchParams.set("padding",(r==null?void 0:r.padding)||"");const a=document.createElement("iframe");a.src=s.toString(),a.style.height=(u=r==null?void 0:r.height)!=null?u:"40px",a.style.setProperty("overflow","hidden","important"),a.style.setProperty("display","block","important"),a.style.setProperty("width","100%","important"),a.style.setProperty("maxWidth","100%","important"),a.style.setProperty("border","0","important"),a.style.setProperty("margin","0","important"),a.style.setProperty("padding","0","important"),a.style.setProperty("userSelect","none","important"),a.style.setProperty("colorScheme","light only","important"),e.replaceChildren(a)},M=new WeakSet,ae=function({accessToken:e,saveCard:t}){const i=N(),r=he(),n=new URL(`${i}/vaultSubmit/vaultSubmit.html`);n.searchParams.set("host",btoa(window.location.origin)),n.searchParams.set("vault_api_url",`${r}/api/v1/tokens/`),n.searchParams.set("access_token",e),n.searchParams.set("lang",this.sdkEmbed.lang),t!==void 0&&n.searchParams.set("save_card",`${t}`);const l=document.createElement("iframe");return l.id="moneyhash-submit-iframe",l.src=n.toString(),l.hidden=!0,document.body.appendChild(l),l};module.exports=fe;
"use strict";var ne=Object.defineProperty,ie=Object.defineProperties;var se=Object.getOwnPropertyDescriptors;var O=Object.getOwnPropertySymbols;var oe=Object.prototype.hasOwnProperty,de=Object.prototype.propertyIsEnumerable;var q=(s,e,t)=>e in s?ne(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,b=(s,e)=>{for(var t in e||(e={}))oe.call(e,t)&&q(s,t,e[t]);if(O)for(var t of O(e))de.call(e,t)&&q(s,t,e[t]);return s},z=(s,e)=>ie(s,se(e));var w=(s,e,t)=>(q(s,typeof e!="symbol"?e+"":e,t),t),ce=(s,e,t)=>{if(!e.has(s))throw TypeError("Cannot "+t)};var P=(s,e,t)=>{if(e.has(s))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(s):e.set(s,t)};var y=(s,e,t)=>(ce(s,e,"access private method"),t);var f=(s,e,t)=>new Promise((o,r)=>{var n=a=>{try{i(t.next(a))}catch(c){r(c)}},d=a=>{try{i(t.throw(a))}catch(c){r(c)}},i=a=>a.done?o(a.value):Promise.resolve(a.value).then(n,d);i((t=t.apply(s,e)).next())});const u=require("./warnIf-08c3effc.cjs");function le(){return typeof window!="undefined"}const v=class{constructor(){le()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=u.getIframeUrl(),t=new URL(`${e}/embed/headless-sdk`);t.searchParams.set("sdk","true"),t.searchParams.set("parent",window.location.origin),t.searchParams.set("version","js@1.4.3");const o=document.createElement("iframe");o.id="moneyhash-headless-sdk",o.src=t.toString(),o.hidden=!0,document.body.appendChild(o),v.messagingService=new u.MessagingService({target:o.contentWindow,targetOrigin:e}),v.isCommunicationReady=new Promise(r=>{var d;const n=i=>{var a;i.data.type==="headlessSDK:init"&&(r(),(a=v.messagingService)==null||a.removeListener(n))};(d=v.messagingService)==null||d.onReceive(n)})}request(o){return f(this,arguments,function*({api:e,payload:t}){return yield v.isCommunicationReady,new Promise((r,n)=>{var i,a;(i=v.messagingService)==null||i.send({type:e,data:t});const d=c=>{var m;const{type:l,data:h}=c.data;l===e&&(h.status==="resolved"?r(h.payload):n(h.payload),(m=v.messagingService)==null||m.removeListener(d))};(a=v.messagingService)==null||a.onReceive(d)})})}postMessage(e){var t;(t=v.messagingService)==null||t.send({type:e})}};let S=v;w(S,"messagingService",null),w(S,"isCommunicationReady");class J{constructor(){w(this,"promise");w(this,"resolve");w(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function he(){var e;return(e=window.MONEYHASH_VAULT_API_URL)!=null?e:"https://vault.moneyhash.io"}function N(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function K(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}function me(s){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!s.includes(t))return t;return null}function ue(s){return(Array.isArray(s)?s.length:Object.keys(s).length)===0}function pe(s,e){return new Promise((t,o)=>{if(document.getElementById(e)){t(void 0);return}const n=document.createElement("script");n.src=s,n.id=e,n.addEventListener("load",()=>{t(void 0)}),n.addEventListener("error",()=>{o(new Error("Script failed to load"))}),document.body.appendChild(n)})}function ge(s){return new Promise(e=>{setTimeout(()=>{e("done")},s*1e3)})}const G=new Set(["method","customerBalance","savedCard"]);var A,Q,C,X,U,Z,L,V,R,ee,M,te,_,re,$,ae;class fe{constructor(e){P(this,A);P(this,C);P(this,U);P(this,L);P(this,R);P(this,M);P(this,_);P(this,$);w(this,"options");w(this,"sdkApiHandler",new S);w(this,"sdkEmbed");w(this,"vaultSubmitListener",{current:null});w(this,"mountedCardElements",[]);this.options=e,this.sdkEmbed=new u.SDKEmbed(z(b({},e),{headless:!0})),y(this,M,te).call(this,this.vaultSubmitListener)}getIntentDetails(e){return this.sdkApiHandler.request({api:"sdk:getIntentDetails",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}getIntentMethods(e){return this.sdkApiHandler.request({api:"sdk:getIntentMethods",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}proceedWith({intentId:e,type:t,id:o,metaData:r}){return u.throwIf(!G.has(t),`type must be a valid one (${[...G].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:o,lang:this.sdkEmbed.lang,metaData:r}})}resetSelectedMethod(e){return this.sdkApiHandler.request({api:"sdk:resetSelectedMethod",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}deleteCard({cardId:e,intentSecret:t}){return u.throwIf(this.options.type==="payout","deleteCard is allowed only for payment intent!"),this.sdkApiHandler.request({api:"sdk:deleteCard",payload:{cardId:e,intentSecret:t,lang:this.sdkEmbed.lang}})}payWithApplePay(c){return f(this,arguments,function*({intentId:e,currency:t,amount:o,countryCode:r,onCancel:n=()=>{},onError:d,onComplete:i,billingData:a={}}){if(yield pe("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)return;const l=new ApplePaySession(3,{countryCode:r,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${o}`}}),{state:h,intent:m}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(h==="INTENT_FORM"){if(ue(a))throw new Error("Billing data is missing while calling payWithApplePay");yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"APPLE_PAY",lang:this.sdkEmbed.lang,billingData:a}})}}catch(p){throw yield this.resetSelectedMethod(e),p}l.onvalidatemerchant=p=>{fetch(`${K()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:m.secret,validation_url:p.validationURL})}).then(g=>g.ok?g.json():Promise.reject()).then(g=>l.completeMerchantValidation(g)).catch(d)},l.onpaymentauthorized=p=>{fetch(`${K()}/api/v1/providers/applepay/token/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({token_data:p.payment.token,secret:m.secret})}).then(g=>g.ok?g.json():Promise.reject()).then(()=>{l.completePayment(ApplePaySession.STATUS_SUCCESS),i()}).catch(()=>{l.completePayment(ApplePaySession.STATUS_FAILURE),d()})},l.oncancel=n,l.begin()})}renderForm({selector:e,intentId:t}){return u.throwIf(!e,"selector is required for renderForm"),u.throwIf(!t,"intentId is required for renderForm"),this.sdkEmbed.render({selector:e,intentId:t})}setLocale(e){u.warnIf(!!e&&!u.supportedLanguages.has(e),`Invalid locale. Supported languages (${[...u.supportedLanguages].join(" | ")})`);const t=u.supportedLanguages.has(e)?e:"en";return this.sdkEmbed.setLocale(t)}removeEventListeners(){return this.sdkEmbed.abortService()}updateIntentDiscount({intentId:e,discount:t}){return u.throwIf(!t.title.en,"English discount title is required!"),this.sdkApiHandler.request({api:"sdk:updateIntentDiscount",payload:{intentId:e,discount:t,lang:this.sdkEmbed.lang}})}updateIntentFees({intentId:e,fees:t}){return t.forEach(o=>{u.throwIf(!o.title.en,"English fee title is required!")}),this.sdkApiHandler.request({api:"sdk:updateIntentFees",payload:{intentId:e,fees:t,lang:this.sdkEmbed.lang}})}elements({styles:e,classes:t,fontSourceCss:o}){const r=[],n={},d=new Map;let i=!1;return y(this,R,ee).call(this,r),{create:({elementType:a,elementOptions:c})=>{var H,j;const l=new Map,h=document.querySelector(c.selector);u.throwIf(!h,`Couldn't find an element with selector ${c.selector}!`),h.classList.add("MoneyHashElement");const m=b(b({},t),c.classes),p=((H=m==null?void 0:m.focus)==null?void 0:H.split(" "))||["MoneyHashElement--focus"],g=((j=m==null?void 0:m.error)==null?void 0:j.split(" "))||["MoneyHashElement--error"];return r.push(I=>{var D,W,T,x,B,Y;const{type:E,data:k}=I.data;if(E===`${a}:init`&&(n[a]=k.isValid),E===`${a}@focus`){h.classList.add(...p),(D=l.get(`${a}@focus`))==null||D();return}if(E===`${a}@blur`){h.classList.remove(...p),(W=l.get(`${a}@blur`))==null||W();return}if(E===`${a}@error`){k.isValid?h.classList.remove(...g):h.classList.add(...g),(T=l.get(`${a}@error`))==null||T(k);return}if(E===`${a}@changeInput`){if((x=l.get(`${a}@changeInput`))==null||x(),n[a]=k.isValid,d.get("validityChange")){const F=Object.values(n).every(Boolean);F!==i&&((B=d.get("validityChange"))==null||B(F),i=F)}return}E===`${a}@cardNumberChange`&&((Y=l.get(`${a}@cardNumberChange`))==null||Y(k))}),{mount:()=>{this.mountedCardElements.push(a),y(this,_,re).call(this,{container:h,elementType:a,elementOptions:c,styles:b(b({},e),c.styles),fontSourceCss:o})},on:(I,E)=>{l.set(`${a}@${I}`,E)},off:I=>l.delete(`${a}@${I}`)}},on:(a,c)=>{d.set(a,c)}}}submitForm(d){return f(this,arguments,function*({intentId:e,accessToken:t,billingData:o,shippingData:r,saveCard:n}){const i=me(this.mountedCardElements);u.throwIf(!!i,`You must mount ${i} element!`);const a=new J;let c,l;t&&(this.vaultSubmitListener.current=m=>{const{type:p,data:g}=m.data;p==="vaultSubmit:success"&&a.resolve(g),p==="vaultSubmit:error"&&a.reject(g)},l=y(this,$,ae).call(this,{accessToken:t,saveCard:n}),c=yield a.promise);const h=yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"CARD",lang:this.sdkEmbed.lang,billingData:o,shippingData:r,cardEmbed:c}});return l&&l.remove(),h})}submitCvv(o){return f(this,arguments,function*({intentId:e,cvv:t}){return this.sdkApiHandler.request({api:"sdk:submitCardCvv",payload:{intentId:e,cvv:t,lang:this.sdkEmbed.lang}})})}renderUrl(n){return f(this,arguments,function*({intentId:e,url:t,renderStrategy:o,options:r}){switch(o){case"IFRAME":return y(this,A,Q).call(this,{url:t,intentId:e});case"POPUP_IFRAME":return y(this,C,X).call(this,{url:t,intentId:e,options:r});case"REDIRECT":return y(this,U,Z).call(this,{url:t,options:r});default:return null}})}onExpiration(e,t){const o=new Date(e),r=setInterval(()=>f(this,null,function*(){const n=new Date;o<n&&(clearInterval(r),t())}),1e3);return()=>clearInterval(r)}}A=new WeakSet,Q=function(o){return f(this,arguments,function*({intentId:e,url:t}){const r=document.querySelector("#rendered-url-iframe-container");u.throwIf(!r,"Couldn't find an element with id rendered-url-iframe-container to render the iframe!");const n=document.createElement("iframe");n.src=t,n.style.setProperty("border","0","important"),n.style.setProperty("width","100%","important"),n.style.setProperty("height","100%","important"),r==null||r.replaceChildren(n),yield y(this,L,V).call(this,{intentId:e}),n.remove()})},C=new WeakSet,X=function(r){return f(this,arguments,function*({intentId:e,url:t,options:o={}}){const{width:n=600,height:d=400,left:i=200,top:a=200}=o.window||{},c=window.open(t,"",`width=${n},height=${d},left=${i},top=${a}`);u.throwIf(!c,"Popup blocked by browser!"),yield y(this,L,V).call(this,{intentId:e,isUsingPopUp:!0}),c==null||c.close()})},U=new WeakSet,Z=function(o){return f(this,arguments,function*({url:e,options:t}){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},L=new WeakSet,V=function(o){return f(this,arguments,function*({intentId:e,isUsingPopUp:t=!1}){const r=new J,n=d=>f(this,null,function*(){var a,c,l,h;if(d.origin!==u.getIframeUrl())return;const{type:i}=d.data;if(i==="intentResult"){t&&this.sdkApiHandler.postMessage("EmbedResultClose");const[m]=yield Promise.all([this.getIntentDetails(e),ge(1)]),p=m.transaction.status.split(".")[1];p==="successful"||p.startsWith("pending")?(c=(a=this.options).onComplete)==null||c.call(a,b({type:this.options.type},m)):(h=(l=this.options).onFail)==null||h.call(l,b({type:this.options.type},m)),r.resolve(()=>null),window.removeEventListener("message",n)}});return window.addEventListener("message",n),r.promise})},R=new WeakSet,ee=function(e){const t=o=>{o.origin===N()&&e.forEach(r=>{r(o)})};window.addEventListener("message",t)},M=new WeakSet,te=function(e){const t=o=>{e.current&&e.current(o)};window.addEventListener("message",t)},_=new WeakSet,re=function({container:e,elementType:t,elementOptions:o,styles:r,fontSourceCss:n}){var c,l,h,m;const d=N(),i=new URL(`${d}/vaultField/vaultField.html`);n&&i.searchParams.set("fontSourceCss",n),i.searchParams.set("host",btoa(window.location.origin)),i.searchParams.set("type",t),((c=o.validation)==null?void 0:c.required)!==void 0&&i.searchParams.set("required",`${(l=o.validation)==null?void 0:l.required}`),i.searchParams.set("placeholder",(h=o.placeholder)!=null?h:""),i.searchParams.set("lang",this.sdkEmbed.lang),i.searchParams.set("direction",(r==null?void 0:r.direction)||""),i.searchParams.set("color",JSON.stringify(r!=null&&r.color?r.color:"#000")),i.searchParams.set("placeholderColor",(r==null?void 0:r.placeholderColor)||"#ccc"),i.searchParams.set("backgroundColor",(r==null?void 0:r.backgroundColor)||"transparent"),i.searchParams.set("fontSize",(r==null?void 0:r.fontSize)||""),i.searchParams.set("fontFamily",(r==null?void 0:r.fontFamily)||""),i.searchParams.set("fontWeight",`${r==null?void 0:r.fontWeight}`),i.searchParams.set("fontStyle",(r==null?void 0:r.fontStyle)||""),i.searchParams.set("padding",(r==null?void 0:r.padding)||"");const a=document.createElement("iframe");a.src=i.toString(),a.style.height=(m=r==null?void 0:r.height)!=null?m:"40px",a.style.setProperty("overflow","hidden","important"),a.style.setProperty("display","block","important"),a.style.setProperty("width","100%","important"),a.style.setProperty("maxWidth","100%","important"),a.style.setProperty("border","0","important"),a.style.setProperty("margin","0","important"),a.style.setProperty("padding","0","important"),a.style.setProperty("userSelect","none","important"),a.style.setProperty("colorScheme","light only","important"),e.replaceChildren(a)},$=new WeakSet,ae=function({accessToken:e,saveCard:t}){const o=N(),r=he(),n=new URL(`${o}/vaultSubmit/vaultSubmit.html`);n.searchParams.set("host",btoa(window.location.origin)),n.searchParams.set("vault_api_url",`${r}/api/v1/tokens/`),n.searchParams.set("access_token",e),n.searchParams.set("lang",this.sdkEmbed.lang),t!==void 0&&n.searchParams.set("save_card",`${t}`);const d=document.createElement("iframe");return d.id="moneyhash-submit-iframe",d.src=n.toString(),d.hidden=!0,document.body.appendChild(d),d};module.exports=fe;

@@ -5,41 +5,41 @@ var se = Object.defineProperty, oe = Object.defineProperties;

var ce = Object.prototype.hasOwnProperty, le = Object.prototype.propertyIsEnumerable;
var q = (o, e, t) => e in o ? se(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t, E = (o, e) => {
var q = (s, e, t) => e in s ? se(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, b = (s, e) => {
for (var t in e || (e = {}))
ce.call(e, t) && q(o, t, e[t]);
ce.call(e, t) && q(s, t, e[t]);
if (z)
for (var t of z(e))
le.call(e, t) && q(o, t, e[t]);
return o;
}, J = (o, e) => oe(o, de(e));
var f = (o, e, t) => (q(o, typeof e != "symbol" ? e + "" : e, t), t), me = (o, e, t) => {
if (!e.has(o))
le.call(e, t) && q(s, t, e[t]);
return s;
}, J = (s, e) => oe(s, de(e));
var f = (s, e, t) => (q(s, typeof e != "symbol" ? e + "" : e, t), t), me = (s, e, t) => {
if (!e.has(s))
throw TypeError("Cannot " + t);
};
var P = (o, e, t) => {
if (e.has(o))
var P = (s, e, t) => {
if (e.has(s))
throw TypeError("Cannot add the same private member more than once");
e instanceof WeakSet ? e.add(o) : e.set(o, t);
e instanceof WeakSet ? e.add(s) : e.set(s, t);
};
var v = (o, e, t) => (me(o, e, "access private method"), t);
var p = (o, e, t) => new Promise((i, r) => {
var w = (s, e, t) => (me(s, e, "access private method"), t);
var g = (s, e, t) => new Promise((o, r) => {
var n = (a) => {
try {
s(t.next(a));
} catch (d) {
r(d);
i(t.next(a));
} catch (c) {
r(c);
}
}, l = (a) => {
}, d = (a) => {
try {
s(t.throw(a));
} catch (d) {
r(d);
i(t.throw(a));
} catch (c) {
r(c);
}
}, s = (a) => a.done ? i(a.value) : Promise.resolve(a.value).then(n, l);
s((t = t.apply(o, e)).next());
}, i = (a) => a.done ? o(a.value) : Promise.resolve(a.value).then(n, d);
i((t = t.apply(s, e)).next());
});
import { M as ue, g as X, S as he, t as w, w as pe, s as N } from "./warnIf-f46979fc.js";
import { M as pe, g as X, S as ue, t as y, w as he, s as N } from "./warnIf-c0417b00.js";
function ge() {
return typeof window != "undefined";
}
const y = class {
const v = class {
constructor() {

@@ -52,39 +52,43 @@ ge() && this.initSDKCommunicationIframe();

const e = X(), t = new URL(`${e}/embed/headless-sdk`);
t.searchParams.set("sdk", "true"), t.searchParams.set("parent", window.location.origin), t.searchParams.set("version", "js@1.4.3-beta.0");
const i = document.createElement("iframe");
i.id = "moneyhash-headless-sdk", i.src = t.toString(), i.hidden = !0, document.body.appendChild(i), y.messagingService = new ue({
target: i.contentWindow,
t.searchParams.set("sdk", "true"), t.searchParams.set("parent", window.location.origin), t.searchParams.set("version", "js@1.4.3");
const o = document.createElement("iframe");
o.id = "moneyhash-headless-sdk", o.src = t.toString(), o.hidden = !0, document.body.appendChild(o), v.messagingService = new pe({
target: o.contentWindow,
targetOrigin: e
}), y.isCommunicationReady = new Promise((r) => {
var l;
const n = (s) => {
}), v.isCommunicationReady = new Promise((r) => {
var d;
const n = (i) => {
var a;
s.data.type === "headlessSDK:init" && (r(), (a = y.messagingService) == null || a.removeListener(n));
i.data.type === "headlessSDK:init" && (r(), (a = v.messagingService) == null || a.removeListener(n));
};
(l = y.messagingService) == null || l.onReceive(n);
(d = v.messagingService) == null || d.onReceive(n);
});
}
request(i) {
return p(this, arguments, function* ({
request(o) {
return g(this, arguments, function* ({
api: e,
payload: t
}) {
return yield y.isCommunicationReady, new Promise((r, n) => {
var s, a;
(s = y.messagingService) == null || s.send({
return yield v.isCommunicationReady, new Promise((r, n) => {
var i, a;
(i = v.messagingService) == null || i.send({
type: e,
data: t
});
const l = (d) => {
var u;
const { type: c, data: m } = d.data;
c === e && (m.status === "resolved" ? r(m.payload) : n(m.payload), (u = y.messagingService) == null || u.removeListener(l));
const d = (c) => {
var p;
const { type: l, data: m } = c.data;
l === e && (m.status === "resolved" ? r(m.payload) : n(m.payload), (p = v.messagingService) == null || p.removeListener(d));
};
(a = y.messagingService) == null || a.onReceive(l);
(a = v.messagingService) == null || a.onReceive(d);
});
});
}
postMessage(e) {
var t;
(t = v.messagingService) == null || t.send({ type: e });
}
};
let I = y;
f(I, "messagingService", null), f(I, "isCommunicationReady");
let A = v;
f(A, "messagingService", null), f(A, "isCommunicationReady");
class K {

@@ -112,3 +116,3 @@ constructor() {

}
function ve(o) {
function ve(s) {
const e = [

@@ -121,11 +125,11 @@ "cardNumber",

for (const t of e)
if (!o.includes(t))
if (!s.includes(t))
return t;
return null;
}
function we(o) {
return (Array.isArray(o) ? o.length : Object.keys(o).length) === 0;
function we(s) {
return (Array.isArray(s) ? s.length : Object.keys(s).length) === 0;
}
function ye(o, e) {
return new Promise((t, i) => {
function ye(s, e) {
return new Promise((t, o) => {
if (document.getElementById(e)) {

@@ -136,14 +140,14 @@ t(void 0);

const n = document.createElement("script");
n.src = o, n.id = e, n.addEventListener("load", () => {
n.src = s, n.id = e, n.addEventListener("load", () => {
t(void 0);
}), n.addEventListener("error", () => {
i(new Error("Script failed to load"));
o(new Error("Script failed to load"));
}), document.body.appendChild(n);
});
}
function Pe(o) {
function Pe(s) {
return new Promise((e) => {
setTimeout(() => {
e("done");
}, o * 1e3);
}, s * 1e3);
});

@@ -156,3 +160,3 @@ }

]);
var L, Z, C, ee, U, te, A, H, R, re, _, ae, $, ne, M, ie;
var L, Z, C, ee, U, te, I, H, R, re, M, ae, _, ne, $, ie;
class Se {

@@ -163,9 +167,9 @@ constructor(e) {

P(this, U);
P(this, A);
P(this, I);
P(this, R);
P(this, M);
P(this, _);
P(this, $);
P(this, M);
f(this, "options");
f(this, "sdkApiHandler", new I());
f(this, "sdkApiHandler", new A());
f(this, "sdkEmbed");

@@ -176,3 +180,3 @@ f(this, "vaultSubmitListener", {

f(this, "mountedCardElements", []);
this.options = e, this.sdkEmbed = new he(J(E({}, e), { headless: !0 })), v(this, _, ae).call(this, this.vaultSubmitListener);
this.options = e, this.sdkEmbed = new ue(J(b({}, e), { headless: !0 })), w(this, M, ae).call(this, this.vaultSubmitListener);
}

@@ -268,6 +272,6 @@ /**

type: t,
id: i,
id: o,
metaData: r
}) {
return w(
return y(
!Q.has(t),

@@ -283,3 +287,3 @@ `type must be a valid one (${[...Q].join(

intentId: e,
id: i,
id: o,
lang: this.sdkEmbed.lang,

@@ -332,3 +336,3 @@ metaData: r

}) {
return w(
return y(
this.options.type === "payout",

@@ -383,12 +387,12 @@ "deleteCard is allowed only for payment intent!"

*/
payWithApplePay(d) {
return p(this, arguments, function* ({
payWithApplePay(c) {
return g(this, arguments, function* ({
intentId: e,
currency: t,
amount: i,
amount: o,
countryCode: r,
onCancel: n = () => {
},
onError: l,
onComplete: s,
onError: d,
onComplete: i,
billingData: a = {}

@@ -401,3 +405,3 @@ }) {

return;
const c = new ApplePaySession(3, {
const l = new ApplePaySession(3, {
countryCode: r,

@@ -410,5 +414,5 @@ currencyCode: t,

type: "final",
amount: `${i}`
amount: `${o}`
}
}), { state: m, intent: u } = yield this.proceedWith({
}), { state: m, intent: p } = yield this.proceedWith({
intentId: e,

@@ -434,6 +438,6 @@ type: "method",

}
} catch (g) {
throw yield this.resetSelectedMethod(e), g;
} catch (u) {
throw yield this.resetSelectedMethod(e), u;
}
c.onvalidatemerchant = (g) => {
l.onvalidatemerchant = (u) => {
fetch(`${G()}/api/v1/providers/applepay/session/`, {

@@ -445,9 +449,9 @@ method: "post",

body: JSON.stringify({
secret: u.secret,
validation_url: g.validationURL
secret: p.secret,
validation_url: u.validationURL
})
}).then((h) => h.ok ? h.json() : Promise.reject()).then(
(h) => c.completeMerchantValidation(h)
).catch(l);
}, c.onpaymentauthorized = (g) => {
(h) => l.completeMerchantValidation(h)
).catch(d);
}, l.onpaymentauthorized = (u) => {
fetch(`${G()}/api/v1/providers/applepay/token/`, {

@@ -459,11 +463,11 @@ method: "post",

body: JSON.stringify({
token_data: g.payment.token,
secret: u.secret
token_data: u.payment.token,
secret: p.secret
})
}).then((h) => h.ok ? h.json() : Promise.reject()).then(() => {
c.completePayment(ApplePaySession.STATUS_SUCCESS), s();
l.completePayment(ApplePaySession.STATUS_SUCCESS), i();
}).catch(() => {
c.completePayment(ApplePaySession.STATUS_FAILURE), l();
l.completePayment(ApplePaySession.STATUS_FAILURE), d();
});
}, c.oncancel = n, c.begin();
}, l.oncancel = n, l.begin();
});

@@ -488,3 +492,3 @@ }

renderForm({ selector: e, intentId: t }) {
return w(!e, "selector is required for renderForm"), w(!t, "intentId is required for renderForm"), this.sdkEmbed.render({ selector: e, intentId: t });
return y(!e, "selector is required for renderForm"), y(!t, "intentId is required for renderForm"), this.sdkEmbed.render({ selector: e, intentId: t });
}

@@ -504,3 +508,3 @@ /**

setLocale(e) {
pe(
he(
!!e && !N.has(e),

@@ -540,3 +544,3 @@ `Invalid locale. Supported languages (${[...N].join(

}) {
return w(!t.title.en, "English discount title is required!"), this.sdkApiHandler.request({
return y(!t.title.en, "English discount title is required!"), this.sdkApiHandler.request({
api: "sdk:updateIntentDiscount",

@@ -566,4 +570,4 @@ payload: {

updateIntentFees({ intentId: e, fees: t }) {
return t.forEach((i) => {
w(!i.title.en, "English fee title is required!");
return t.forEach((o) => {
y(!o.title.en, "English fee title is required!");
}), this.sdkApiHandler.request({

@@ -590,6 +594,6 @@ api: "sdk:updateIntentFees",

*/
elements({ styles: e, classes: t, fontSourceCss: i }) {
const r = [], n = {}, l = /* @__PURE__ */ new Map();
let s = !1;
return v(this, R, re).call(this, r), {
elements({ styles: e, classes: t, fontSourceCss: o }) {
const r = [], n = {}, d = /* @__PURE__ */ new Map();
let i = !1;
return w(this, R, re).call(this, r), {
/**

@@ -616,57 +620,57 @@ * Creates card field element

*/
create: ({ elementType: a, elementOptions: d }) => {
create: ({ elementType: a, elementOptions: c }) => {
var j, D;
const c = /* @__PURE__ */ new Map(), m = document.querySelector(
d.selector
const l = /* @__PURE__ */ new Map(), m = document.querySelector(
c.selector
);
w(
y(
!m,
`Couldn't find an element with selector ${d.selector}!`
`Couldn't find an element with selector ${c.selector}!`
), m.classList.add("MoneyHashElement");
const u = E(E({}, t), d.classes), g = ((j = u == null ? void 0 : u.focus) == null ? void 0 : j.split(" ")) || [
const p = b(b({}, t), c.classes), u = ((j = p == null ? void 0 : p.focus) == null ? void 0 : j.split(" ")) || [
"MoneyHashElement--focus"
], h = ((D = u == null ? void 0 : u.error) == null ? void 0 : D.split(" ")) || [
], h = ((D = p == null ? void 0 : p.error) == null ? void 0 : D.split(" ")) || [
"MoneyHashElement--error"
];
return r.push((k) => {
var T, W, x, B, Y, O;
const { type: b, data: S } = k.data;
if (b === `${a}:init` && (n[a] = S.isValid), b === `${a}@focus`) {
m.classList.add(...g), (T = c.get(`${a}@focus`)) == null || T();
var W, T, x, B, Y, O;
const { type: E, data: S } = k.data;
if (E === `${a}:init` && (n[a] = S.isValid), E === `${a}@focus`) {
m.classList.add(...u), (W = l.get(`${a}@focus`)) == null || W();
return;
}
if (b === `${a}@blur`) {
m.classList.remove(...g), (W = c.get(`${a}@blur`)) == null || W();
if (E === `${a}@blur`) {
m.classList.remove(...u), (T = l.get(`${a}@blur`)) == null || T();
return;
}
if (b === `${a}@error`) {
S.isValid ? m.classList.remove(...h) : m.classList.add(...h), (x = c.get(`${a}@error`)) == null || x(S);
if (E === `${a}@error`) {
S.isValid ? m.classList.remove(...h) : m.classList.add(...h), (x = l.get(`${a}@error`)) == null || x(S);
return;
}
if (b === `${a}@changeInput`) {
if ((B = c.get(`${a}@changeInput`)) == null || B(), n[a] = S.isValid, l.get("validityChange")) {
if (E === `${a}@changeInput`) {
if ((B = l.get(`${a}@changeInput`)) == null || B(), n[a] = S.isValid, d.get("validityChange")) {
const F = Object.values(n).every(Boolean);
F !== s && ((Y = l.get("validityChange")) == null || Y(F), s = F);
F !== i && ((Y = d.get("validityChange")) == null || Y(F), i = F);
}
return;
}
b === `${a}@cardNumberChange` && ((O = c.get(`${a}@cardNumberChange`)) == null || O(S));
E === `${a}@cardNumberChange` && ((O = l.get(`${a}@cardNumberChange`)) == null || O(S));
}), {
mount: () => {
this.mountedCardElements.push(a), v(this, $, ne).call(this, {
this.mountedCardElements.push(a), w(this, _, ne).call(this, {
container: m,
elementType: a,
elementOptions: d,
styles: E(E({}, e), d.styles),
fontSourceCss: i
elementOptions: c,
styles: b(b({}, e), c.styles),
fontSourceCss: o
});
},
on: (k, b) => {
c.set(`${a}@${k}`, b);
on: (k, E) => {
l.set(`${a}@${k}`, E);
},
off: (k) => c.delete(`${a}@${k}`)
off: (k) => l.delete(`${a}@${k}`)
};
},
on: (a, d) => {
l.set(a, d);
on: (a, c) => {
d.set(a, c);
}

@@ -689,21 +693,21 @@ };

*/
submitForm(l) {
return p(this, arguments, function* ({
submitForm(d) {
return g(this, arguments, function* ({
intentId: e,
accessToken: t,
billingData: i,
billingData: o,
shippingData: r,
saveCard: n
}) {
const s = ve(this.mountedCardElements);
w(
!!s,
`You must mount ${s} element!`
const i = ve(this.mountedCardElements);
y(
!!i,
`You must mount ${i} element!`
);
const a = new K();
let d, c;
t && (this.vaultSubmitListener.current = (u) => {
const { type: g, data: h } = u.data;
g === "vaultSubmit:success" && a.resolve(h), g === "vaultSubmit:error" && a.reject(h);
}, c = v(this, M, ie).call(this, { accessToken: t, saveCard: n }), d = yield a.promise);
let c, l;
t && (this.vaultSubmitListener.current = (p) => {
const { type: u, data: h } = p.data;
u === "vaultSubmit:success" && a.resolve(h), u === "vaultSubmit:error" && a.reject(h);
}, l = w(this, $, ie).call(this, { accessToken: t, saveCard: n }), c = yield a.promise);
const m = yield this.sdkApiHandler.request({

@@ -715,8 +719,8 @@ api: "sdk:submitNativeForm",

lang: this.sdkEmbed.lang,
billingData: i,
billingData: o,
shippingData: r,
cardEmbed: d
cardEmbed: c
}
});
return c && c.remove(), m;
return l && l.remove(), m;
});

@@ -734,4 +738,4 @@ }

*/
submitCvv(i) {
return p(this, arguments, function* ({
submitCvv(o) {
return g(this, arguments, function* ({
intentId: e,

@@ -760,15 +764,15 @@ cvv: t

renderUrl(n) {
return p(this, arguments, function* ({
return g(this, arguments, function* ({
intentId: e,
url: t,
renderStrategy: i,
renderStrategy: o,
options: r
}) {
switch (i) {
switch (o) {
case "IFRAME":
return v(this, L, Z).call(this, { url: t, intentId: e });
return w(this, L, Z).call(this, { url: t, intentId: e });
case "POPUP_IFRAME":
return v(this, C, ee).call(this, { url: t, intentId: e, options: r });
return w(this, C, ee).call(this, { url: t, intentId: e, options: r });
case "REDIRECT":
return v(this, U, te).call(this, { url: t, options: r });
return w(this, U, te).call(this, { url: t, options: r });
default:

@@ -791,5 +795,5 @@ return null;

onExpiration(e, t) {
const i = new Date(e), r = setInterval(() => p(this, null, function* () {
const o = new Date(e), r = setInterval(() => g(this, null, function* () {
const n = new Date();
i < n && (clearInterval(r), t());
o < n && (clearInterval(r), t());
}), 1e3);

@@ -799,4 +803,4 @@ return () => clearInterval(r);

}
L = new WeakSet(), Z = function(i) {
return p(this, arguments, function* ({
L = new WeakSet(), Z = function(o) {
return g(this, arguments, function* ({
intentId: e,

@@ -806,3 +810,3 @@ url: t

const r = document.querySelector("#rendered-url-iframe-container");
w(
y(
!r,

@@ -812,27 +816,24 @@ "Couldn't find an element with id rendered-url-iframe-container to render the iframe!"

const n = document.createElement("iframe");
n.src = t, n.style.setProperty("border", "0", "important"), n.style.setProperty("width", "100%", "important"), n.style.setProperty("height", "100%", "important"), r == null || r.replaceChildren(n), yield v(this, A, H).call(this, e), n.remove();
n.src = t, n.style.setProperty("border", "0", "important"), n.style.setProperty("width", "100%", "important"), n.style.setProperty("height", "100%", "important"), r == null || r.replaceChildren(n), yield w(this, I, H).call(this, { intentId: e }), n.remove();
});
}, C = new WeakSet(), ee = function(r) {
return p(this, arguments, function* ({
return g(this, arguments, function* ({
intentId: e,
url: t,
options: i = {}
options: o = {}
}) {
const {
width: n = 600,
height: l = 400,
left: s = 200,
height: d = 400,
left: i = 200,
top: a = 200
} = i.window || {}, d = window.open(
// `${urlObject.toString()}`,
} = o.window || {}, c = window.open(
t,
"",
`width=${n},height=${l},left=${s},top=${a}`
`width=${n},height=${d},left=${i},top=${a}`
);
w(!d, "Popup blocked by browser!"), setTimeout(() => {
window.xx = d, console.log(d == null ? void 0 : d.closed);
}, 1e3), yield v(this, A, H).call(this, e), d == null || d.close();
y(!c, "Popup blocked by browser!"), yield w(this, I, H).call(this, { intentId: e, isUsingPopUp: !0 }), c == null || c.close();
});
}, U = new WeakSet(), te = function(i) {
return p(this, arguments, function* ({
}, U = new WeakSet(), te = function(o) {
return g(this, arguments, function* ({
url: e,

@@ -847,69 +848,73 @@ options: t

});
}, A = new WeakSet(), H = function(e) {
return p(this, null, function* () {
const t = new K(), i = (r) => p(this, null, function* () {
var l, s, a, d;
if (r.origin !== X())
}, I = new WeakSet(), H = function(o) {
return g(this, arguments, function* ({
intentId: e,
isUsingPopUp: t = !1
}) {
const r = new K(), n = (d) => g(this, null, function* () {
var a, c, l, m;
if (d.origin !== X())
return;
const { type: n } = r.data;
if (n === "intentResult") {
const [c] = yield Promise.all([
const { type: i } = d.data;
if (i === "intentResult") {
t && this.sdkApiHandler.postMessage("EmbedResultClose");
const [p] = yield Promise.all([
this.getIntentDetails(e),
Pe(1)
]), m = c.transaction.status.split(".")[1];
m === "successful" || m.startsWith("pending") ? (s = (l = this.options).onComplete) == null || s.call(l, E({
]), u = p.transaction.status.split(".")[1];
u === "successful" || u.startsWith("pending") ? (c = (a = this.options).onComplete) == null || c.call(a, b({
type: this.options.type
}, c)) : (d = (a = this.options).onFail) == null || d.call(a, E({
}, p)) : (m = (l = this.options).onFail) == null || m.call(l, b({
type: this.options.type
}, c)), t.resolve(() => null), window.removeEventListener("message", i);
}, p)), r.resolve(() => null), window.removeEventListener("message", n);
}
});
return window.addEventListener("message", i), t.promise;
return window.addEventListener("message", n), r.promise;
});
}, R = new WeakSet(), re = function(e) {
const t = (i) => {
i.origin === V() && e.forEach((r) => {
r(i);
const t = (o) => {
o.origin === V() && e.forEach((r) => {
r(o);
});
};
window.addEventListener("message", t);
}, _ = new WeakSet(), ae = function(e) {
const t = (i) => {
e.current && e.current(i);
}, M = new WeakSet(), ae = function(e) {
const t = (o) => {
e.current && e.current(o);
};
window.addEventListener("message", t);
}, $ = new WeakSet(), ne = function({
}, _ = new WeakSet(), ne = function({
container: e,
elementType: t,
elementOptions: i,
elementOptions: o,
styles: r,
fontSourceCss: n
}) {
var d, c, m, u;
const l = V(), s = new URL(`${l}/vaultField/vaultField.html`);
n && s.searchParams.set("fontSourceCss", n), s.searchParams.set("host", btoa(window.location.origin)), s.searchParams.set("type", t), ((d = i.validation) == null ? void 0 : d.required) !== void 0 && s.searchParams.set(
var c, l, m, p;
const d = V(), i = new URL(`${d}/vaultField/vaultField.html`);
n && i.searchParams.set("fontSourceCss", n), i.searchParams.set("host", btoa(window.location.origin)), i.searchParams.set("type", t), ((c = o.validation) == null ? void 0 : c.required) !== void 0 && i.searchParams.set(
"required",
`${(c = i.validation) == null ? void 0 : c.required}`
), s.searchParams.set("placeholder", (m = i.placeholder) != null ? m : ""), s.searchParams.set("lang", this.sdkEmbed.lang), s.searchParams.set("direction", (r == null ? void 0 : r.direction) || ""), s.searchParams.set(
`${(l = o.validation) == null ? void 0 : l.required}`
), i.searchParams.set("placeholder", (m = o.placeholder) != null ? m : ""), i.searchParams.set("lang", this.sdkEmbed.lang), i.searchParams.set("direction", (r == null ? void 0 : r.direction) || ""), i.searchParams.set(
"color",
JSON.stringify(r != null && r.color ? r.color : "#000")
), s.searchParams.set(
), i.searchParams.set(
"placeholderColor",
(r == null ? void 0 : r.placeholderColor) || "#ccc"
), s.searchParams.set(
), i.searchParams.set(
"backgroundColor",
(r == null ? void 0 : r.backgroundColor) || "transparent"
), s.searchParams.set("fontSize", (r == null ? void 0 : r.fontSize) || ""), s.searchParams.set("fontFamily", (r == null ? void 0 : r.fontFamily) || ""), s.searchParams.set("fontWeight", `${r == null ? void 0 : r.fontWeight}`), s.searchParams.set("fontStyle", (r == null ? void 0 : r.fontStyle) || ""), s.searchParams.set("padding", (r == null ? void 0 : r.padding) || "");
), i.searchParams.set("fontSize", (r == null ? void 0 : r.fontSize) || ""), i.searchParams.set("fontFamily", (r == null ? void 0 : r.fontFamily) || ""), i.searchParams.set("fontWeight", `${r == null ? void 0 : r.fontWeight}`), i.searchParams.set("fontStyle", (r == null ? void 0 : r.fontStyle) || ""), i.searchParams.set("padding", (r == null ? void 0 : r.padding) || "");
const a = document.createElement("iframe");
a.src = s.toString(), a.style.height = (u = r == null ? void 0 : r.height) != null ? u : "40px", a.style.setProperty("overflow", "hidden", "important"), a.style.setProperty("display", "block", "important"), a.style.setProperty("width", "100%", "important"), a.style.setProperty("maxWidth", "100%", "important"), a.style.setProperty("border", "0", "important"), a.style.setProperty("margin", "0", "important"), a.style.setProperty("padding", "0", "important"), a.style.setProperty("userSelect", "none", "important"), a.style.setProperty("colorScheme", "light only", "important"), e.replaceChildren(a);
}, M = new WeakSet(), ie = function({
a.src = i.toString(), a.style.height = (p = r == null ? void 0 : r.height) != null ? p : "40px", a.style.setProperty("overflow", "hidden", "important"), a.style.setProperty("display", "block", "important"), a.style.setProperty("width", "100%", "important"), a.style.setProperty("maxWidth", "100%", "important"), a.style.setProperty("border", "0", "important"), a.style.setProperty("margin", "0", "important"), a.style.setProperty("padding", "0", "important"), a.style.setProperty("userSelect", "none", "important"), a.style.setProperty("colorScheme", "light only", "important"), e.replaceChildren(a);
}, $ = new WeakSet(), ie = function({
accessToken: e,
saveCard: t
}) {
const i = V(), r = fe(), n = new URL(
`${i}/vaultSubmit/vaultSubmit.html`
const o = V(), r = fe(), n = new URL(
`${o}/vaultSubmit/vaultSubmit.html`
);
n.searchParams.set("host", btoa(window.location.origin)), n.searchParams.set("vault_api_url", `${r}/api/v1/tokens/`), n.searchParams.set("access_token", e), n.searchParams.set("lang", this.sdkEmbed.lang), t !== void 0 && n.searchParams.set("save_card", `${t}`);
const l = document.createElement("iframe");
return l.id = "moneyhash-submit-iframe", l.src = n.toString(), l.hidden = !0, document.body.appendChild(l), l;
const d = document.createElement("iframe");
return d.id = "moneyhash-submit-iframe", d.src = n.toString(), d.hidden = !0, document.body.appendChild(d), d;
};

@@ -916,0 +921,0 @@ export {

@@ -1,1 +0,1 @@

(function(l,o){typeof exports=="object"&&typeof module!="undefined"?module.exports=o():typeof define=="function"&&define.amd?define(o):(l=typeof globalThis!="undefined"?globalThis:l||self,l.MoneyHash=o())})(this,function(){var N,se,V,re,j,ae,M,z,T,oe,D,de,W,ce,x,le;"use strict";var ye=Object.defineProperty,ve=Object.defineProperties;var we=Object.getOwnPropertyDescriptors;var ie=Object.getOwnPropertySymbols;var be=Object.prototype.hasOwnProperty,Pe=Object.prototype.propertyIsEnumerable;var Y=(l,o,m)=>o in l?ye(l,o,{enumerable:!0,configurable:!0,writable:!0,value:m}):l[o]=m,S=(l,o)=>{for(var m in o||(o={}))be.call(o,m)&&Y(l,m,o[m]);if(ie)for(var m of ie(o))Pe.call(o,m)&&Y(l,m,o[m]);return l},ne=(l,o)=>ve(l,we(o));var f=(l,o,m)=>(Y(l,typeof o!="symbol"?o+"":o,m),m),Ee=(l,o,m)=>{if(!o.has(l))throw TypeError("Cannot "+m)};var L=(l,o,m)=>{if(o.has(l))throw TypeError("Cannot add the same private member more than once");o instanceof WeakSet?o.add(l):o.set(l,m)};var k=(l,o,m)=>(Ee(l,o,"access private method"),m);var b=(l,o,m)=>new Promise((A,w)=>{var H=P=>{try{C(m.next(P))}catch(U){w(U)}},R=P=>{try{C(m.throw(P))}catch(U){w(U)}},C=P=>P.done?A(P.value):Promise.resolve(P.value).then(H,R);C((m=m.apply(l,o)).next())});class l{constructor(e){f(this,"target");f(this,"targetOrigin");f(this,"listeners");f(this,"onIncomingMessageBind",this.onIncomingMessage.bind(this));this.target=e.target,this.targetOrigin=e.targetOrigin,this.listeners=[],window.addEventListener("message",this.onIncomingMessageBind)}send(e){this.target.postMessage(e,this.targetOrigin)}onReceive(e){this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter(t=>t!==e)}onIncomingMessage(e){e.origin===this.targetOrigin&&this.listeners.forEach(t=>{t(e,this.send.bind(this))})}abortService(){window.removeEventListener("message",this.onIncomingMessageBind)}}function o(){var e;return(e=window.MONEYHASH_IFRAME_URL)!=null?e:"https://embed.moneyhash.io"}function m(){return typeof window!="undefined"}const E=class{constructor(){m()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=o(),t=new URL(`${e}/embed/headless-sdk`);t.searchParams.set("sdk","true"),t.searchParams.set("parent",window.location.origin),t.searchParams.set("version","js@1.4.3-beta.0");const r=document.createElement("iframe");r.id="moneyhash-headless-sdk",r.src=t.toString(),r.hidden=!0,document.body.appendChild(r),E.messagingService=new l({target:r.contentWindow,targetOrigin:e}),E.isCommunicationReady=new Promise(i=>{var h;const s=a=>{var n;a.data.type==="headlessSDK:init"&&(i(),(n=E.messagingService)==null||n.removeListener(s))};(h=E.messagingService)==null||h.onReceive(s)})}request(r){return b(this,arguments,function*({api:e,payload:t}){return yield E.isCommunicationReady,new Promise((i,s)=>{var a,n;(a=E.messagingService)==null||a.send({type:e,data:t});const h=c=>{var p;const{type:d,data:u}=c.data;d===e&&(u.status==="resolved"?i(u.payload):s(u.payload),(p=E.messagingService)==null||p.removeListener(h))};(n=E.messagingService)==null||n.onReceive(h)})})}};let A=E;f(A,"messagingService",null),f(A,"isCommunicationReady");function w(g,e){if(g)throw new Error(e)}const H=new Set(["payment","payout"]),R=new Set(["en","fr","ar"]);class C{constructor(e){f(this,"options");f(this,"messagingService",null);f(this,"iframe",null);f(this,"isCommunicationReady",null);w(!H.has(e.type),`MoneyHash constructor must be called with valid type (${[...H].join(" | ")})!`),this.options=e}get lang(){var t;return((t=this.options.locale)==null?void 0:t.split("-")[0])||"en"}render({selector:e,intentId:t}){var a,n;(a=this.messagingService)==null||a.abortService();const r=o(),i=new URL(`${r}/embed/${this.options.type}/${t}`);i.searchParams.set("sdk","true"),i.searchParams.set("parent",window.location.origin),i.searchParams.set("version","js@1.4.3-beta.0");const s=(n=this.options.locale)==null?void 0:n.split("-")[0];s&&i.searchParams.set("lang",s),this.iframe=document.createElement("iframe"),this.iframe.src=i.toString(),this.iframe.style.height="100%",this.iframe.style.width="100%",this.iframe.style.border="0";const h=document.querySelector(e);return w(!h,`Couldn't find an element with selector ${e}!`),h.replaceChildren(this.iframe),this.messagingService=new l({target:this.iframe.contentWindow,targetOrigin:r}),this.isCommunicationReady=new Promise(c=>{var u;const d=p=>{var y;p.data.type==="sdk:init"&&(c(),(y=this.messagingService)==null||y.removeListener(d))};(u=this.messagingService)==null||u.onReceive(d)}),this.messagingService.onReceive((c,d)=>{var y,v,_,$;const{type:u,data:p}=c.data;switch(u){case"sdk:init":{d({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(v=(y=this.options).onComplete)==null||v.call(y,S({type:this.options.type},p)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{($=(_=this.options).onFail)==null||$.call(_,S({type:this.options.type},p)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}}}),this.isCommunicationReady}setLocale(e){return b(this,null,function*(){var t;yield this==null?void 0:this.isCommunicationReady,this.options.locale=e,(t=this.messagingService)==null||t.send({type:"changeLanguage",data:{locale:e}})})}abortService(){return b(this,null,function*(){var e;yield this==null?void 0:this.isCommunicationReady,(e=this.messagingService)==null||e.abortService()})}}class P{constructor(){f(this,"promise");f(this,"resolve");f(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function U(){var e;return(e=window.MONEYHASH_VAULT_API_URL)!=null?e:"https://vault.moneyhash.io"}function O(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function J(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}function he(g){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!g.includes(t))return t;return null}function me(g){return(Array.isArray(g)?g.length:Object.keys(g).length)===0}function ue(g,e){return new Promise((t,r)=>{if(document.getElementById(e)){t(void 0);return}const s=document.createElement("script");s.src=g,s.id=e,s.addEventListener("load",()=>{t(void 0)}),s.addEventListener("error",()=>{r(new Error("Script failed to load"))}),document.body.appendChild(s)})}function pe(g){return new Promise(e=>{setTimeout(()=>{e("done")},g*1e3)})}function ge(g,e){g&&console.warn(e)}const K=new Set(["method","customerBalance","savedCard"]);class fe{constructor(e){L(this,N);L(this,V);L(this,j);L(this,M);L(this,T);L(this,D);L(this,W);L(this,x);f(this,"options");f(this,"sdkApiHandler",new A);f(this,"sdkEmbed");f(this,"vaultSubmitListener",{current:null});f(this,"mountedCardElements",[]);this.options=e,this.sdkEmbed=new C(ne(S({},e),{headless:!0})),k(this,D,de).call(this,this.vaultSubmitListener)}getIntentDetails(e){return this.sdkApiHandler.request({api:"sdk:getIntentDetails",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}getIntentMethods(e){return this.sdkApiHandler.request({api:"sdk:getIntentMethods",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}proceedWith({intentId:e,type:t,id:r,metaData:i}){return w(!K.has(t),`type must be a valid one (${[...K].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:r,lang:this.sdkEmbed.lang,metaData:i}})}resetSelectedMethod(e){return this.sdkApiHandler.request({api:"sdk:resetSelectedMethod",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}deleteCard({cardId:e,intentSecret:t}){return w(this.options.type==="payout","deleteCard is allowed only for payment intent!"),this.sdkApiHandler.request({api:"sdk:deleteCard",payload:{cardId:e,intentSecret:t,lang:this.sdkEmbed.lang}})}payWithApplePay(c){return b(this,arguments,function*({intentId:e,currency:t,amount:r,countryCode:i,onCancel:s=()=>{},onError:h,onComplete:a,billingData:n={}}){if(yield ue("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)return;const d=new ApplePaySession(3,{countryCode:i,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${r}`}}),{state:u,intent:p}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(u==="INTENT_FORM"){if(me(n))throw new Error("Billing data is missing while calling payWithApplePay");yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"APPLE_PAY",lang:this.sdkEmbed.lang,billingData:n}})}}catch(y){throw yield this.resetSelectedMethod(e),y}d.onvalidatemerchant=y=>{fetch(`${J()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:p.secret,validation_url:y.validationURL})}).then(v=>v.ok?v.json():Promise.reject()).then(v=>d.completeMerchantValidation(v)).catch(h)},d.onpaymentauthorized=y=>{fetch(`${J()}/api/v1/providers/applepay/token/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({token_data:y.payment.token,secret:p.secret})}).then(v=>v.ok?v.json():Promise.reject()).then(()=>{d.completePayment(ApplePaySession.STATUS_SUCCESS),a()}).catch(()=>{d.completePayment(ApplePaySession.STATUS_FAILURE),h()})},d.oncancel=s,d.begin()})}renderForm({selector:e,intentId:t}){return w(!e,"selector is required for renderForm"),w(!t,"intentId is required for renderForm"),this.sdkEmbed.render({selector:e,intentId:t})}setLocale(e){ge(!!e&&!R.has(e),`Invalid locale. Supported languages (${[...R].join(" | ")})`);const t=R.has(e)?e:"en";return this.sdkEmbed.setLocale(t)}removeEventListeners(){return this.sdkEmbed.abortService()}updateIntentDiscount({intentId:e,discount:t}){return w(!t.title.en,"English discount title is required!"),this.sdkApiHandler.request({api:"sdk:updateIntentDiscount",payload:{intentId:e,discount:t,lang:this.sdkEmbed.lang}})}updateIntentFees({intentId:e,fees:t}){return t.forEach(r=>{w(!r.title.en,"English fee title is required!")}),this.sdkApiHandler.request({api:"sdk:updateIntentFees",payload:{intentId:e,fees:t,lang:this.sdkEmbed.lang}})}elements({styles:e,classes:t,fontSourceCss:r}){const i=[],s={},h=new Map;let a=!1;return k(this,T,oe).call(this,i),{create:({elementType:n,elementOptions:c})=>{var _,$;const d=new Map,u=document.querySelector(c.selector);w(!u,`Couldn't find an element with selector ${c.selector}!`),u.classList.add("MoneyHashElement");const p=S(S({},t),c.classes),y=((_=p==null?void 0:p.focus)==null?void 0:_.split(" "))||["MoneyHashElement--focus"],v=(($=p==null?void 0:p.error)==null?void 0:$.split(" "))||["MoneyHashElement--error"];return i.push(F=>{var G,Q,X,Z,ee,te;const{type:I,data:q}=F.data;if(I===`${n}:init`&&(s[n]=q.isValid),I===`${n}@focus`){u.classList.add(...y),(G=d.get(`${n}@focus`))==null||G();return}if(I===`${n}@blur`){u.classList.remove(...y),(Q=d.get(`${n}@blur`))==null||Q();return}if(I===`${n}@error`){q.isValid?u.classList.remove(...v):u.classList.add(...v),(X=d.get(`${n}@error`))==null||X(q);return}if(I===`${n}@changeInput`){if((Z=d.get(`${n}@changeInput`))==null||Z(),s[n]=q.isValid,h.get("validityChange")){const B=Object.values(s).every(Boolean);B!==a&&((ee=h.get("validityChange"))==null||ee(B),a=B)}return}I===`${n}@cardNumberChange`&&((te=d.get(`${n}@cardNumberChange`))==null||te(q))}),{mount:()=>{this.mountedCardElements.push(n),k(this,W,ce).call(this,{container:u,elementType:n,elementOptions:c,styles:S(S({},e),c.styles),fontSourceCss:r})},on:(F,I)=>{d.set(`${n}@${F}`,I)},off:F=>d.delete(`${n}@${F}`)}},on:(n,c)=>{h.set(n,c)}}}submitForm(h){return b(this,arguments,function*({intentId:e,accessToken:t,billingData:r,shippingData:i,saveCard:s}){const a=he(this.mountedCardElements);w(!!a,`You must mount ${a} element!`);const n=new P;let c,d;t&&(this.vaultSubmitListener.current=p=>{const{type:y,data:v}=p.data;y==="vaultSubmit:success"&&n.resolve(v),y==="vaultSubmit:error"&&n.reject(v)},d=k(this,x,le).call(this,{accessToken:t,saveCard:s}),c=yield n.promise);const u=yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"CARD",lang:this.sdkEmbed.lang,billingData:r,shippingData:i,cardEmbed:c}});return d&&d.remove(),u})}submitCvv(r){return b(this,arguments,function*({intentId:e,cvv:t}){return this.sdkApiHandler.request({api:"sdk:submitCardCvv",payload:{intentId:e,cvv:t,lang:this.sdkEmbed.lang}})})}renderUrl(s){return b(this,arguments,function*({intentId:e,url:t,renderStrategy:r,options:i}){switch(r){case"IFRAME":return k(this,N,se).call(this,{url:t,intentId:e});case"POPUP_IFRAME":return k(this,V,re).call(this,{url:t,intentId:e,options:i});case"REDIRECT":return k(this,j,ae).call(this,{url:t,options:i});default:return null}})}onExpiration(e,t){const r=new Date(e),i=setInterval(()=>b(this,null,function*(){const s=new Date;r<s&&(clearInterval(i),t())}),1e3);return()=>clearInterval(i)}}return N=new WeakSet,se=function(r){return b(this,arguments,function*({intentId:e,url:t}){const i=document.querySelector("#rendered-url-iframe-container");w(!i,"Couldn't find an element with id rendered-url-iframe-container to render the iframe!");const s=document.createElement("iframe");s.src=t,s.style.setProperty("border","0","important"),s.style.setProperty("width","100%","important"),s.style.setProperty("height","100%","important"),i==null||i.replaceChildren(s),yield k(this,M,z).call(this,e),s.remove()})},V=new WeakSet,re=function(i){return b(this,arguments,function*({intentId:e,url:t,options:r={}}){const{width:s=600,height:h=400,left:a=200,top:n=200}=r.window||{},c=window.open(t,"",`width=${s},height=${h},left=${a},top=${n}`);w(!c,"Popup blocked by browser!"),setTimeout(()=>{window.xx=c,console.log(c==null?void 0:c.closed)},1e3),yield k(this,M,z).call(this,e),c==null||c.close()})},j=new WeakSet,ae=function(r){return b(this,arguments,function*({url:e,options:t}){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},M=new WeakSet,z=function(e){return b(this,null,function*(){const t=new P,r=i=>b(this,null,function*(){var h,a,n,c;if(i.origin!==o())return;const{type:s}=i.data;if(s==="intentResult"){const[d]=yield Promise.all([this.getIntentDetails(e),pe(1)]),u=d.transaction.status.split(".")[1];u==="successful"||u.startsWith("pending")?(a=(h=this.options).onComplete)==null||a.call(h,S({type:this.options.type},d)):(c=(n=this.options).onFail)==null||c.call(n,S({type:this.options.type},d)),t.resolve(()=>null),window.removeEventListener("message",r)}});return window.addEventListener("message",r),t.promise})},T=new WeakSet,oe=function(e){const t=r=>{r.origin===O()&&e.forEach(i=>{i(r)})};window.addEventListener("message",t)},D=new WeakSet,de=function(e){const t=r=>{e.current&&e.current(r)};window.addEventListener("message",t)},W=new WeakSet,ce=function({container:e,elementType:t,elementOptions:r,styles:i,fontSourceCss:s}){var c,d,u,p;const h=O(),a=new URL(`${h}/vaultField/vaultField.html`);s&&a.searchParams.set("fontSourceCss",s),a.searchParams.set("host",btoa(window.location.origin)),a.searchParams.set("type",t),((c=r.validation)==null?void 0:c.required)!==void 0&&a.searchParams.set("required",`${(d=r.validation)==null?void 0:d.required}`),a.searchParams.set("placeholder",(u=r.placeholder)!=null?u:""),a.searchParams.set("lang",this.sdkEmbed.lang),a.searchParams.set("direction",(i==null?void 0:i.direction)||""),a.searchParams.set("color",JSON.stringify(i!=null&&i.color?i.color:"#000")),a.searchParams.set("placeholderColor",(i==null?void 0:i.placeholderColor)||"#ccc"),a.searchParams.set("backgroundColor",(i==null?void 0:i.backgroundColor)||"transparent"),a.searchParams.set("fontSize",(i==null?void 0:i.fontSize)||""),a.searchParams.set("fontFamily",(i==null?void 0:i.fontFamily)||""),a.searchParams.set("fontWeight",`${i==null?void 0:i.fontWeight}`),a.searchParams.set("fontStyle",(i==null?void 0:i.fontStyle)||""),a.searchParams.set("padding",(i==null?void 0:i.padding)||"");const n=document.createElement("iframe");n.src=a.toString(),n.style.height=(p=i==null?void 0:i.height)!=null?p:"40px",n.style.setProperty("overflow","hidden","important"),n.style.setProperty("display","block","important"),n.style.setProperty("width","100%","important"),n.style.setProperty("maxWidth","100%","important"),n.style.setProperty("border","0","important"),n.style.setProperty("margin","0","important"),n.style.setProperty("padding","0","important"),n.style.setProperty("userSelect","none","important"),n.style.setProperty("colorScheme","light only","important"),e.replaceChildren(n)},x=new WeakSet,le=function({accessToken:e,saveCard:t}){const r=O(),i=U(),s=new URL(`${r}/vaultSubmit/vaultSubmit.html`);s.searchParams.set("host",btoa(window.location.origin)),s.searchParams.set("vault_api_url",`${i}/api/v1/tokens/`),s.searchParams.set("access_token",e),s.searchParams.set("lang",this.sdkEmbed.lang),t!==void 0&&s.searchParams.set("save_card",`${t}`);const h=document.createElement("iframe");return h.id="moneyhash-submit-iframe",h.src=s.toString(),h.hidden=!0,document.body.appendChild(h),h},fe});
(function(c,o){typeof exports=="object"&&typeof module!="undefined"?module.exports=o():typeof define=="function"&&define.amd?define(o):(c=typeof globalThis!="undefined"?globalThis:c||self,c.MoneyHash=o())})(this,function(){var N,se,V,re,j,ae,M,z,T,oe,D,de,W,ce,x,le;"use strict";var ye=Object.defineProperty,ve=Object.defineProperties;var we=Object.getOwnPropertyDescriptors;var ie=Object.getOwnPropertySymbols;var be=Object.prototype.hasOwnProperty,Pe=Object.prototype.propertyIsEnumerable;var Y=(c,o,m)=>o in c?ye(c,o,{enumerable:!0,configurable:!0,writable:!0,value:m}):c[o]=m,S=(c,o)=>{for(var m in o||(o={}))be.call(o,m)&&Y(c,m,o[m]);if(ie)for(var m of ie(o))Pe.call(o,m)&&Y(c,m,o[m]);return c},ne=(c,o)=>ve(c,we(o));var y=(c,o,m)=>(Y(c,typeof o!="symbol"?o+"":o,m),m),Ee=(c,o,m)=>{if(!o.has(c))throw TypeError("Cannot "+m)};var L=(c,o,m)=>{if(o.has(c))throw TypeError("Cannot add the same private member more than once");o instanceof WeakSet?o.add(c):o.set(c,m)};var k=(c,o,m)=>(Ee(c,o,"access private method"),m);var b=(c,o,m)=>new Promise((A,w)=>{var q=E=>{try{C(m.next(E))}catch(U){w(U)}},R=E=>{try{C(m.throw(E))}catch(U){w(U)}},C=E=>E.done?A(E.value):Promise.resolve(E.value).then(q,R);C((m=m.apply(c,o)).next())});class c{constructor(e){y(this,"target");y(this,"targetOrigin");y(this,"listeners");y(this,"onIncomingMessageBind",this.onIncomingMessage.bind(this));this.target=e.target,this.targetOrigin=e.targetOrigin,this.listeners=[],window.addEventListener("message",this.onIncomingMessageBind)}send(e){this.target.postMessage(e,this.targetOrigin)}onReceive(e){this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter(t=>t!==e)}onIncomingMessage(e){e.origin===this.targetOrigin&&this.listeners.forEach(t=>{t(e,this.send.bind(this))})}abortService(){window.removeEventListener("message",this.onIncomingMessageBind)}}function o(){var e;return(e=window.MONEYHASH_IFRAME_URL)!=null?e:"https://embed.moneyhash.io"}function m(){return typeof window!="undefined"}const P=class{constructor(){m()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=o(),t=new URL(`${e}/embed/headless-sdk`);t.searchParams.set("sdk","true"),t.searchParams.set("parent",window.location.origin),t.searchParams.set("version","js@1.4.3");const r=document.createElement("iframe");r.id="moneyhash-headless-sdk",r.src=t.toString(),r.hidden=!0,document.body.appendChild(r),P.messagingService=new c({target:r.contentWindow,targetOrigin:e}),P.isCommunicationReady=new Promise(i=>{var l;const s=a=>{var n;a.data.type==="headlessSDK:init"&&(i(),(n=P.messagingService)==null||n.removeListener(s))};(l=P.messagingService)==null||l.onReceive(s)})}request(r){return b(this,arguments,function*({api:e,payload:t}){return yield P.isCommunicationReady,new Promise((i,s)=>{var a,n;(a=P.messagingService)==null||a.send({type:e,data:t});const l=h=>{var u;const{type:d,data:p}=h.data;d===e&&(p.status==="resolved"?i(p.payload):s(p.payload),(u=P.messagingService)==null||u.removeListener(l))};(n=P.messagingService)==null||n.onReceive(l)})})}postMessage(e){var t;(t=P.messagingService)==null||t.send({type:e})}};let A=P;y(A,"messagingService",null),y(A,"isCommunicationReady");function w(g,e){if(g)throw new Error(e)}const q=new Set(["payment","payout"]),R=new Set(["en","fr","ar"]);class C{constructor(e){y(this,"options");y(this,"messagingService",null);y(this,"iframe",null);y(this,"isCommunicationReady",null);w(!q.has(e.type),`MoneyHash constructor must be called with valid type (${[...q].join(" | ")})!`),this.options=e}get lang(){var t;return((t=this.options.locale)==null?void 0:t.split("-")[0])||"en"}render({selector:e,intentId:t}){var a,n;(a=this.messagingService)==null||a.abortService();const r=o(),i=new URL(`${r}/embed/${this.options.type}/${t}`);i.searchParams.set("sdk","true"),i.searchParams.set("parent",window.location.origin),i.searchParams.set("version","js@1.4.3");const s=(n=this.options.locale)==null?void 0:n.split("-")[0];s&&i.searchParams.set("lang",s),this.iframe=document.createElement("iframe"),this.iframe.src=i.toString(),this.iframe.style.height="100%",this.iframe.style.width="100%",this.iframe.style.border="0";const l=document.querySelector(e);return w(!l,`Couldn't find an element with selector ${e}!`),l.replaceChildren(this.iframe),this.messagingService=new c({target:this.iframe.contentWindow,targetOrigin:r}),this.isCommunicationReady=new Promise(h=>{var p;const d=u=>{var f;u.data.type==="sdk:init"&&(h(),(f=this.messagingService)==null||f.removeListener(d))};(p=this.messagingService)==null||p.onReceive(d)}),this.messagingService.onReceive((h,d)=>{var f,v,_,$;const{type:p,data:u}=h.data;switch(p){case"sdk:init":{d({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(v=(f=this.options).onComplete)==null||v.call(f,S({type:this.options.type},u)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{($=(_=this.options).onFail)==null||$.call(_,S({type:this.options.type},u)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}}}),this.isCommunicationReady}setLocale(e){return b(this,null,function*(){var t;yield this==null?void 0:this.isCommunicationReady,this.options.locale=e,(t=this.messagingService)==null||t.send({type:"changeLanguage",data:{locale:e}})})}abortService(){return b(this,null,function*(){var e;yield this==null?void 0:this.isCommunicationReady,(e=this.messagingService)==null||e.abortService()})}}class E{constructor(){y(this,"promise");y(this,"resolve");y(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function U(){var e;return(e=window.MONEYHASH_VAULT_API_URL)!=null?e:"https://vault.moneyhash.io"}function O(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function J(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}function he(g){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!g.includes(t))return t;return null}function me(g){return(Array.isArray(g)?g.length:Object.keys(g).length)===0}function pe(g,e){return new Promise((t,r)=>{if(document.getElementById(e)){t(void 0);return}const s=document.createElement("script");s.src=g,s.id=e,s.addEventListener("load",()=>{t(void 0)}),s.addEventListener("error",()=>{r(new Error("Script failed to load"))}),document.body.appendChild(s)})}function ue(g){return new Promise(e=>{setTimeout(()=>{e("done")},g*1e3)})}function ge(g,e){g&&console.warn(e)}const K=new Set(["method","customerBalance","savedCard"]);class fe{constructor(e){L(this,N);L(this,V);L(this,j);L(this,M);L(this,T);L(this,D);L(this,W);L(this,x);y(this,"options");y(this,"sdkApiHandler",new A);y(this,"sdkEmbed");y(this,"vaultSubmitListener",{current:null});y(this,"mountedCardElements",[]);this.options=e,this.sdkEmbed=new C(ne(S({},e),{headless:!0})),k(this,D,de).call(this,this.vaultSubmitListener)}getIntentDetails(e){return this.sdkApiHandler.request({api:"sdk:getIntentDetails",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}getIntentMethods(e){return this.sdkApiHandler.request({api:"sdk:getIntentMethods",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}proceedWith({intentId:e,type:t,id:r,metaData:i}){return w(!K.has(t),`type must be a valid one (${[...K].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:r,lang:this.sdkEmbed.lang,metaData:i}})}resetSelectedMethod(e){return this.sdkApiHandler.request({api:"sdk:resetSelectedMethod",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}deleteCard({cardId:e,intentSecret:t}){return w(this.options.type==="payout","deleteCard is allowed only for payment intent!"),this.sdkApiHandler.request({api:"sdk:deleteCard",payload:{cardId:e,intentSecret:t,lang:this.sdkEmbed.lang}})}payWithApplePay(h){return b(this,arguments,function*({intentId:e,currency:t,amount:r,countryCode:i,onCancel:s=()=>{},onError:l,onComplete:a,billingData:n={}}){if(yield pe("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)return;const d=new ApplePaySession(3,{countryCode:i,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${r}`}}),{state:p,intent:u}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(p==="INTENT_FORM"){if(me(n))throw new Error("Billing data is missing while calling payWithApplePay");yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"APPLE_PAY",lang:this.sdkEmbed.lang,billingData:n}})}}catch(f){throw yield this.resetSelectedMethod(e),f}d.onvalidatemerchant=f=>{fetch(`${J()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:u.secret,validation_url:f.validationURL})}).then(v=>v.ok?v.json():Promise.reject()).then(v=>d.completeMerchantValidation(v)).catch(l)},d.onpaymentauthorized=f=>{fetch(`${J()}/api/v1/providers/applepay/token/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({token_data:f.payment.token,secret:u.secret})}).then(v=>v.ok?v.json():Promise.reject()).then(()=>{d.completePayment(ApplePaySession.STATUS_SUCCESS),a()}).catch(()=>{d.completePayment(ApplePaySession.STATUS_FAILURE),l()})},d.oncancel=s,d.begin()})}renderForm({selector:e,intentId:t}){return w(!e,"selector is required for renderForm"),w(!t,"intentId is required for renderForm"),this.sdkEmbed.render({selector:e,intentId:t})}setLocale(e){ge(!!e&&!R.has(e),`Invalid locale. Supported languages (${[...R].join(" | ")})`);const t=R.has(e)?e:"en";return this.sdkEmbed.setLocale(t)}removeEventListeners(){return this.sdkEmbed.abortService()}updateIntentDiscount({intentId:e,discount:t}){return w(!t.title.en,"English discount title is required!"),this.sdkApiHandler.request({api:"sdk:updateIntentDiscount",payload:{intentId:e,discount:t,lang:this.sdkEmbed.lang}})}updateIntentFees({intentId:e,fees:t}){return t.forEach(r=>{w(!r.title.en,"English fee title is required!")}),this.sdkApiHandler.request({api:"sdk:updateIntentFees",payload:{intentId:e,fees:t,lang:this.sdkEmbed.lang}})}elements({styles:e,classes:t,fontSourceCss:r}){const i=[],s={},l=new Map;let a=!1;return k(this,T,oe).call(this,i),{create:({elementType:n,elementOptions:h})=>{var _,$;const d=new Map,p=document.querySelector(h.selector);w(!p,`Couldn't find an element with selector ${h.selector}!`),p.classList.add("MoneyHashElement");const u=S(S({},t),h.classes),f=((_=u==null?void 0:u.focus)==null?void 0:_.split(" "))||["MoneyHashElement--focus"],v=(($=u==null?void 0:u.error)==null?void 0:$.split(" "))||["MoneyHashElement--error"];return i.push(F=>{var G,Q,X,Z,ee,te;const{type:I,data:H}=F.data;if(I===`${n}:init`&&(s[n]=H.isValid),I===`${n}@focus`){p.classList.add(...f),(G=d.get(`${n}@focus`))==null||G();return}if(I===`${n}@blur`){p.classList.remove(...f),(Q=d.get(`${n}@blur`))==null||Q();return}if(I===`${n}@error`){H.isValid?p.classList.remove(...v):p.classList.add(...v),(X=d.get(`${n}@error`))==null||X(H);return}if(I===`${n}@changeInput`){if((Z=d.get(`${n}@changeInput`))==null||Z(),s[n]=H.isValid,l.get("validityChange")){const B=Object.values(s).every(Boolean);B!==a&&((ee=l.get("validityChange"))==null||ee(B),a=B)}return}I===`${n}@cardNumberChange`&&((te=d.get(`${n}@cardNumberChange`))==null||te(H))}),{mount:()=>{this.mountedCardElements.push(n),k(this,W,ce).call(this,{container:p,elementType:n,elementOptions:h,styles:S(S({},e),h.styles),fontSourceCss:r})},on:(F,I)=>{d.set(`${n}@${F}`,I)},off:F=>d.delete(`${n}@${F}`)}},on:(n,h)=>{l.set(n,h)}}}submitForm(l){return b(this,arguments,function*({intentId:e,accessToken:t,billingData:r,shippingData:i,saveCard:s}){const a=he(this.mountedCardElements);w(!!a,`You must mount ${a} element!`);const n=new E;let h,d;t&&(this.vaultSubmitListener.current=u=>{const{type:f,data:v}=u.data;f==="vaultSubmit:success"&&n.resolve(v),f==="vaultSubmit:error"&&n.reject(v)},d=k(this,x,le).call(this,{accessToken:t,saveCard:s}),h=yield n.promise);const p=yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"CARD",lang:this.sdkEmbed.lang,billingData:r,shippingData:i,cardEmbed:h}});return d&&d.remove(),p})}submitCvv(r){return b(this,arguments,function*({intentId:e,cvv:t}){return this.sdkApiHandler.request({api:"sdk:submitCardCvv",payload:{intentId:e,cvv:t,lang:this.sdkEmbed.lang}})})}renderUrl(s){return b(this,arguments,function*({intentId:e,url:t,renderStrategy:r,options:i}){switch(r){case"IFRAME":return k(this,N,se).call(this,{url:t,intentId:e});case"POPUP_IFRAME":return k(this,V,re).call(this,{url:t,intentId:e,options:i});case"REDIRECT":return k(this,j,ae).call(this,{url:t,options:i});default:return null}})}onExpiration(e,t){const r=new Date(e),i=setInterval(()=>b(this,null,function*(){const s=new Date;r<s&&(clearInterval(i),t())}),1e3);return()=>clearInterval(i)}}return N=new WeakSet,se=function(r){return b(this,arguments,function*({intentId:e,url:t}){const i=document.querySelector("#rendered-url-iframe-container");w(!i,"Couldn't find an element with id rendered-url-iframe-container to render the iframe!");const s=document.createElement("iframe");s.src=t,s.style.setProperty("border","0","important"),s.style.setProperty("width","100%","important"),s.style.setProperty("height","100%","important"),i==null||i.replaceChildren(s),yield k(this,M,z).call(this,{intentId:e}),s.remove()})},V=new WeakSet,re=function(i){return b(this,arguments,function*({intentId:e,url:t,options:r={}}){const{width:s=600,height:l=400,left:a=200,top:n=200}=r.window||{},h=window.open(t,"",`width=${s},height=${l},left=${a},top=${n}`);w(!h,"Popup blocked by browser!"),yield k(this,M,z).call(this,{intentId:e,isUsingPopUp:!0}),h==null||h.close()})},j=new WeakSet,ae=function(r){return b(this,arguments,function*({url:e,options:t}){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},M=new WeakSet,z=function(r){return b(this,arguments,function*({intentId:e,isUsingPopUp:t=!1}){const i=new E,s=l=>b(this,null,function*(){var n,h,d,p;if(l.origin!==o())return;const{type:a}=l.data;if(a==="intentResult"){t&&this.sdkApiHandler.postMessage("EmbedResultClose");const[u]=yield Promise.all([this.getIntentDetails(e),ue(1)]),f=u.transaction.status.split(".")[1];f==="successful"||f.startsWith("pending")?(h=(n=this.options).onComplete)==null||h.call(n,S({type:this.options.type},u)):(p=(d=this.options).onFail)==null||p.call(d,S({type:this.options.type},u)),i.resolve(()=>null),window.removeEventListener("message",s)}});return window.addEventListener("message",s),i.promise})},T=new WeakSet,oe=function(e){const t=r=>{r.origin===O()&&e.forEach(i=>{i(r)})};window.addEventListener("message",t)},D=new WeakSet,de=function(e){const t=r=>{e.current&&e.current(r)};window.addEventListener("message",t)},W=new WeakSet,ce=function({container:e,elementType:t,elementOptions:r,styles:i,fontSourceCss:s}){var h,d,p,u;const l=O(),a=new URL(`${l}/vaultField/vaultField.html`);s&&a.searchParams.set("fontSourceCss",s),a.searchParams.set("host",btoa(window.location.origin)),a.searchParams.set("type",t),((h=r.validation)==null?void 0:h.required)!==void 0&&a.searchParams.set("required",`${(d=r.validation)==null?void 0:d.required}`),a.searchParams.set("placeholder",(p=r.placeholder)!=null?p:""),a.searchParams.set("lang",this.sdkEmbed.lang),a.searchParams.set("direction",(i==null?void 0:i.direction)||""),a.searchParams.set("color",JSON.stringify(i!=null&&i.color?i.color:"#000")),a.searchParams.set("placeholderColor",(i==null?void 0:i.placeholderColor)||"#ccc"),a.searchParams.set("backgroundColor",(i==null?void 0:i.backgroundColor)||"transparent"),a.searchParams.set("fontSize",(i==null?void 0:i.fontSize)||""),a.searchParams.set("fontFamily",(i==null?void 0:i.fontFamily)||""),a.searchParams.set("fontWeight",`${i==null?void 0:i.fontWeight}`),a.searchParams.set("fontStyle",(i==null?void 0:i.fontStyle)||""),a.searchParams.set("padding",(i==null?void 0:i.padding)||"");const n=document.createElement("iframe");n.src=a.toString(),n.style.height=(u=i==null?void 0:i.height)!=null?u:"40px",n.style.setProperty("overflow","hidden","important"),n.style.setProperty("display","block","important"),n.style.setProperty("width","100%","important"),n.style.setProperty("maxWidth","100%","important"),n.style.setProperty("border","0","important"),n.style.setProperty("margin","0","important"),n.style.setProperty("padding","0","important"),n.style.setProperty("userSelect","none","important"),n.style.setProperty("colorScheme","light only","important"),e.replaceChildren(n)},x=new WeakSet,le=function({accessToken:e,saveCard:t}){const r=O(),i=U(),s=new URL(`${r}/vaultSubmit/vaultSubmit.html`);s.searchParams.set("host",btoa(window.location.origin)),s.searchParams.set("vault_api_url",`${i}/api/v1/tokens/`),s.searchParams.set("access_token",e),s.searchParams.set("lang",this.sdkEmbed.lang),t!==void 0&&s.searchParams.set("save_card",`${t}`);const l=document.createElement("iframe");return l.id="moneyhash-submit-iframe",l.src=s.toString(),l.hidden=!0,document.body.appendChild(l),l},fe});

@@ -1,1 +0,1 @@

"use strict";var n=Object.defineProperty;var d=(t,e,s)=>e in t?n(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var a=(t,e,s)=>(d(t,typeof e!="symbol"?e+"":e,s),s);const r=require("./warnIf-6822cba3.cjs");class o{constructor(e){a(this,"options");a(this,"sdkEmbed");this.options=e,this.sdkEmbed=new r.SDKEmbed(e)}start({selector:e,intentId:s}){return r.throwIf(!e,"selector is required for start"),r.throwIf(!s,"intentId is required for start"),this.sdkEmbed.render({selector:e,intentId:s})}setLocale(e){r.warnIf(!!e&&!r.supportedLanguages.has(e),`Invalid locale. Supported languages (${[...r.supportedLanguages].join(" | ")})`);const s=r.supportedLanguages.has(e)?e:"en";return this.sdkEmbed.setLocale(s)}removeEventListeners(){return this.sdkEmbed.abortService()}}module.exports=o;
"use strict";var n=Object.defineProperty;var d=(t,e,s)=>e in t?n(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var a=(t,e,s)=>(d(t,typeof e!="symbol"?e+"":e,s),s);const r=require("./warnIf-08c3effc.cjs");class o{constructor(e){a(this,"options");a(this,"sdkEmbed");this.options=e,this.sdkEmbed=new r.SDKEmbed(e)}start({selector:e,intentId:s}){return r.throwIf(!e,"selector is required for start"),r.throwIf(!s,"intentId is required for start"),this.sdkEmbed.render({selector:e,intentId:s})}setLocale(e){r.warnIf(!!e&&!r.supportedLanguages.has(e),`Invalid locale. Supported languages (${[...r.supportedLanguages].join(" | ")})`);const s=r.supportedLanguages.has(e)?e:"en";return this.sdkEmbed.setLocale(s)}removeEventListeners(){return this.sdkEmbed.abortService()}}module.exports=o;
var o = Object.defineProperty;
var n = (r, s, e) => s in r ? o(r, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[s] = e;
var t = (r, s, e) => (n(r, typeof s != "symbol" ? s + "" : s, e), e);
import { S as i, t as d, w as u, s as a } from "./warnIf-f46979fc.js";
import { S as i, t as d, w as u, s as a } from "./warnIf-c0417b00.js";
class b {

@@ -6,0 +6,0 @@ constructor(s) {

@@ -1,1 +0,1 @@

(function(i,s){typeof exports=="object"&&typeof module!="undefined"?module.exports=s():typeof define=="function"&&define.amd?define(s):(i=typeof globalThis!="undefined"?globalThis:i||self,i.MoneyHash=s())})(this,function(){"use strict";var F=Object.defineProperty;var O=Object.getOwnPropertySymbols;var U=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable;var v=(i,s,t)=>s in i?F(i,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[s]=t,w=(i,s)=>{for(var t in s||(s={}))U.call(s,t)&&v(i,t,s[t]);if(O)for(var t of O(s))$.call(s,t)&&v(i,t,s[t]);return i};var a=(i,s,t)=>(v(i,typeof s!="symbol"?s+"":s,t),t);var b=(i,s,t)=>new Promise((g,o)=>{var p=r=>{try{h(t.next(r))}catch(e){o(e)}},f=r=>{try{h(t.throw(r))}catch(e){o(e)}},h=r=>r.done?g(r.value):Promise.resolve(r.value).then(p,f);h((t=t.apply(i,s)).next())});class i{constructor(e){a(this,"target");a(this,"targetOrigin");a(this,"listeners");a(this,"onIncomingMessageBind",this.onIncomingMessage.bind(this));this.target=e.target,this.targetOrigin=e.targetOrigin,this.listeners=[],window.addEventListener("message",this.onIncomingMessageBind)}send(e){this.target.postMessage(e,this.targetOrigin)}onReceive(e){this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter(n=>n!==e)}onIncomingMessage(e){e.origin===this.targetOrigin&&this.listeners.forEach(n=>{n(e,this.send.bind(this))})}abortService(){window.removeEventListener("message",this.onIncomingMessageBind)}}function s(){var e;return(e=window.MONEYHASH_IFRAME_URL)!=null?e:"https://embed.moneyhash.io"}function t(r,e){if(r)throw new Error(e)}const g=new Set(["payment","payout"]),o=new Set(["en","fr","ar"]);class p{constructor(e){a(this,"options");a(this,"messagingService",null);a(this,"iframe",null);a(this,"isCommunicationReady",null);t(!g.has(e.type),`MoneyHash constructor must be called with valid type (${[...g].join(" | ")})!`),this.options=e}get lang(){var n;return((n=this.options.locale)==null?void 0:n.split("-")[0])||"en"}render({selector:e,intentId:n}){var L,M;(L=this.messagingService)==null||L.abortService();const S=s(),c=new URL(`${S}/embed/${this.options.type}/${n}`);c.searchParams.set("sdk","true"),c.searchParams.set("parent",window.location.origin),c.searchParams.set("version","js@1.4.3-beta.0");const R=(M=this.options.locale)==null?void 0:M.split("-")[0];R&&c.searchParams.set("lang",R),this.iframe=document.createElement("iframe"),this.iframe.src=c.toString(),this.iframe.style.height="100%",this.iframe.style.width="100%",this.iframe.style.border="0";const E=document.querySelector(e);return t(!E,`Couldn't find an element with selector ${e}!`),E.replaceChildren(this.iframe),this.messagingService=new i({target:this.iframe.contentWindow,targetOrigin:S}),this.isCommunicationReady=new Promise(y=>{var l;const m=u=>{var d;u.data.type==="sdk:init"&&(y(),(d=this.messagingService)==null||d.removeListener(m))};(l=this.messagingService)==null||l.onReceive(m)}),this.messagingService.onReceive((y,m)=>{var d,I,k,C;const{type:l,data:u}=y.data;switch(l){case"sdk:init":{m({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(I=(d=this.options).onComplete)==null||I.call(d,w({type:this.options.type},u)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{(C=(k=this.options).onFail)==null||C.call(k,w({type:this.options.type},u)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}}}),this.isCommunicationReady}setLocale(e){return b(this,null,function*(){var n;yield this==null?void 0:this.isCommunicationReady,this.options.locale=e,(n=this.messagingService)==null||n.send({type:"changeLanguage",data:{locale:e}})})}abortService(){return b(this,null,function*(){var e;yield this==null?void 0:this.isCommunicationReady,(e=this.messagingService)==null||e.abortService()})}}function f(r,e){r&&console.warn(e)}class h{constructor(e){a(this,"options");a(this,"sdkEmbed");this.options=e,this.sdkEmbed=new p(e)}start({selector:e,intentId:n}){return t(!e,"selector is required for start"),t(!n,"intentId is required for start"),this.sdkEmbed.render({selector:e,intentId:n})}setLocale(e){f(!!e&&!o.has(e),`Invalid locale. Supported languages (${[...o].join(" | ")})`);const n=o.has(e)?e:"en";return this.sdkEmbed.setLocale(n)}removeEventListeners(){return this.sdkEmbed.abortService()}}return h});
(function(i,s){typeof exports=="object"&&typeof module!="undefined"?module.exports=s():typeof define=="function"&&define.amd?define(s):(i=typeof globalThis!="undefined"?globalThis:i||self,i.MoneyHash=s())})(this,function(){"use strict";var F=Object.defineProperty;var O=Object.getOwnPropertySymbols;var U=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable;var v=(i,s,t)=>s in i?F(i,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[s]=t,w=(i,s)=>{for(var t in s||(s={}))U.call(s,t)&&v(i,t,s[t]);if(O)for(var t of O(s))$.call(s,t)&&v(i,t,s[t]);return i};var a=(i,s,t)=>(v(i,typeof s!="symbol"?s+"":s,t),t);var b=(i,s,t)=>new Promise((g,o)=>{var p=r=>{try{h(t.next(r))}catch(e){o(e)}},f=r=>{try{h(t.throw(r))}catch(e){o(e)}},h=r=>r.done?g(r.value):Promise.resolve(r.value).then(p,f);h((t=t.apply(i,s)).next())});class i{constructor(e){a(this,"target");a(this,"targetOrigin");a(this,"listeners");a(this,"onIncomingMessageBind",this.onIncomingMessage.bind(this));this.target=e.target,this.targetOrigin=e.targetOrigin,this.listeners=[],window.addEventListener("message",this.onIncomingMessageBind)}send(e){this.target.postMessage(e,this.targetOrigin)}onReceive(e){this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter(n=>n!==e)}onIncomingMessage(e){e.origin===this.targetOrigin&&this.listeners.forEach(n=>{n(e,this.send.bind(this))})}abortService(){window.removeEventListener("message",this.onIncomingMessageBind)}}function s(){var e;return(e=window.MONEYHASH_IFRAME_URL)!=null?e:"https://embed.moneyhash.io"}function t(r,e){if(r)throw new Error(e)}const g=new Set(["payment","payout"]),o=new Set(["en","fr","ar"]);class p{constructor(e){a(this,"options");a(this,"messagingService",null);a(this,"iframe",null);a(this,"isCommunicationReady",null);t(!g.has(e.type),`MoneyHash constructor must be called with valid type (${[...g].join(" | ")})!`),this.options=e}get lang(){var n;return((n=this.options.locale)==null?void 0:n.split("-")[0])||"en"}render({selector:e,intentId:n}){var L,M;(L=this.messagingService)==null||L.abortService();const S=s(),c=new URL(`${S}/embed/${this.options.type}/${n}`);c.searchParams.set("sdk","true"),c.searchParams.set("parent",window.location.origin),c.searchParams.set("version","js@1.4.3");const R=(M=this.options.locale)==null?void 0:M.split("-")[0];R&&c.searchParams.set("lang",R),this.iframe=document.createElement("iframe"),this.iframe.src=c.toString(),this.iframe.style.height="100%",this.iframe.style.width="100%",this.iframe.style.border="0";const E=document.querySelector(e);return t(!E,`Couldn't find an element with selector ${e}!`),E.replaceChildren(this.iframe),this.messagingService=new i({target:this.iframe.contentWindow,targetOrigin:S}),this.isCommunicationReady=new Promise(y=>{var l;const m=u=>{var d;u.data.type==="sdk:init"&&(y(),(d=this.messagingService)==null||d.removeListener(m))};(l=this.messagingService)==null||l.onReceive(m)}),this.messagingService.onReceive((y,m)=>{var d,I,k,C;const{type:l,data:u}=y.data;switch(l){case"sdk:init":{m({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(I=(d=this.options).onComplete)==null||I.call(d,w({type:this.options.type},u)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{(C=(k=this.options).onFail)==null||C.call(k,w({type:this.options.type},u)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}}}),this.isCommunicationReady}setLocale(e){return b(this,null,function*(){var n;yield this==null?void 0:this.isCommunicationReady,this.options.locale=e,(n=this.messagingService)==null||n.send({type:"changeLanguage",data:{locale:e}})})}abortService(){return b(this,null,function*(){var e;yield this==null?void 0:this.isCommunicationReady,(e=this.messagingService)==null||e.abortService()})}}function f(r,e){r&&console.warn(e)}class h{constructor(e){a(this,"options");a(this,"sdkEmbed");this.options=e,this.sdkEmbed=new p(e)}start({selector:e,intentId:n}){return t(!e,"selector is required for start"),t(!n,"intentId is required for start"),this.sdkEmbed.render({selector:e,intentId:n})}setLocale(e){f(!!e&&!o.has(e),`Invalid locale. Supported languages (${[...o].join(" | ")})`);const n=o.has(e)?e:"en";return this.sdkEmbed.setLocale(n)}removeEventListeners(){return this.sdkEmbed.abortService()}}return h});
{
"name": "@moneyhash/js-sdk",
"version": "1.4.3-beta.0",
"version": "1.4.3",
"description": "MoneyHash JavaScript SDK",

@@ -5,0 +5,0 @@ "type": "module",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc