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
63
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.2.2 to 1.3.0

dist/warnIf-a53a88a2.cjs

2

dist/headless.cjs.js

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

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

@@ -134,9 +134,20 @@ export declare interface AbstractIntent {

classes?: Partial<Record<ElementClassNames, string>>;
/**
* absolute URL pointing to a CSS file with @font-face definitions,
* @example "https://fonts.googleapis.com/css?family=Open+Sans&display=swap"
*/
fontSourceCss?: string;
};
declare type ElementStyles = {
color?: string;
color?: VariantStyle;
backgroundColor?: string;
placeholderColor?: string;
fontSize?: string;
fontFamily?: string;
/**
* @default "normal"
*/
fontStyle?: "normal" | "italic" | "oblique";
fontWeight?: number | string;
padding?: string;

@@ -569,3 +580,3 @@ height?: string;

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

@@ -766,2 +777,5 @@ * Submits the form with the form fields data (card, billing, shipping)

status: TransactionStatus;
responseCode: string;
responseMessage: string;
localizedResponseMessage: string;
operations: TransactionOperation[];

@@ -824,4 +838,9 @@ createdDate: string;

declare type VariantStyle = string | {
base: string;
error?: string;
};
export declare type VoidOperationStatus = "pending" | "failed" | "successful";
export { }

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

var se = Object.defineProperty, ne = Object.defineProperties;
var ie = Object.getOwnPropertyDescriptors;
var ie = Object.defineProperty, se = Object.defineProperties;
var oe = Object.getOwnPropertyDescriptors;
var z = Object.getOwnPropertySymbols;
var oe = Object.prototype.hasOwnProperty, de = Object.prototype.propertyIsEnumerable;
var V = (i, e, t) => e in i ? se(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, P = (i, e) => {
var de = Object.prototype.hasOwnProperty, ce = Object.prototype.propertyIsEnumerable;
var q = (s, e, t) => e in s ? ie(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, E = (s, e) => {
for (var t in e || (e = {}))
oe.call(e, t) && V(i, t, e[t]);
de.call(e, t) && q(s, t, e[t]);
if (z)
for (var t of z(e))
de.call(e, t) && V(i, t, e[t]);
return i;
}, O = (i, e) => ne(i, ie(e));
var h = (i, e, t) => (V(i, typeof e != "symbol" ? e + "" : e, t), t), ce = (i, e, t) => {
if (!e.has(i))
ce.call(e, t) && q(s, t, e[t]);
return s;
}, J = (s, e) => se(s, oe(e));
var g = (s, e, t) => (q(s, typeof e != "symbol" ? e + "" : e, t), t), le = (s, e, t) => {
if (!e.has(s))
throw TypeError("Cannot " + t);
};
var w = (i, e, t) => {
if (e.has(i))
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(i) : e.set(i, t);
e instanceof WeakSet ? e.add(s) : e.set(s, t);
};
var f = (i, e, t) => (ce(i, e, "access private method"), t);
var y = (i, e, t) => new Promise((s, a) => {
var d = (o) => {
var f = (s, e, t) => (le(s, e, "access private method"), t);
var v = (s, e, t) => new Promise((n, a) => {
var o = (r) => {
try {
r(t.next(o));
i(t.next(r));
} catch (l) {
a(l);
}
}, n = (o) => {
}, d = (r) => {
try {
r(t.throw(o));
i(t.throw(r));
} catch (l) {
a(l);
}
}, r = (o) => o.done ? s(o.value) : Promise.resolve(o.value).then(d, n);
r((t = t.apply(i, e)).next());
}, i = (r) => r.done ? n(r.value) : Promise.resolve(r.value).then(o, d);
i((t = t.apply(s, e)).next());
});
import { M as le, g as me, S as pe, t as E, w as ue, s as N } from "./warnIf-a6422dbb.js";
function he() {
import { M as me, g as he, S as pe, t as w, w as ue, s as N } from "./warnIf-f9638a41.js";
function ge() {
return typeof window != "undefined";
}
const v = class {
const y = class {
constructor() {
he() && this.initSDKCommunicationIframe();
ge() && this.initSDKCommunicationIframe();
}

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

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

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

};
let A = v;
h(A, "messagingService", null), h(A, "isCommunicationReady");
class J {
let L = y;
g(L, "messagingService", null), g(L, "isCommunicationReady");
class K {
constructor() {
h(this, "promise");
h(this, "resolve");
h(this, "reject");
g(this, "promise");
g(this, "resolve");
g(this, "reject");
this.promise = new Promise((e, t) => {

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

}
function ge() {
function fe() {
var e;
return (e = window.MONEYHASH_VAULT_API_URL) != null ? e : "https://vault.moneyhash.io";
}
function q() {
function V() {
var e;
return (e = window.MONEYHASH_VAULT_INPUT_IFRAME_URL) != null ? e : "https://vault-form.moneyhash.io";
}
function K() {
function G() {
var e;
return (e = window.API_URL) != null ? e : "https://web.moneyhash.io";
}
function fe(i) {
function ve(s) {
const e = [

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

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

@@ -135,11 +135,11 @@ t(void 0);

}
const d = document.createElement("script");
d.src = i, d.id = e, d.addEventListener("load", () => {
const o = document.createElement("script");
o.src = s, o.id = e, o.addEventListener("load", () => {
t(void 0);
}), d.addEventListener("error", () => {
s(new Error("Script failed to load"));
}), document.body.appendChild(d);
}), o.addEventListener("error", () => {
n(new Error("Script failed to load"));
}), document.body.appendChild(o);
});
}
const G = /* @__PURE__ */ new Set([
const Q = /* @__PURE__ */ new Set([
"method",

@@ -149,21 +149,21 @@ "customerBalance",

]);
var I, Q, C, X, U, Z, S, H, R, ee, _, te, M, re, $, ae;
class Ee {
var I, X, C, Z, U, ee, A, H, R, te, _, re, M, ae, $, ne;
class ke {
constructor(e) {
w(this, I);
w(this, C);
w(this, U);
w(this, S);
w(this, R);
w(this, _);
w(this, M);
w(this, $);
h(this, "options");
h(this, "sdkApiHandler", new A());
h(this, "sdkEmbed");
h(this, "vaultSubmitListener", {
P(this, I);
P(this, C);
P(this, U);
P(this, A);
P(this, R);
P(this, _);
P(this, M);
P(this, $);
g(this, "options");
g(this, "sdkApiHandler", new L());
g(this, "sdkEmbed");
g(this, "vaultSubmitListener", {
current: null
});
h(this, "mountedCardElements", []);
this.options = e, this.sdkEmbed = new pe(O(P({}, e), { headless: !0 })), f(this, _, te).call(this, this.vaultSubmitListener);
g(this, "mountedCardElements", []);
this.options = e, this.sdkEmbed = new pe(J(E({}, e), { headless: !0 })), f(this, _, re).call(this, this.vaultSubmitListener);
}

@@ -259,8 +259,8 @@ /**

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

@@ -274,3 +274,3 @@ )})`

intentId: e,
id: s,
id: n,
lang: this.sdkEmbed.lang,

@@ -323,3 +323,3 @@ metaData: a

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

@@ -375,14 +375,14 @@ "deleteCard is allowed only for payment intent!"

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

@@ -400,5 +400,5 @@ "moneyHash-apple-pay-sdk"

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

@@ -410,3 +410,3 @@ type: "method",

if (m === "INTENT_FORM") {
if (ye(o))
if (we(r))
throw new Error(

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

lang: this.sdkEmbed.lang,
billingData: o
billingData: r
}

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

c.onvalidatemerchant = (u) => {
fetch(`${K()}/api/v1/providers/applepay/session/`, {
fetch(`${G()}/api/v1/providers/applepay/session/`, {
method: "post",

@@ -437,3 +437,3 @@ headers: {

body: JSON.stringify({
secret: g.secret,
secret: h.secret,
validation_url: u.validationURL

@@ -443,5 +443,5 @@ })

(p) => c.completeMerchantValidation(p)
).catch(n);
).catch(d);
}, c.onpaymentauthorized = (u) => {
fetch(`${K()}/api/v1/providers/applepay/token/`, {
fetch(`${G()}/api/v1/providers/applepay/token/`, {
method: "post",

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

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

@@ -481,3 +481,3 @@ }

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

@@ -532,3 +532,3 @@ /**

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

@@ -558,3 +558,5 @@ payload: {

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

@@ -580,6 +582,6 @@ payload: {

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

@@ -606,56 +608,57 @@ * Creates card field element

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

@@ -678,21 +681,21 @@ };

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

@@ -704,3 +707,3 @@ api: "sdk:submitNativeForm",

lang: this.sdkEmbed.lang,
billingData: s,
billingData: n,
shippingData: a,

@@ -723,4 +726,4 @@ cardEmbed: l

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

@@ -739,11 +742,11 @@ cvv: t

}
renderUrl(e, t, s) {
return y(this, null, function* () {
renderUrl(e, t, n) {
return v(this, null, function* () {
switch (t) {
case "IFRAME":
return f(this, I, Q).call(this, e);
return f(this, I, X).call(this, e);
case "POPUP_IFRAME":
return f(this, C, X).call(this, e);
return f(this, C, Z).call(this, e);
case "REDIRECT":
return f(this, U, Z).call(this, e, s);
return f(this, U, ee).call(this, e, n);
default:

@@ -755,14 +758,14 @@ return null;

}
I = new WeakSet(), Q = function(e) {
return y(this, null, function* () {
I = new WeakSet(), X = function(e) {
return v(this, null, function* () {
const t = document.querySelector("#rendered-url-iframe-container");
E(
w(
!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 f(this, S, H).call(this), s.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, A, H).call(this), n.remove();
});
}, C = new WeakSet(), X = function(e) {
return y(this, null, function* () {
}, C = new WeakSet(), Z = function(e) {
return v(this, null, function* () {
const t = window.open(

@@ -773,6 +776,6 @@ `${e}`,

);
E(!t, "Popup blocked by browser!"), yield f(this, S, H).call(this), t == null || t.close();
w(!t, "Popup blocked by browser!"), yield f(this, A, H).call(this), t == null || t.close();
});
}, U = new WeakSet(), Z = function(e, t) {
return y(this, null, function* () {
}, U = new WeakSet(), ee = function(e, t) {
return v(this, null, function* () {
if (!t || !t.redirectToNewWindow) {

@@ -784,17 +787,17 @@ window.location.href = e;

});
}, S = new WeakSet(), H = function() {
return y(this, null, function* () {
const e = new J(), t = (s) => {
var n, r, o, l;
const { type: a, data: d } = s.data;
}, A = new WeakSet(), H = function() {
return v(this, null, function* () {
const e = new K(), t = (n) => {
var d, i, r, l;
const { type: a, data: o } = n.data;
switch (a) {
case "onComplete":
(r = (n = this.options).onComplete) == null || r.call(n, P({
(i = (d = this.options).onComplete) == null || i.call(d, E({
type: this.options.type
}, d)), e.resolve(() => null), window.removeEventListener("message", t);
}, o)), e.resolve(() => null), window.removeEventListener("message", t);
break;
case "onFail":
(l = (o = this.options).onFail) == null || l.call(o, P({
(l = (r = this.options).onFail) == null || l.call(r, E({
type: this.options.type
}, d)), e.resolve(() => null), window.removeEventListener("message", t);
}, o)), e.resolve(() => null), window.removeEventListener("message", t);
break;

@@ -808,47 +811,51 @@ default:

});
}, R = new WeakSet(), ee = function(e) {
const t = (s) => {
s.origin === q() && e.forEach((a) => {
a(s);
}, R = new WeakSet(), te = function(e) {
const t = (n) => {
n.origin === V() && e.forEach((a) => {
a(n);
});
};
window.addEventListener("message", t);
}, _ = new WeakSet(), te = function(e) {
const t = (s) => {
e.current && e.current(s);
}, _ = new WeakSet(), re = function(e) {
const t = (n) => {
e.current && e.current(n);
};
window.addEventListener("message", t);
}, M = new WeakSet(), re = function({
}, M = new WeakSet(), ae = function({
container: e,
elementType: t,
elementOptions: s,
styles: a
elementOptions: n,
styles: a,
fontSourceCss: o
}) {
var o, l, c, m;
const d = q(), n = new URL(`${d}/vaultField/vaultField.html`);
n.searchParams.set("host", btoa(window.location.origin)), n.searchParams.set("type", t), ((o = s.validation) == null ? void 0 : o.required) !== void 0 && n.searchParams.set(
var l, c, m, h;
const d = V(), i = new URL(`${d}/vaultField/vaultField.html`);
o && i.searchParams.set("fontSourceCss", o), i.searchParams.set("host", btoa(window.location.origin)), i.searchParams.set("type", t), ((l = n.validation) == null ? void 0 : l.required) !== void 0 && i.searchParams.set(
"required",
`${(l = s.validation) == null ? void 0 : l.required}`
), n.searchParams.set("placeholder", (c = s.placeholder) != null ? c : ""), n.searchParams.set("lang", this.sdkEmbed.lang), n.searchParams.set("direction", (a == null ? void 0 : a.direction) || ""), n.searchParams.set("color", (a == null ? void 0 : a.color) || "#000"), n.searchParams.set(
`${(c = n.validation) == null ? void 0 : c.required}`
), i.searchParams.set("placeholder", (m = n.placeholder) != null ? m : ""), i.searchParams.set("lang", this.sdkEmbed.lang), i.searchParams.set("direction", (a == null ? void 0 : a.direction) || ""), i.searchParams.set(
"color",
a != null && a.color ? JSON.stringify(a.color) : "#000"
), i.searchParams.set(
"placeholderColor",
(a == null ? void 0 : a.placeholderColor) || "#ccc"
), n.searchParams.set(
), i.searchParams.set(
"backgroundColor",
(a == null ? void 0 : a.backgroundColor) || "transparent"
), n.searchParams.set("fontSize", (a == null ? void 0 : a.fontSize) || ""), n.searchParams.set("padding", (a == null ? void 0 : a.padding) || "");
), i.searchParams.set("fontSize", (a == null ? void 0 : a.fontSize) || ""), i.searchParams.set("fontFamily", (a == null ? void 0 : a.fontFamily) || ""), i.searchParams.set("fontWeight", `${a == null ? void 0 : a.fontWeight}`), i.searchParams.set("fontStyle", (a == null ? void 0 : a.fontStyle) || ""), i.searchParams.set("padding", (a == null ? void 0 : a.padding) || "");
const r = document.createElement("iframe");
r.src = n.toString(), r.style.height = (m = a == null ? void 0 : a.height) != null ? m : "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);
}, $ = new WeakSet(), ae = function({
r.src = i.toString(), r.style.height = (h = a == null ? void 0 : a.height) != null ? h : "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);
}, $ = new WeakSet(), ne = function({
accessToken: e,
saveCard: t
}) {
const s = q(), a = ge(), d = new URL(
`${s}/vaultSubmit/vaultSubmit.html`
const n = V(), a = fe(), o = new URL(
`${n}/vaultSubmit/vaultSubmit.html`
);
d.searchParams.set("host", btoa(window.location.origin)), d.searchParams.set("vault_api_url", `${a}/api/v1/tokens/`), d.searchParams.set("access_token", e), d.searchParams.set("lang", this.sdkEmbed.lang), t !== void 0 && d.searchParams.set("save_card", `${t}`);
const n = document.createElement("iframe");
return n.id = "moneyhash-submit-iframe", n.src = d.toString(), n.hidden = !0, document.body.appendChild(n), n;
o.searchParams.set("host", btoa(window.location.origin)), o.searchParams.set("vault_api_url", `${a}/api/v1/tokens/`), o.searchParams.set("access_token", e), o.searchParams.set("lang", this.sdkEmbed.lang), t !== void 0 && o.searchParams.set("save_card", `${t}`);
const d = document.createElement("iframe");
return d.id = "moneyhash-submit-iframe", d.src = o.toString(), d.hidden = !0, document.body.appendChild(d), d;
};
export {
Ee as default
ke as default
};

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

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

@@ -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-81c25f18.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-a53a88a2.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;

@@ -334,2 +334,5 @@ export declare interface AbstractIntent {

status: TransactionStatus;
responseCode: string;
responseMessage: string;
localizedResponseMessage: string;
operations: TransactionOperation[];

@@ -336,0 +339,0 @@ createdDate: string;

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-a6422dbb.js";
import { S as i, t as d, w as u, s as a } from "./warnIf-f9638a41.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.2.2");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.3.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});
{
"name": "@moneyhash/js-sdk",
"version": "1.2.2",
"version": "1.3.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