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
62
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.0.6 to 1.1.0

dist/sdkEmbed-2ce660d7.cjs

2

dist/headless.cjs.js

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

"use strict";var O=Object.defineProperty,J=Object.defineProperties;var z=Object.getOwnPropertyDescriptors;var F=Object.getOwnPropertySymbols;var K=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable;var _=(n,e,t)=>e in n?O(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,P=(n,e)=>{for(var t in e||(e={}))K.call(e,t)&&_(n,t,e[t]);if(F)for(var t of F(e))G.call(e,t)&&_(n,t,e[t]);return n},$=(n,e)=>J(n,z(e));var h=(n,e,t)=>(_(n,typeof e!="symbol"?e+"":e,t),t),Q=(n,e,t)=>{if(!e.has(n))throw TypeError("Cannot "+t)};var v=(n,e,t)=>{if(e.has(n))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(n):e.set(n,t)};var g=(n,e,t)=>(Q(n,e,"access private method"),t);var f=(n,e,t)=>new Promise((r,s)=>{var o=i=>{try{a(t.next(i))}catch(c){s(c)}},d=i=>{try{a(t.throw(i))}catch(c){s(c)}},a=i=>i.done?r(i.value):Promise.resolve(i.value).then(o,d);a((t=t.apply(n,e)).next())});const u=require("./sdkEmbed-955a36b1.cjs");function X(){return typeof window!="undefined"}const w=class{constructor(){X()&&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.0.6");const r=document.createElement("iframe");r.id="moneyhash-headless-sdk",r.src=t.toString(),r.hidden=!0,document.body.appendChild(r),w.messagingService=new u.MessagingService({target:r.contentWindow,targetOrigin:e}),w.isCommunicationReady=new Promise(s=>{var d;const o=a=>{var i;a.data.type==="headlessSDK:init"&&(s(),(i=w.messagingService)==null||i.removeListener(o))};(d=w.messagingService)==null||d.onReceive(o)})}request(r){return f(this,arguments,function*({api:e,payload:t}){return yield w.isCommunicationReady,new Promise((s,o)=>{var a,i;(a=w.messagingService)==null||a.send({type:e,data:t});const d=c=>{var m;const{type:l,data:y}=c.data;l===e&&(y.status==="resolved"?s(y.payload):o(y.payload),(m=w.messagingService)==null||m.removeListener(d))};(i=w.messagingService)==null||i.onReceive(d)})})}};let E=w;h(E,"messagingService",null),h(E,"isCommunicationReady");class N{constructor(){h(this,"promise");h(this,"resolve");h(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function Z(){var e;return(e=window.MONEYHASH_VAULT_API_URL)!=null?e:"https://vault.moneyhash.io"}function T(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function ee(n){return(Array.isArray(n)?n.length:Object.keys(n).length)===0}function te(n,e){return new Promise((t,r)=>{if(document.getElementById(e)){t(void 0);return}const o=document.createElement("script");o.src=n,o.id=e,o.addEventListener("load",()=>{t(void 0)}),o.addEventListener("error",()=>{r(new Error("Script failed to load"))}),document.body.appendChild(o)})}function H(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}function re(n){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!n.includes(t))return t;return null}const q=new Set(["method","customerBalance","savedCard"]);var I,V,L,j,A,W,k,M,S,x,U,D,C,Y,R,B;class se{constructor(e){v(this,I);v(this,L);v(this,A);v(this,k);v(this,S);v(this,U);v(this,C);v(this,R);h(this,"options");h(this,"sdkApiHandler",new E);h(this,"sdkEmbed");h(this,"vaultSubmitListener",{current:null});h(this,"mountedCardElements",[]);this.options=e,this.sdkEmbed=new u.SDKEmbed($(P({},e),{headless:!0})),g(this,U,D).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:s}){return u.throwIf(!q.has(t),`type must be a valid one (${[...q].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:r,lang:this.sdkEmbed.lang,metaData:s}})}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:r,countryCode:s,onCancel:o=()=>{},onError:d,onComplete:a,billingData:i={}}){if(yield te("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)return;const l=new ApplePaySession(3,{countryCode:s,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${r}`}}),{state:y,intent:m}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(y==="INTENT_FORM"){if(ee(i))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:i}})}}catch(p){throw yield this.resetSelectedMethod(e),p}l.onvalidatemerchant=p=>{fetch(`${H()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:m.secret,validation_url:p.validationURL})}).then(b=>b.ok?b.json():Promise.reject()).then(b=>l.completeMerchantValidation(b)).catch(d)},l.onpaymentauthorized=p=>{fetch(`${H()}/api/v1/providers/applepay/token/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({token_data:p.payment.token,secret:m.secret})}).then(b=>b.ok?b.json():Promise.reject()).then(()=>{l.completePayment(ApplePaySession.STATUS_SUCCESS),a()}).catch(()=>{l.completePayment(ApplePaySession.STATUS_FAILURE),d()})},l.oncancel=o,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){return this.sdkEmbed.setLocale(e)}removeEventListeners(){return this.sdkEmbed.abortService()}elements({styles:e}){const t=[];return g(this,S,x).call(this,t),{create:({elementType:r,elementOptions:s})=>{const o=new Map,d=document.querySelector(s.selector);return u.throwIf(!d,`Couldn't find an element with selector ${s.selector}!`),d.classList.add("MoneyHashElement"),t.push(a=>{var l,y,m,p;const{type:i,data:c}=a.data;i===`${r}@focus`&&(d.classList.add("MoneyHashElement--focus"),(l=o.get(`${r}@focus`))==null||l()),i===`${r}@blur`&&(d.classList.remove("MoneyHashElement--focus"),(y=o.get(`${r}@blur`))==null||y()),i===`${r}@changeInput`&&((m=o.get(`${r}@changeInput`))==null||m()),i===`${r}@cardNumberChange`&&((p=o.get(`${r}@cardNumberChange`))==null||p(c))}),{mount:()=>{this.mountedCardElements.push(r),g(this,C,Y).call(this,{container:d,elementType:r,elementOptions:s,styles:P(P({},e),s.styles)})},on:(a,i)=>{o.set(`${r}@${a}`,i)}}}}}submitForm(o){return f(this,arguments,function*({intentId:e,accessToken:t,billingData:r,shippingData:s}){const d=re(this.mountedCardElements);u.throwIf(!!d,`You must mount ${d} element!`);const a=new N;let i,c;t&&(this.vaultSubmitListener.current=y=>{const{type:m,data:p}=y.data;m==="vaultSubmit:success"&&a.resolve(p),m==="vaultSubmit:error"&&a.reject(p)},c=g(this,R,B).call(this,t),i=yield a.promise);const l=yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"CARD",lang:this.sdkEmbed.lang,billingData:r,shippingData:s,cardEmbed:i}});return c&&c.remove(),l})}submitCvv(r){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(e,t){return f(this,null,function*(){switch(t){case"IFRAME":return g(this,I,V).call(this,e);case"POPUP_IFRAME":return g(this,L,j).call(this,e);case"REDIRECT":return g(this,A,W).call(this,e);default:return null}})}}I=new WeakSet,V=function(e){return f(this,null,function*(){const t=document.querySelector("#rendered-url-iframe-container");u.throwIf(!t,"Couldn't find an element with id rendered-url-iframe-container to render the iframe!");const r=document.createElement("iframe");r.src=e,r.style.setProperty("border","0","important"),r.style.setProperty("width","100%","important"),r.style.setProperty("height","100%","important"),t==null||t.replaceChildren(r),yield g(this,k,M).call(this),r.remove()})},L=new WeakSet,j=function(e){return f(this,null,function*(){const t=window.open(`${e}`,"","width=600,height=400,left=200,top=200");u.throwIf(!t,"Popup blocked by browser!"),yield g(this,k,M).call(this),t==null||t.close()})},A=new WeakSet,W=function(e){return f(this,null,function*(){window.open(e,"_blank")})},k=new WeakSet,M=function(){return f(this,null,function*(){const e=new N,t=r=>{var d,a,i,c;const{type:s,data:o}=r.data;switch(s){case"onComplete":(a=(d=this.options).onComplete)==null||a.call(d,P({type:this.options.type},o)),e.resolve(()=>null),window.removeEventListener("message",t);break;case"onFail":(c=(i=this.options).onFail)==null||c.call(i,P({type:this.options.type},o)),e.resolve(()=>null),window.removeEventListener("message",t);break;default:e.resolve(()=>null);break}};return window.addEventListener("message",t),e.promise})},S=new WeakSet,x=function(e){const t=r=>{e.forEach(s=>{s(r)})};window.addEventListener("message",t)},U=new WeakSet,D=function(e){const t=r=>{e.current&&e.current(r)};window.addEventListener("message",t)},C=new WeakSet,Y=function({container:e,elementType:t,elementOptions:r,styles:s}){var i,c;const o=T(),d=new URL(`${o}/vaultField/vaultField.html`);d.searchParams.set("host",btoa(window.location.origin)),d.searchParams.set("type",t),d.searchParams.set("placeholder",(i=r.placeholder)!=null?i:""),d.searchParams.set("color",(s==null?void 0:s.color)||"#000"),d.searchParams.set("placeholderColor",(s==null?void 0:s.placeholderColor)||"#ccc"),d.searchParams.set("backgroundColor",(s==null?void 0:s.backgroundColor)||"transparent");const a=document.createElement("iframe");a.src=d.toString(),a.style.height=(c=r.height)!=null?c:"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)},R=new WeakSet,B=function(e){const t=T(),r=Z(),s=new URL(`${t}/vaultSubmit/vaultSubmit.html`);s.searchParams.set("host",btoa(window.location.origin)),s.searchParams.set("vault_api_url",`${r}/api/v1/tokens/`),s.searchParams.set("access_token",e);const o=document.createElement("iframe");return o.id="moneyhash-submit-iframe",o.src=s.toString(),o.hidden=!0,document.body.appendChild(o),o};module.exports=se;
"use strict";var K=Object.defineProperty,G=Object.defineProperties;var Q=Object.getOwnPropertyDescriptors;var H=Object.getOwnPropertySymbols;var X=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable;var _=(s,e,t)=>e in s?K(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,b=(s,e)=>{for(var t in e||(e={}))X.call(e,t)&&_(s,t,e[t]);if(H)for(var t of H(e))Z.call(e,t)&&_(s,t,e[t]);return s},V=(s,e)=>G(s,Q(e));var u=(s,e,t)=>(_(s,typeof e!="symbol"?e+"":e,t),t),ee=(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)=>(ee(s,e,"access private method"),t);var w=(s,e,t)=>new Promise((n,r)=>{var o=d=>{try{a(t.next(d))}catch(l){r(l)}},i=d=>{try{a(t.throw(d))}catch(l){r(l)}},a=d=>d.done?n(d.value):Promise.resolve(d.value).then(o,i);a((t=t.apply(s,e)).next())});const g=require("./sdkEmbed-2ce660d7.cjs");function te(){return typeof window!="undefined"}const v=class{constructor(){te()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=g.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.1.0");const n=document.createElement("iframe");n.id="moneyhash-headless-sdk",n.src=t.toString(),n.hidden=!0,document.body.appendChild(n),v.messagingService=new g.MessagingService({target:n.contentWindow,targetOrigin:e}),v.isCommunicationReady=new Promise(r=>{var i;const o=a=>{var d;a.data.type==="headlessSDK:init"&&(r(),(d=v.messagingService)==null||d.removeListener(o))};(i=v.messagingService)==null||i.onReceive(o)})}request(n){return w(this,arguments,function*({api:e,payload:t}){return yield v.isCommunicationReady,new Promise((r,o)=>{var a,d;(a=v.messagingService)==null||a.send({type:e,data:t});const i=l=>{var h;const{type:c,data:m}=l.data;c===e&&(m.status==="resolved"?r(m.payload):o(m.payload),(h=v.messagingService)==null||h.removeListener(i))};(d=v.messagingService)==null||d.onReceive(i)})})}};let E=v;u(E,"messagingService",null),u(E,"isCommunicationReady");class T{constructor(){u(this,"promise");u(this,"resolve");u(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function re(){var e;return(e=window.MONEYHASH_VAULT_API_URL)!=null?e:"https://vault.moneyhash.io"}function j(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function N(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}function ne(s){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!s.includes(t))return t;return null}function ae(s){return(Array.isArray(s)?s.length:Object.keys(s).length)===0}function ie(s,e){return new Promise((t,n)=>{if(document.getElementById(e)){t(void 0);return}const o=document.createElement("script");o.src=s,o.id=e,o.addEventListener("load",()=>{t(void 0)}),o.addEventListener("error",()=>{n(new Error("Script failed to load"))}),document.body.appendChild(o)})}const W=new Set(["method","customerBalance","savedCard"]);var L,x,I,D,S,Y,k,M,A,B,C,z,U,O,R,J;class se{constructor(e){P(this,L);P(this,I);P(this,S);P(this,k);P(this,A);P(this,C);P(this,U);P(this,R);u(this,"options");u(this,"sdkApiHandler",new E);u(this,"sdkEmbed");u(this,"vaultSubmitListener",{current:null});u(this,"mountedCardElements",[]);this.options=e,this.sdkEmbed=new g.SDKEmbed(V(b({},e),{headless:!0})),y(this,C,z).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:n,metaData:r}){return g.throwIf(!W.has(t),`type must be a valid one (${[...W].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:n,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 g.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(l){return w(this,arguments,function*({intentId:e,currency:t,amount:n,countryCode:r,onCancel:o=()=>{},onError:i,onComplete:a,billingData:d={}}){if(yield ie("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:`${n}`}}),{state:m,intent:h}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(m==="INTENT_FORM"){if(ae(d))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:d}})}}catch(p){throw yield this.resetSelectedMethod(e),p}c.onvalidatemerchant=p=>{fetch(`${N()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:h.secret,validation_url:p.validationURL})}).then(f=>f.ok?f.json():Promise.reject()).then(f=>c.completeMerchantValidation(f)).catch(i)},c.onpaymentauthorized=p=>{fetch(`${N()}/api/v1/providers/applepay/token/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({token_data:p.payment.token,secret:h.secret})}).then(f=>f.ok?f.json():Promise.reject()).then(()=>{c.completePayment(ApplePaySession.STATUS_SUCCESS),a()}).catch(()=>{c.completePayment(ApplePaySession.STATUS_FAILURE),i()})},c.oncancel=o,c.begin()})}renderForm({selector:e,intentId:t}){return g.throwIf(!e,"selector is required for renderForm"),g.throwIf(!t,"intentId is required for renderForm"),this.sdkEmbed.render({selector:e,intentId:t})}setLocale(e){return this.sdkEmbed.setLocale(e)}removeEventListeners(){return this.sdkEmbed.abortService()}elements({styles:e,classNames:t}){const n=[];return y(this,A,B).call(this,n),{create:({elementType:r,elementOptions:o})=>{const i=new Map,a=document.querySelector(o.selector);g.throwIf(!a,`Couldn't find an element with selector ${o.selector}!`),a.classList.add("MoneyHashElement");const d=(t==null?void 0:t.focus)||"MoneyHashElement--focus",l=(t==null?void 0:t.error)||"MoneyHashElement--error";return n.push(c=>{var p,f,$,F,q;const{type:m,data:h}=c.data;if(m===`${r}@focus`){a.classList.add(d),(p=i.get(`${r}@focus`))==null||p();return}if(m===`${r}@blur`){a.classList.remove(d),(f=i.get(`${r}@blur`))==null||f();return}if(m===`${r}@error`){h.isValid?a.classList.remove(l):a.classList.add(l),($=i.get(`${r}@error`))==null||$(h);return}if(m===`${r}@changeInput`){(F=i.get(`${r}@changeInput`))==null||F();return}m===`${r}@cardNumberChange`&&((q=i.get(`${r}@cardNumberChange`))==null||q(h))}),{mount:()=>{this.mountedCardElements.push(r),y(this,U,O).call(this,{container:a,elementType:r,elementOptions:o,styles:b(b({},e),o.styles)})},on:(c,m)=>{i.set(`${r}@${c}`,m)},off:c=>i.delete(`${r}@${c}`)}}}}submitForm(o){return w(this,arguments,function*({intentId:e,accessToken:t,billingData:n,shippingData:r}){const i=ne(this.mountedCardElements);g.throwIf(!!i,`You must mount ${i} element!`);const a=new T;let d,l;t&&(this.vaultSubmitListener.current=m=>{const{type:h,data:p}=m.data;h==="vaultSubmit:success"&&a.resolve(p),h==="vaultSubmit:error"&&a.reject(p)},l=y(this,R,J).call(this,t),d=yield a.promise);const c=yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"CARD",lang:this.sdkEmbed.lang,billingData:n,shippingData:r,cardEmbed:d}});return l&&l.remove(),c})}submitCvv(n){return w(this,arguments,function*({intentId:e,cvv:t}){return this.sdkApiHandler.request({api:"sdk:submitCardCvv",payload:{intentId:e,cvv:t,lang:this.sdkEmbed.lang}})})}renderUrl(e,t,n){return w(this,null,function*(){switch(t){case"IFRAME":return y(this,L,x).call(this,e);case"POPUP_IFRAME":return y(this,I,D).call(this,e);case"REDIRECT":return y(this,S,Y).call(this,e,n);default:return null}})}}L=new WeakSet,x=function(e){return w(this,null,function*(){const t=document.querySelector("#rendered-url-iframe-container");g.throwIf(!t,"Couldn't find an element with id rendered-url-iframe-container to render the iframe!");const n=document.createElement("iframe");n.src=e,n.style.setProperty("border","0","important"),n.style.setProperty("width","100%","important"),n.style.setProperty("height","100%","important"),t==null||t.replaceChildren(n),yield y(this,k,M).call(this),n.remove()})},I=new WeakSet,D=function(e){return w(this,null,function*(){const t=window.open(`${e}`,"","width=600,height=400,left=200,top=200");g.throwIf(!t,"Popup blocked by browser!"),yield y(this,k,M).call(this),t==null||t.close()})},S=new WeakSet,Y=function(e,t){return w(this,null,function*(){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},k=new WeakSet,M=function(){return w(this,null,function*(){const e=new T,t=n=>{var i,a,d,l;const{type:r,data:o}=n.data;switch(r){case"onComplete":(a=(i=this.options).onComplete)==null||a.call(i,b({type:this.options.type},o)),e.resolve(()=>null),window.removeEventListener("message",t);break;case"onFail":(l=(d=this.options).onFail)==null||l.call(d,b({type:this.options.type},o)),e.resolve(()=>null),window.removeEventListener("message",t);break;default:e.resolve(()=>null);break}};return window.addEventListener("message",t),e.promise})},A=new WeakSet,B=function(e){const t=n=>{e.forEach(r=>{r(n)})};window.addEventListener("message",t)},C=new WeakSet,z=function(e){const t=n=>{e.current&&e.current(n)};window.addEventListener("message",t)},U=new WeakSet,O=function({container:e,elementType:t,elementOptions:n,styles:r}){var d,l,c,m;const o=j(),i=new URL(`${o}/vaultField/vaultField.html`);i.searchParams.set("host",btoa(window.location.origin)),i.searchParams.set("type",t),((d=n.validation)==null?void 0:d.required)!==void 0&&i.searchParams.set("required",`${(l=n.validation)==null?void 0:l.required}`),i.searchParams.set("placeholder",(c=n.placeholder)!=null?c:""),i.searchParams.set("lang",this.sdkEmbed.lang),i.searchParams.set("direction",(r==null?void 0:r.direction)||""),i.searchParams.set("color",(r==null?void 0: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("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)},R=new WeakSet,J=function(e){const t=j(),n=re(),r=new URL(`${t}/vaultSubmit/vaultSubmit.html`);r.searchParams.set("host",btoa(window.location.origin)),r.searchParams.set("vault_api_url",`${n}/api/v1/tokens/`),r.searchParams.set("access_token",e),r.searchParams.set("lang",this.sdkEmbed.lang);const o=document.createElement("iframe");return o.id="moneyhash-submit-iframe",o.src=r.toString(),o.hidden=!0,document.body.appendChild(o),o};module.exports=se;

@@ -64,5 +64,13 @@ export declare interface AbstractIntent {

first6Digits: number;
cardImageUrl: string;
brand: string;
brandIconUrl: string;
};
declare type CommonElementOptions = {
selector: string;
placeholder?: string;
styles?: ElementStyles;
classes?: Partial<Record<ElementClassNames, string>>;
};
export declare type CustomerBalances = [

@@ -80,14 +88,21 @@ {

on<T extends ElementEvents>(event: T, callback: (data: T extends "cardNumberChange" ? CardNumberChangeData : never) => void): void;
off: (event: ElementEvents) => boolean;
};
declare type ElementEvents = "focus" | "blur" | "changeInput" | "cardNumberChange";
declare type ElementClassNames = "focus" | "error";
declare type ElementEvents = "focus" | "blur" | "error" | "changeInput" | "cardNumberChange";
declare type ElementProps = {
elementType: ElementType;
elementOptions: {
selector: string;
height?: string;
placeholder?: string;
styles?: ElementStyles;
elementType: Exclude<ElementType, "cardHolderName">;
elementOptions: CommonElementOptions & {
validation?: never;
};
} | {
elementType: "cardHolderName";
elementOptions: CommonElementOptions & {
validation?: {
required?: boolean;
};
};
};

@@ -101,2 +116,3 @@

styles?: ElementStyles;
classNames?: Partial<Record<ElementClassNames, string>>;
};

@@ -108,2 +124,6 @@

placeholderColor?: string;
fontSize?: string;
padding?: string;
height?: string;
direction?: "ltr" | "rtl";
};

@@ -465,3 +485,3 @@

*/
setLocale(locale: string): Promise<void>;
setLocale(locale: SupportedLanguages): Promise<void>;
/**

@@ -484,3 +504,3 @@ * Cleanup all listeners set by the SDK

*/
elements({ styles }: ElementsProps): Elements;
elements({ styles, classNames }: ElementsProps): Elements;
/**

@@ -529,3 +549,4 @@ * Submits the form with the form fields data (card, billing, shipping)

*/
renderUrl(url: string, renderStrategy: "IFRAME" | "POPUP_IFRAME" | "REDIRECT"): Promise<void | null>;
renderUrl(url: string, renderStrategy: UrlRenderStrategy): Promise<void>;
renderUrl(url: string, renderStrategy: UrlRenderStrategy, options?: RenderOptions): Promise<void>;
}

@@ -605,2 +626,6 @@ export default MoneyHashHeadless;

export declare type RenderOptions = {
redirectToNewWindow: boolean;
};
declare interface SDKEmbedOptions<TType extends IntentType> {

@@ -607,0 +632,0 @@ /**

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

var O = Object.defineProperty, J = Object.defineProperties;
var z = Object.getOwnPropertyDescriptors;
var F = Object.getOwnPropertySymbols;
var K = Object.prototype.hasOwnProperty, G = Object.prototype.propertyIsEnumerable;
var _ = (n, e, t) => e in n ? O(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, P = (n, e) => {
var K = Object.defineProperty, G = Object.defineProperties;
var Q = Object.getOwnPropertyDescriptors;
var H = Object.getOwnPropertySymbols;
var X = Object.prototype.hasOwnProperty, Z = Object.prototype.propertyIsEnumerable;
var _ = (s, e, t) => e in s ? K(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, b = (s, e) => {
for (var t in e || (e = {}))
K.call(e, t) && _(n, t, e[t]);
if (F)
for (var t of F(e))
G.call(e, t) && _(n, t, e[t]);
return n;
}, $ = (n, e) => J(n, z(e));
var u = (n, e, t) => (_(n, typeof e != "symbol" ? e + "" : e, t), t), Q = (n, e, t) => {
if (!e.has(n))
X.call(e, t) && _(s, t, e[t]);
if (H)
for (var t of H(e))
Z.call(e, t) && _(s, t, e[t]);
return s;
}, V = (s, e) => G(s, Q(e));
var h = (s, e, t) => (_(s, typeof e != "symbol" ? e + "" : e, t), t), ee = (s, e, t) => {
if (!e.has(s))
throw TypeError("Cannot " + t);
};
var v = (n, e, t) => {
if (e.has(n))
var w = (s, e, t) => {
if (e.has(s))
throw TypeError("Cannot add the same private member more than once");
e instanceof WeakSet ? e.add(n) : e.set(n, t);
e instanceof WeakSet ? e.add(s) : e.set(s, t);
};
var y = (n, e, t) => (Q(n, e, "access private method"), t);
var g = (n, e, t) => new Promise((r, s) => {
var o = (i) => {
var f = (s, e, t) => (ee(s, e, "access private method"), t);
var y = (s, e, t) => new Promise((n, r) => {
var o = (d) => {
try {
a(t.next(i));
} catch (c) {
s(c);
a(t.next(d));
} catch (l) {
r(l);
}
}, d = (i) => {
}, i = (d) => {
try {
a(t.throw(i));
} catch (c) {
s(c);
a(t.throw(d));
} catch (l) {
r(l);
}
}, a = (i) => i.done ? r(i.value) : Promise.resolve(i.value).then(o, d);
a((t = t.apply(n, e)).next());
}, a = (d) => d.done ? n(d.value) : Promise.resolve(d.value).then(o, i);
a((t = t.apply(s, e)).next());
});
import { M as X, g as Z, S as ee, t as w } from "./sdkEmbed-13f4e15c.js";
function te() {
import { M as te, g as re, S as ne, t as P } from "./sdkEmbed-f5156d5c.js";
function ae() {
return typeof window != "undefined";
}
const f = class {
const v = class {
constructor() {
te() && this.initSDKCommunicationIframe();
ae() && this.initSDKCommunicationIframe();
}

@@ -50,34 +50,34 @@ initSDKCommunicationIframe() {

return;
const e = Z(), 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.0.6");
const r = document.createElement("iframe");
r.id = "moneyhash-headless-sdk", r.src = t.toString(), r.hidden = !0, document.body.appendChild(r), f.messagingService = new X({
target: r.contentWindow,
const e = re(), 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.1.0");
const n = document.createElement("iframe");
n.id = "moneyhash-headless-sdk", n.src = t.toString(), n.hidden = !0, document.body.appendChild(n), v.messagingService = new te({
target: n.contentWindow,
targetOrigin: e
}), f.isCommunicationReady = new Promise((s) => {
var d;
}), v.isCommunicationReady = new Promise((r) => {
var i;
const o = (a) => {
var i;
a.data.type === "headlessSDK:init" && (s(), (i = f.messagingService) == null || i.removeListener(o));
var d;
a.data.type === "headlessSDK:init" && (r(), (d = v.messagingService) == null || d.removeListener(o));
};
(d = f.messagingService) == null || d.onReceive(o);
(i = v.messagingService) == null || i.onReceive(o);
});
}
request(r) {
return g(this, arguments, function* ({
request(n) {
return y(this, arguments, function* ({
api: e,
payload: t
}) {
return yield f.isCommunicationReady, new Promise((s, o) => {
var a, i;
(a = f.messagingService) == null || a.send({
return yield v.isCommunicationReady, new Promise((r, o) => {
var a, d;
(a = v.messagingService) == null || a.send({
type: e,
data: t
});
const d = (c) => {
var m;
const { type: l, data: h } = c.data;
l === e && (h.status === "resolved" ? s(h.payload) : o(h.payload), (m = f.messagingService) == null || m.removeListener(d));
const i = (l) => {
var p;
const { type: c, data: m } = l.data;
c === e && (m.status === "resolved" ? r(m.payload) : o(m.payload), (p = v.messagingService) == null || p.removeListener(i));
};
(i = f.messagingService) == null || i.onReceive(d);
(d = v.messagingService) == null || d.onReceive(i);
});

@@ -87,9 +87,9 @@ });

};
let E = f;
u(E, "messagingService", null), u(E, "isCommunicationReady");
class N {
let E = v;
h(E, "messagingService", null), h(E, "isCommunicationReady");
class T {
constructor() {
u(this, "promise");
u(this, "resolve");
u(this, "reject");
h(this, "promise");
h(this, "resolve");
h(this, "reject");
this.promise = new Promise((e, t) => {

@@ -100,32 +100,15 @@ this.resolve = e, this.reject = t;

}
function re() {
function ie() {
var e;
return (e = window.MONEYHASH_VAULT_API_URL) != null ? e : "https://vault.moneyhash.io";
}
function T() {
function j() {
var e;
return (e = window.MONEYHASH_VAULT_INPUT_IFRAME_URL) != null ? e : "https://vault-form.moneyhash.io";
}
function se(n) {
return (Array.isArray(n) ? n.length : Object.keys(n).length) === 0;
}
function ne(n, e) {
return new Promise((t, r) => {
if (document.getElementById(e)) {
t(void 0);
return;
}
const o = document.createElement("script");
o.src = n, o.id = e, o.addEventListener("load", () => {
t(void 0);
}), o.addEventListener("error", () => {
r(new Error("Script failed to load"));
}), document.body.appendChild(o);
});
}
function H() {
function N() {
var e;
return (e = window.API_URL) != null ? e : "https://web.moneyhash.io";
}
function ae(n) {
function se(s) {
const e = [

@@ -138,7 +121,24 @@ "cardNumber",

for (const t of e)
if (!n.includes(t))
if (!s.includes(t))
return t;
return null;
}
const V = /* @__PURE__ */ new Set([
function oe(s) {
return (Array.isArray(s) ? s.length : Object.keys(s).length) === 0;
}
function de(s, e) {
return new Promise((t, n) => {
if (document.getElementById(e)) {
t(void 0);
return;
}
const o = document.createElement("script");
o.src = s, o.id = e, o.addEventListener("load", () => {
t(void 0);
}), o.addEventListener("error", () => {
n(new Error("Script failed to load"));
}), document.body.appendChild(o);
});
}
const W = /* @__PURE__ */ new Set([
"method",

@@ -148,21 +148,21 @@ "customerBalance",

]);
var L, j, S, q, A, W, k, M, I, x, U, D, C, Y, R, B;
class de {
var L, x, S, D, A, Y, k, M, I, B, C, z, U, O, R, J;
class me {
constructor(e) {
v(this, L);
v(this, S);
v(this, A);
v(this, k);
v(this, I);
v(this, U);
v(this, C);
v(this, R);
u(this, "options");
u(this, "sdkApiHandler", new E());
u(this, "sdkEmbed");
u(this, "vaultSubmitListener", {
w(this, L);
w(this, S);
w(this, A);
w(this, k);
w(this, I);
w(this, C);
w(this, U);
w(this, R);
h(this, "options");
h(this, "sdkApiHandler", new E());
h(this, "sdkEmbed");
h(this, "vaultSubmitListener", {
current: null
});
u(this, "mountedCardElements", []);
this.options = e, this.sdkEmbed = new ee($(P({}, e), { headless: !0 })), y(this, U, D).call(this, this.vaultSubmitListener);
h(this, "mountedCardElements", []);
this.options = e, this.sdkEmbed = new ne(V(b({}, e), { headless: !0 })), f(this, C, z).call(this, this.vaultSubmitListener);
}

@@ -258,8 +258,8 @@ /**

type: t,
id: r,
metaData: s
id: n,
metaData: r
}) {
return w(
!V.has(t),
`type must be a valid one (${[...V].join(
return P(
!W.has(t),
`type must be a valid one (${[...W].join(
" | "

@@ -273,5 +273,5 @@ )})`

intentId: e,
id: r,
id: n,
lang: this.sdkEmbed.lang,
metaData: s
metaData: r
}

@@ -322,3 +322,3 @@ });

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

@@ -373,15 +373,15 @@ "deleteCard is allowed only for payment intent!"

*/
payWithApplePay(c) {
return g(this, arguments, function* ({
payWithApplePay(l) {
return y(this, arguments, function* ({
intentId: e,
currency: t,
amount: r,
countryCode: s,
amount: n,
countryCode: r,
onCancel: o = () => {
},
onError: d,
onError: i,
onComplete: a,
billingData: i = {}
billingData: d = {}
}) {
if (yield ne(
if (yield de(
"https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js",

@@ -391,4 +391,4 @@ "moneyHash-apple-pay-sdk"

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

@@ -400,5 +400,5 @@ supportedNetworks: ["visa", "masterCard", "amex", "discover", "mada"],

type: "final",
amount: `${r}`
amount: `${n}`
}
}), { state: h, intent: m } = yield this.proceedWith({
}), { state: m, intent: p } = yield this.proceedWith({
intentId: e,

@@ -409,4 +409,4 @@ type: "method",

try {
if (h === "INTENT_FORM") {
if (se(i))
if (m === "INTENT_FORM") {
if (oe(d))
throw new Error(

@@ -421,11 +421,11 @@ "Billing data is missing while calling payWithApplePay"

lang: this.sdkEmbed.lang,
billingData: i
billingData: d
}
});
}
} catch (p) {
throw yield this.resetSelectedMethod(e), p;
} catch (u) {
throw yield this.resetSelectedMethod(e), u;
}
l.onvalidatemerchant = (p) => {
fetch(`${H()}/api/v1/providers/applepay/session/`, {
c.onvalidatemerchant = (u) => {
fetch(`${N()}/api/v1/providers/applepay/session/`, {
method: "post",

@@ -436,10 +436,10 @@ headers: {

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

@@ -450,11 +450,11 @@ headers: {

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

@@ -479,3 +479,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 P(!e, "selector is required for renderForm"), P(!t, "intentId is required for renderForm"), this.sdkEmbed.render({ selector: e, intentId: t });
}

@@ -516,5 +516,5 @@ /**

*/
elements({ styles: e }) {
const t = [];
return y(this, I, x).call(this, t), {
elements({ styles: e, classNames: t }) {
const n = [];
return f(this, I, B).call(this, n), {
/**

@@ -541,25 +541,44 @@ * Creates card field element

*/
create: ({ elementType: r, elementOptions: s }) => {
const o = /* @__PURE__ */ new Map(), d = document.querySelector(
s.selector
create: ({ elementType: r, elementOptions: o }) => {
const i = /* @__PURE__ */ new Map(), a = document.querySelector(
o.selector
);
return w(
!d,
`Couldn't find an element with selector ${s.selector}!`
), d.classList.add("MoneyHashElement"), t.push((a) => {
var l, h, m, p;
const { type: i, data: c } = a.data;
i === `${r}@focus` && (d.classList.add("MoneyHashElement--focus"), (l = o.get(`${r}@focus`)) == null || l()), i === `${r}@blur` && (d.classList.remove("MoneyHashElement--focus"), (h = o.get(`${r}@blur`)) == null || h()), i === `${r}@changeInput` && ((m = o.get(`${r}@changeInput`)) == null || m()), i === `${r}@cardNumberChange` && ((p = o.get(`${r}@cardNumberChange`)) == null || p(c));
P(
!a,
`Couldn't find an element with selector ${o.selector}!`
), a.classList.add("MoneyHashElement");
const d = (t == null ? void 0 : t.focus) || "MoneyHashElement--focus", l = (t == null ? void 0 : t.error) || "MoneyHashElement--error";
return n.push((c) => {
var u, g, $, F, q;
const { type: m, data: p } = c.data;
if (m === `${r}@focus`) {
a.classList.add(d), (u = i.get(`${r}@focus`)) == null || u();
return;
}
if (m === `${r}@blur`) {
a.classList.remove(d), (g = i.get(`${r}@blur`)) == null || g();
return;
}
if (m === `${r}@error`) {
p.isValid ? a.classList.remove(l) : a.classList.add(l), ($ = i.get(`${r}@error`)) == null || $(p);
return;
}
if (m === `${r}@changeInput`) {
(F = i.get(`${r}@changeInput`)) == null || F();
return;
}
m === `${r}@cardNumberChange` && ((q = i.get(`${r}@cardNumberChange`)) == null || q(p));
}), {
mount: () => {
this.mountedCardElements.push(r), y(this, C, Y).call(this, {
container: d,
this.mountedCardElements.push(r), f(this, U, O).call(this, {
container: a,
elementType: r,
elementOptions: s,
styles: P(P({}, e), s.styles)
elementOptions: o,
styles: b(b({}, e), o.styles)
});
},
on: (a, i) => {
o.set(`${r}@${a}`, i);
}
on: (c, m) => {
i.set(`${r}@${c}`, m);
},
off: (c) => i.delete(`${r}@${c}`)
};

@@ -584,20 +603,20 @@ }

submitForm(o) {
return g(this, arguments, function* ({
return y(this, arguments, function* ({
intentId: e,
accessToken: t,
billingData: r,
shippingData: s
billingData: n,
shippingData: r
}) {
const d = ae(this.mountedCardElements);
w(
!!d,
`You must mount ${d} element!`
const i = se(this.mountedCardElements);
P(
!!i,
`You must mount ${i} element!`
);
const a = new N();
let i, c;
t && (this.vaultSubmitListener.current = (h) => {
const { type: m, data: p } = h.data;
m === "vaultSubmit:success" && a.resolve(p), m === "vaultSubmit:error" && a.reject(p);
}, c = y(this, R, B).call(this, t), i = yield a.promise);
const l = yield this.sdkApiHandler.request({
const a = new T();
let d, l;
t && (this.vaultSubmitListener.current = (m) => {
const { type: p, data: u } = m.data;
p === "vaultSubmit:success" && a.resolve(u), p === "vaultSubmit:error" && a.reject(u);
}, l = f(this, R, J).call(this, t), d = yield a.promise);
const c = yield this.sdkApiHandler.request({
api: "sdk:submitNativeForm",

@@ -608,8 +627,8 @@ payload: {

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

@@ -627,4 +646,4 @@ }

*/
submitCvv(r) {
return g(this, arguments, function* ({
submitCvv(n) {
return y(this, arguments, function* ({
intentId: e,

@@ -643,20 +662,11 @@ cvv: t

}
/**
* Render the received url in an iframe, popup iframe or redirect
*
* @example
* ```
* moneyHash.renderUrl('<url>', 'IFRAME');
* ```
*
*/
renderUrl(e, t) {
return g(this, null, function* () {
renderUrl(e, t, n) {
return y(this, null, function* () {
switch (t) {
case "IFRAME":
return y(this, L, j).call(this, e);
return f(this, L, x).call(this, e);
case "POPUP_IFRAME":
return y(this, S, q).call(this, e);
return f(this, S, D).call(this, e);
case "REDIRECT":
return y(this, A, W).call(this, e);
return f(this, A, Y).call(this, e, n);
default:

@@ -668,14 +678,14 @@ return null;

}
L = new WeakSet(), j = function(e) {
return g(this, null, function* () {
L = new WeakSet(), x = function(e) {
return y(this, null, function* () {
const t = document.querySelector("#rendered-url-iframe-container");
w(
P(
!t,
"Couldn't find an element with id rendered-url-iframe-container to render the iframe!"
);
const r = document.createElement("iframe");
r.src = e, r.style.setProperty("border", "0", "important"), r.style.setProperty("width", "100%", "important"), r.style.setProperty("height", "100%", "important"), t == null || t.replaceChildren(r), yield y(this, k, M).call(this), r.remove();
const n = document.createElement("iframe");
n.src = e, n.style.setProperty("border", "0", "important"), n.style.setProperty("width", "100%", "important"), n.style.setProperty("height", "100%", "important"), t == null || t.replaceChildren(n), yield f(this, k, M).call(this), n.remove();
});
}, S = new WeakSet(), q = function(e) {
return g(this, null, function* () {
}, S = new WeakSet(), D = function(e) {
return y(this, null, function* () {
const t = window.open(

@@ -686,16 +696,20 @@ `${e}`,

);
w(!t, "Popup blocked by browser!"), yield y(this, k, M).call(this), t == null || t.close();
P(!t, "Popup blocked by browser!"), yield f(this, k, M).call(this), t == null || t.close();
});
}, A = new WeakSet(), W = function(e) {
return g(this, null, function* () {
}, A = new WeakSet(), Y = function(e, t) {
return y(this, null, function* () {
if (!t || !t.redirectToNewWindow) {
window.location.href = e;
return;
}
window.open(e, "_blank");
});
}, k = new WeakSet(), M = function() {
return g(this, null, function* () {
const e = new N(), t = (r) => {
var d, a, i, c;
const { type: s, data: o } = r.data;
switch (s) {
return y(this, null, function* () {
const e = new T(), t = (n) => {
var i, a, d, l;
const { type: r, data: o } = n.data;
switch (r) {
case "onComplete":
(a = (d = this.options).onComplete) == null || a.call(d, P({
(a = (i = this.options).onComplete) == null || a.call(i, b({
type: this.options.type

@@ -705,3 +719,3 @@ }, o)), e.resolve(() => null), window.removeEventListener("message", t);

case "onFail":
(c = (i = this.options).onFail) == null || c.call(i, P({
(l = (d = this.options).onFail) == null || l.call(d, b({
type: this.options.type

@@ -717,41 +731,44 @@ }, o)), e.resolve(() => null), window.removeEventListener("message", t);

});
}, I = new WeakSet(), x = function(e) {
const t = (r) => {
e.forEach((s) => {
s(r);
}, I = new WeakSet(), B = function(e) {
const t = (n) => {
e.forEach((r) => {
r(n);
});
};
window.addEventListener("message", t);
}, U = new WeakSet(), D = function(e) {
const t = (r) => {
e.current && e.current(r);
}, C = new WeakSet(), z = function(e) {
const t = (n) => {
e.current && e.current(n);
};
window.addEventListener("message", t);
}, C = new WeakSet(), Y = function({
}, U = new WeakSet(), O = function({
container: e,
elementType: t,
elementOptions: r,
styles: s
elementOptions: n,
styles: r
}) {
var i, c;
const o = T(), d = new URL(`${o}/vaultField/vaultField.html`);
d.searchParams.set("host", btoa(window.location.origin)), d.searchParams.set("type", t), d.searchParams.set("placeholder", (i = r.placeholder) != null ? i : ""), d.searchParams.set("color", (s == null ? void 0 : s.color) || "#000"), d.searchParams.set(
var d, l, c, m;
const o = j(), i = new URL(`${o}/vaultField/vaultField.html`);
i.searchParams.set("host", btoa(window.location.origin)), i.searchParams.set("type", t), ((d = n.validation) == null ? void 0 : d.required) !== void 0 && i.searchParams.set(
"required",
`${(l = n.validation) == null ? void 0 : l.required}`
), i.searchParams.set("placeholder", (c = n.placeholder) != null ? c : ""), i.searchParams.set("lang", this.sdkEmbed.lang), i.searchParams.set("direction", (r == null ? void 0 : r.direction) || ""), i.searchParams.set("color", (r == null ? void 0 : r.color) || "#000"), i.searchParams.set(
"placeholderColor",
(s == null ? void 0 : s.placeholderColor) || "#ccc"
), d.searchParams.set(
(r == null ? void 0 : r.placeholderColor) || "#ccc"
), i.searchParams.set(
"backgroundColor",
(s == null ? void 0 : s.backgroundColor) || "transparent"
);
(r == null ? void 0 : r.backgroundColor) || "transparent"
), i.searchParams.set("fontSize", (r == null ? void 0 : r.fontSize) || ""), i.searchParams.set("padding", (r == null ? void 0 : r.padding) || "");
const a = document.createElement("iframe");
a.src = d.toString(), a.style.height = (c = r.height) != null ? c : "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);
}, R = new WeakSet(), B = function(e) {
const t = T(), r = re(), s = new URL(
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);
}, R = new WeakSet(), J = function(e) {
const t = j(), n = ie(), r = new URL(
`${t}/vaultSubmit/vaultSubmit.html`
);
s.searchParams.set("host", btoa(window.location.origin)), s.searchParams.set("vault_api_url", `${r}/api/v1/tokens/`), s.searchParams.set("access_token", e);
r.searchParams.set("host", btoa(window.location.origin)), r.searchParams.set("vault_api_url", `${n}/api/v1/tokens/`), r.searchParams.set("access_token", e), r.searchParams.set("lang", this.sdkEmbed.lang);
const o = document.createElement("iframe");
return o.id = "moneyhash-submit-iframe", o.src = s.toString(), o.hidden = !0, document.body.appendChild(o), o;
return o.id = "moneyhash-submit-iframe", o.src = r.toString(), o.hidden = !0, document.body.appendChild(o), o;
};
export {
de as default
me as default
};

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

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

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

"use strict";var o=Object.defineProperty;var i=(s,e,r)=>e in s?o(s,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):s[e]=r;var t=(s,e,r)=>(i(s,typeof e!="symbol"?e+"":e,r),r);const d=require("./sdkEmbed-955a36b1.cjs");class n{constructor(e){t(this,"options");t(this,"sdkEmbed");this.options=e,this.sdkEmbed=new d.SDKEmbed(e)}start({selector:e,intentId:r}){return d.throwIf(!e,"selector is required for start"),d.throwIf(!r,"intentId is required for start"),this.sdkEmbed.render({selector:e,intentId:r})}setLocale(e){return this.sdkEmbed.setLocale(e)}removeEventListeners(){return this.sdkEmbed.abortService()}}module.exports=n;
"use strict";var o=Object.defineProperty;var i=(s,e,r)=>e in s?o(s,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):s[e]=r;var t=(s,e,r)=>(i(s,typeof e!="symbol"?e+"":e,r),r);const d=require("./sdkEmbed-2ce660d7.cjs");class n{constructor(e){t(this,"options");t(this,"sdkEmbed");this.options=e,this.sdkEmbed=new d.SDKEmbed(e)}start({selector:e,intentId:r}){return d.throwIf(!e,"selector is required for start"),d.throwIf(!r,"intentId is required for start"),this.sdkEmbed.render({selector:e,intentId:r})}setLocale(e){return this.sdkEmbed.setLocale(e)}removeEventListeners(){return this.sdkEmbed.abortService()}}module.exports=n;

@@ -169,3 +169,3 @@ export declare interface AbstractIntent {

*/
setLocale(locale: string): Promise<void>;
setLocale(locale: SupportedLanguages): Promise<void>;
/**

@@ -172,0 +172,0 @@ * Cleanup all listeners set by the SDK

var o = Object.defineProperty;
var i = (s, e, r) => e in s ? o(s, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : s[e] = r;
var t = (s, e, r) => (i(s, typeof e != "symbol" ? e + "" : e, r), r);
import { S as a, t as d } from "./sdkEmbed-13f4e15c.js";
import { S as a, t as d } from "./sdkEmbed-f5156d5c.js";
class b {

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

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

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