@moneyhash/js-sdk
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -1,1 +0,1 @@ | ||
"use strict";var K=Object.defineProperty,G=Object.defineProperties;var Q=Object.getOwnPropertyDescriptors;var H=Object.getOwnPropertySymbols;var X=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable;var _=(s,e,t)=>e in s?K(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,b=(s,e)=>{for(var t in e||(e={}))X.call(e,t)&&_(s,t,e[t]);if(H)for(var t of H(e))Z.call(e,t)&&_(s,t,e[t]);return s},V=(s,e)=>G(s,Q(e));var u=(s,e,t)=>(_(s,typeof e!="symbol"?e+"":e,t),t),ee=(s,e,t)=>{if(!e.has(s))throw TypeError("Cannot "+t)};var P=(s,e,t)=>{if(e.has(s))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(s):e.set(s,t)};var y=(s,e,t)=>(ee(s,e,"access private method"),t);var w=(s,e,t)=>new Promise((n,r)=>{var o=d=>{try{a(t.next(d))}catch(l){r(l)}},i=d=>{try{a(t.throw(d))}catch(l){r(l)}},a=d=>d.done?n(d.value):Promise.resolve(d.value).then(o,i);a((t=t.apply(s,e)).next())});const g=require("./sdkEmbed-2ce660d7.cjs");function te(){return typeof window!="undefined"}const v=class{constructor(){te()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=g.getIframeUrl(),t=new URL(`${e}/embed/headless-sdk`);t.searchParams.set("sdk","true"),t.searchParams.set("parent",window.location.origin),t.searchParams.set("version","js@1.1.0");const n=document.createElement("iframe");n.id="moneyhash-headless-sdk",n.src=t.toString(),n.hidden=!0,document.body.appendChild(n),v.messagingService=new g.MessagingService({target:n.contentWindow,targetOrigin:e}),v.isCommunicationReady=new Promise(r=>{var i;const o=a=>{var d;a.data.type==="headlessSDK:init"&&(r(),(d=v.messagingService)==null||d.removeListener(o))};(i=v.messagingService)==null||i.onReceive(o)})}request(n){return w(this,arguments,function*({api:e,payload:t}){return yield v.isCommunicationReady,new Promise((r,o)=>{var a,d;(a=v.messagingService)==null||a.send({type:e,data:t});const i=l=>{var h;const{type:c,data:m}=l.data;c===e&&(m.status==="resolved"?r(m.payload):o(m.payload),(h=v.messagingService)==null||h.removeListener(i))};(d=v.messagingService)==null||d.onReceive(i)})})}};let E=v;u(E,"messagingService",null),u(E,"isCommunicationReady");class T{constructor(){u(this,"promise");u(this,"resolve");u(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function re(){var e;return(e=window.MONEYHASH_VAULT_API_URL)!=null?e:"https://vault.moneyhash.io"}function j(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function N(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}function ne(s){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!s.includes(t))return t;return null}function ae(s){return(Array.isArray(s)?s.length:Object.keys(s).length)===0}function ie(s,e){return new Promise((t,n)=>{if(document.getElementById(e)){t(void 0);return}const o=document.createElement("script");o.src=s,o.id=e,o.addEventListener("load",()=>{t(void 0)}),o.addEventListener("error",()=>{n(new Error("Script failed to load"))}),document.body.appendChild(o)})}const W=new Set(["method","customerBalance","savedCard"]);var L,x,I,D,S,Y,k,M,A,B,C,z,U,O,R,J;class se{constructor(e){P(this,L);P(this,I);P(this,S);P(this,k);P(this,A);P(this,C);P(this,U);P(this,R);u(this,"options");u(this,"sdkApiHandler",new E);u(this,"sdkEmbed");u(this,"vaultSubmitListener",{current:null});u(this,"mountedCardElements",[]);this.options=e,this.sdkEmbed=new g.SDKEmbed(V(b({},e),{headless:!0})),y(this,C,z).call(this,this.vaultSubmitListener)}getIntentDetails(e){return this.sdkApiHandler.request({api:"sdk:getIntentDetails",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}getIntentMethods(e){return this.sdkApiHandler.request({api:"sdk:getIntentMethods",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}proceedWith({intentId:e,type:t,id:n,metaData:r}){return g.throwIf(!W.has(t),`type must be a valid one (${[...W].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:n,lang:this.sdkEmbed.lang,metaData:r}})}resetSelectedMethod(e){return this.sdkApiHandler.request({api:"sdk:resetSelectedMethod",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}deleteCard({cardId:e,intentSecret:t}){return g.throwIf(this.options.type==="payout","deleteCard is allowed only for payment intent!"),this.sdkApiHandler.request({api:"sdk:deleteCard",payload:{cardId:e,intentSecret:t,lang:this.sdkEmbed.lang}})}payWithApplePay(l){return w(this,arguments,function*({intentId:e,currency:t,amount:n,countryCode:r,onCancel:o=()=>{},onError:i,onComplete:a,billingData:d={}}){if(yield ie("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)return;const c=new ApplePaySession(3,{countryCode:r,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${n}`}}),{state:m,intent:h}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(m==="INTENT_FORM"){if(ae(d))throw new Error("Billing data is missing while calling payWithApplePay");yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"APPLE_PAY",lang:this.sdkEmbed.lang,billingData:d}})}}catch(p){throw yield this.resetSelectedMethod(e),p}c.onvalidatemerchant=p=>{fetch(`${N()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:h.secret,validation_url:p.validationURL})}).then(f=>f.ok?f.json():Promise.reject()).then(f=>c.completeMerchantValidation(f)).catch(i)},c.onpaymentauthorized=p=>{fetch(`${N()}/api/v1/providers/applepay/token/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({token_data:p.payment.token,secret:h.secret})}).then(f=>f.ok?f.json():Promise.reject()).then(()=>{c.completePayment(ApplePaySession.STATUS_SUCCESS),a()}).catch(()=>{c.completePayment(ApplePaySession.STATUS_FAILURE),i()})},c.oncancel=o,c.begin()})}renderForm({selector:e,intentId:t}){return g.throwIf(!e,"selector is required for renderForm"),g.throwIf(!t,"intentId is required for renderForm"),this.sdkEmbed.render({selector:e,intentId:t})}setLocale(e){return this.sdkEmbed.setLocale(e)}removeEventListeners(){return this.sdkEmbed.abortService()}elements({styles:e,classNames:t}){const n=[];return y(this,A,B).call(this,n),{create:({elementType:r,elementOptions:o})=>{const i=new Map,a=document.querySelector(o.selector);g.throwIf(!a,`Couldn't find an element with selector ${o.selector}!`),a.classList.add("MoneyHashElement");const d=(t==null?void 0:t.focus)||"MoneyHashElement--focus",l=(t==null?void 0:t.error)||"MoneyHashElement--error";return n.push(c=>{var p,f,$,F,q;const{type:m,data:h}=c.data;if(m===`${r}@focus`){a.classList.add(d),(p=i.get(`${r}@focus`))==null||p();return}if(m===`${r}@blur`){a.classList.remove(d),(f=i.get(`${r}@blur`))==null||f();return}if(m===`${r}@error`){h.isValid?a.classList.remove(l):a.classList.add(l),($=i.get(`${r}@error`))==null||$(h);return}if(m===`${r}@changeInput`){(F=i.get(`${r}@changeInput`))==null||F();return}m===`${r}@cardNumberChange`&&((q=i.get(`${r}@cardNumberChange`))==null||q(h))}),{mount:()=>{this.mountedCardElements.push(r),y(this,U,O).call(this,{container:a,elementType:r,elementOptions:o,styles:b(b({},e),o.styles)})},on:(c,m)=>{i.set(`${r}@${c}`,m)},off:c=>i.delete(`${r}@${c}`)}}}}submitForm(o){return w(this,arguments,function*({intentId:e,accessToken:t,billingData:n,shippingData:r}){const i=ne(this.mountedCardElements);g.throwIf(!!i,`You must mount ${i} element!`);const a=new T;let d,l;t&&(this.vaultSubmitListener.current=m=>{const{type:h,data:p}=m.data;h==="vaultSubmit:success"&&a.resolve(p),h==="vaultSubmit:error"&&a.reject(p)},l=y(this,R,J).call(this,t),d=yield a.promise);const c=yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"CARD",lang:this.sdkEmbed.lang,billingData:n,shippingData:r,cardEmbed:d}});return l&&l.remove(),c})}submitCvv(n){return w(this,arguments,function*({intentId:e,cvv:t}){return this.sdkApiHandler.request({api:"sdk:submitCardCvv",payload:{intentId:e,cvv:t,lang:this.sdkEmbed.lang}})})}renderUrl(e,t,n){return w(this,null,function*(){switch(t){case"IFRAME":return y(this,L,x).call(this,e);case"POPUP_IFRAME":return y(this,I,D).call(this,e);case"REDIRECT":return y(this,S,Y).call(this,e,n);default:return null}})}}L=new WeakSet,x=function(e){return w(this,null,function*(){const t=document.querySelector("#rendered-url-iframe-container");g.throwIf(!t,"Couldn't find an element with id rendered-url-iframe-container to render the iframe!");const n=document.createElement("iframe");n.src=e,n.style.setProperty("border","0","important"),n.style.setProperty("width","100%","important"),n.style.setProperty("height","100%","important"),t==null||t.replaceChildren(n),yield y(this,k,M).call(this),n.remove()})},I=new WeakSet,D=function(e){return w(this,null,function*(){const t=window.open(`${e}`,"","width=600,height=400,left=200,top=200");g.throwIf(!t,"Popup blocked by browser!"),yield y(this,k,M).call(this),t==null||t.close()})},S=new WeakSet,Y=function(e,t){return w(this,null,function*(){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},k=new WeakSet,M=function(){return w(this,null,function*(){const e=new T,t=n=>{var i,a,d,l;const{type:r,data:o}=n.data;switch(r){case"onComplete":(a=(i=this.options).onComplete)==null||a.call(i,b({type:this.options.type},o)),e.resolve(()=>null),window.removeEventListener("message",t);break;case"onFail":(l=(d=this.options).onFail)==null||l.call(d,b({type:this.options.type},o)),e.resolve(()=>null),window.removeEventListener("message",t);break;default:e.resolve(()=>null);break}};return window.addEventListener("message",t),e.promise})},A=new WeakSet,B=function(e){const t=n=>{e.forEach(r=>{r(n)})};window.addEventListener("message",t)},C=new WeakSet,z=function(e){const t=n=>{e.current&&e.current(n)};window.addEventListener("message",t)},U=new WeakSet,O=function({container:e,elementType:t,elementOptions:n,styles:r}){var d,l,c,m;const o=j(),i=new URL(`${o}/vaultField/vaultField.html`);i.searchParams.set("host",btoa(window.location.origin)),i.searchParams.set("type",t),((d=n.validation)==null?void 0:d.required)!==void 0&&i.searchParams.set("required",`${(l=n.validation)==null?void 0:l.required}`),i.searchParams.set("placeholder",(c=n.placeholder)!=null?c:""),i.searchParams.set("lang",this.sdkEmbed.lang),i.searchParams.set("direction",(r==null?void 0:r.direction)||""),i.searchParams.set("color",(r==null?void 0:r.color)||"#000"),i.searchParams.set("placeholderColor",(r==null?void 0:r.placeholderColor)||"#ccc"),i.searchParams.set("backgroundColor",(r==null?void 0:r.backgroundColor)||"transparent"),i.searchParams.set("fontSize",(r==null?void 0:r.fontSize)||""),i.searchParams.set("padding",(r==null?void 0:r.padding)||"");const a=document.createElement("iframe");a.src=i.toString(),a.style.height=(m=r==null?void 0:r.height)!=null?m:"40px",a.style.setProperty("overflow","hidden","important"),a.style.setProperty("display","block","important"),a.style.setProperty("width","100%","important"),a.style.setProperty("maxWidth","100%","important"),a.style.setProperty("border","0","important"),a.style.setProperty("margin","0","important"),a.style.setProperty("padding","0","important"),a.style.setProperty("userSelect","none","important"),a.style.setProperty("colorScheme","light only","important"),e.replaceChildren(a)},R=new WeakSet,J=function(e){const t=j(),n=re(),r=new URL(`${t}/vaultSubmit/vaultSubmit.html`);r.searchParams.set("host",btoa(window.location.origin)),r.searchParams.set("vault_api_url",`${n}/api/v1/tokens/`),r.searchParams.set("access_token",e),r.searchParams.set("lang",this.sdkEmbed.lang);const o=document.createElement("iframe");return o.id="moneyhash-submit-iframe",o.src=r.toString(),o.hidden=!0,document.body.appendChild(o),o};module.exports=se; | ||
"use strict";var X=Object.defineProperty,Z=Object.defineProperties;var ee=Object.getOwnPropertyDescriptors;var T=Object.getOwnPropertySymbols;var te=Object.prototype.hasOwnProperty,re=Object.prototype.propertyIsEnumerable;var M=(i,e,t)=>e in i?X(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,b=(i,e)=>{for(var t in e||(e={}))te.call(e,t)&&M(i,t,e[t]);if(T)for(var t of T(e))re.call(e,t)&&M(i,t,e[t]);return i},j=(i,e)=>Z(i,ee(e));var g=(i,e,t)=>(M(i,typeof e!="symbol"?e+"":e,t),t),ae=(i,e,t)=>{if(!e.has(i))throw TypeError("Cannot "+t)};var P=(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)=>(ae(i,e,"access private method"),t);var w=(i,e,t)=>new Promise((a,r)=>{var d=o=>{try{n(t.next(o))}catch(c){r(c)}},s=o=>{try{n(t.throw(o))}catch(c){r(c)}},n=o=>o.done?a(o.value):Promise.resolve(o.value).then(d,s);n((t=t.apply(i,e)).next())});const f=require("./sdkEmbed-0ff1d36a.cjs");function ne(){return typeof window!="undefined"}const v=class{constructor(){ne()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=f.getIframeUrl(),t=new URL(`${e}/embed/headless-sdk`);t.searchParams.set("sdk","true"),t.searchParams.set("parent",window.location.origin),t.searchParams.set("version","js@1.1.1");const a=document.createElement("iframe");a.id="moneyhash-headless-sdk",a.src=t.toString(),a.hidden=!0,document.body.appendChild(a),v.messagingService=new f.MessagingService({target:a.contentWindow,targetOrigin:e}),v.isCommunicationReady=new Promise(r=>{var s;const d=n=>{var o;n.data.type==="headlessSDK:init"&&(r(),(o=v.messagingService)==null||o.removeListener(d))};(s=v.messagingService)==null||s.onReceive(d)})}request(a){return w(this,arguments,function*({api:e,payload:t}){return yield v.isCommunicationReady,new Promise((r,d)=>{var n,o;(n=v.messagingService)==null||n.send({type:e,data:t});const s=c=>{var u;const{type:l,data:p}=c.data;l===e&&(p.status==="resolved"?r(p.payload):d(p.payload),(u=v.messagingService)==null||u.removeListener(s))};(o=v.messagingService)==null||o.onReceive(s)})})}};let E=v;g(E,"messagingService",null),g(E,"isCommunicationReady");class W{constructor(){g(this,"promise");g(this,"resolve");g(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function se(){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 D(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}function ie(i){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!i.includes(t))return t;return null}function oe(i){return(Array.isArray(i)?i.length:Object.keys(i).length)===0}function de(i,e){return new Promise((t,a)=>{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",()=>{a(new Error("Script failed to load"))}),document.body.appendChild(d)})}const Y=new Set(["method","customerBalance","savedCard"]);var L,B,I,z,S,J,k,$,A,O,U,K,C,G,R,Q;class ce{constructor(e){P(this,L);P(this,I);P(this,S);P(this,k);P(this,A);P(this,U);P(this,C);P(this,R);g(this,"options");g(this,"sdkApiHandler",new E);g(this,"sdkEmbed");g(this,"vaultSubmitListener",{current:null});g(this,"mountedCardElements",[]);this.options=e,this.sdkEmbed=new f.SDKEmbed(j(b({},e),{headless:!0})),y(this,U,K).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:a,metaData:r}){return f.throwIf(!Y.has(t),`type must be a valid one (${[...Y].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:a,lang:this.sdkEmbed.lang,metaData:r}})}resetSelectedMethod(e){return this.sdkApiHandler.request({api:"sdk:resetSelectedMethod",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}deleteCard({cardId:e,intentSecret:t}){return f.throwIf(this.options.type==="payout","deleteCard is allowed only for payment intent!"),this.sdkApiHandler.request({api:"sdk:deleteCard",payload:{cardId:e,intentSecret:t,lang:this.sdkEmbed.lang}})}payWithApplePay(c){return w(this,arguments,function*({intentId:e,currency:t,amount:a,countryCode:r,onCancel:d=()=>{},onError:s,onComplete:n,billingData:o={}}){if(yield de("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)return;const l=new ApplePaySession(3,{countryCode:r,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${a}`}}),{state:p,intent:u}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(p==="INTENT_FORM"){if(oe(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}l.onvalidatemerchant=h=>{fetch(`${D()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:u.secret,validation_url:h.validationURL})}).then(m=>m.ok?m.json():Promise.reject()).then(m=>l.completeMerchantValidation(m)).catch(s)},l.onpaymentauthorized=h=>{fetch(`${D()}/api/v1/providers/applepay/token/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({token_data:h.payment.token,secret:u.secret})}).then(m=>m.ok?m.json():Promise.reject()).then(()=>{l.completePayment(ApplePaySession.STATUS_SUCCESS),n()}).catch(()=>{l.completePayment(ApplePaySession.STATUS_FAILURE),s()})},l.oncancel=d,l.begin()})}renderForm({selector:e,intentId:t}){return f.throwIf(!e,"selector is required for renderForm"),f.throwIf(!t,"intentId is required for renderForm"),this.sdkEmbed.render({selector:e,intentId:t})}setLocale(e){return this.sdkEmbed.setLocale(e)}removeEventListeners(){return this.sdkEmbed.abortService()}elements({styles:e,classes:t}){const a=[];return y(this,A,O).call(this,a),{create:({elementType:r,elementOptions:d})=>{var p,u;const s=new Map,n=document.querySelector(d.selector);f.throwIf(!n,`Couldn't find an element with selector ${d.selector}!`),n.classList.add("MoneyHashElement");const o=b(b({},t),d.classes),c=((p=o==null?void 0:o.focus)==null?void 0:p.split(" "))||["MoneyHashElement--focus"],l=((u=o==null?void 0:o.error)==null?void 0:u.split(" "))||["MoneyHashElement--error"];return a.push(h=>{var F,N,q,H,V;const{type:m,data:_}=h.data;if(m===`${r}@focus`){n.classList.add(...c),(F=s.get(`${r}@focus`))==null||F();return}if(m===`${r}@blur`){n.classList.remove(...c),(N=s.get(`${r}@blur`))==null||N();return}if(m===`${r}@error`){_.isValid?n.classList.remove(...l):n.classList.add(...l),(q=s.get(`${r}@error`))==null||q(_);return}if(m===`${r}@changeInput`){(H=s.get(`${r}@changeInput`))==null||H();return}m===`${r}@cardNumberChange`&&((V=s.get(`${r}@cardNumberChange`))==null||V(_))}),{mount:()=>{this.mountedCardElements.push(r),y(this,C,G).call(this,{container:n,elementType:r,elementOptions:d,styles:b(b({},e),d.styles)})},on:(h,m)=>{s.set(`${r}@${h}`,m)},off:h=>s.delete(`${r}@${h}`)}}}}submitForm(d){return w(this,arguments,function*({intentId:e,accessToken:t,billingData:a,shippingData:r}){const s=ie(this.mountedCardElements);f.throwIf(!!s,`You must mount ${s} element!`);const n=new W;let o,c;t&&(this.vaultSubmitListener.current=p=>{const{type:u,data:h}=p.data;u==="vaultSubmit:success"&&n.resolve(h),u==="vaultSubmit:error"&&n.reject(h)},c=y(this,R,Q).call(this,t),o=yield n.promise);const l=yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"CARD",lang:this.sdkEmbed.lang,billingData:a,shippingData:r,cardEmbed:o}});return c&&c.remove(),l})}submitCvv(a){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,a){return w(this,null,function*(){switch(t){case"IFRAME":return y(this,L,B).call(this,e);case"POPUP_IFRAME":return y(this,I,z).call(this,e);case"REDIRECT":return y(this,S,J).call(this,e,a);default:return null}})}}L=new WeakSet,B=function(e){return w(this,null,function*(){const t=document.querySelector("#rendered-url-iframe-container");f.throwIf(!t,"Couldn't find an element with id rendered-url-iframe-container to render the iframe!");const a=document.createElement("iframe");a.src=e,a.style.setProperty("border","0","important"),a.style.setProperty("width","100%","important"),a.style.setProperty("height","100%","important"),t==null||t.replaceChildren(a),yield y(this,k,$).call(this),a.remove()})},I=new WeakSet,z=function(e){return w(this,null,function*(){const t=window.open(`${e}`,"","width=600,height=400,left=200,top=200");f.throwIf(!t,"Popup blocked by browser!"),yield y(this,k,$).call(this),t==null||t.close()})},S=new WeakSet,J=function(e,t){return w(this,null,function*(){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},k=new WeakSet,$=function(){return w(this,null,function*(){const e=new W,t=a=>{var s,n,o,c;const{type:r,data:d}=a.data;switch(r){case"onComplete":(n=(s=this.options).onComplete)==null||n.call(s,b({type:this.options.type},d)),e.resolve(()=>null),window.removeEventListener("message",t);break;case"onFail":(c=(o=this.options).onFail)==null||c.call(o,b({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})},A=new WeakSet,O=function(e){const t=a=>{e.forEach(r=>{r(a)})};window.addEventListener("message",t)},U=new WeakSet,K=function(e){const t=a=>{e.current&&e.current(a)};window.addEventListener("message",t)},C=new WeakSet,G=function({container:e,elementType:t,elementOptions:a,styles:r}){var o,c,l,p;const d=x(),s=new URL(`${d}/vaultField/vaultField.html`);s.searchParams.set("host",btoa(window.location.origin)),s.searchParams.set("type",t),((o=a.validation)==null?void 0:o.required)!==void 0&&s.searchParams.set("required",`${(c=a.validation)==null?void 0:c.required}`),s.searchParams.set("placeholder",(l=a.placeholder)!=null?l:""),s.searchParams.set("lang",this.sdkEmbed.lang),s.searchParams.set("direction",(r==null?void 0:r.direction)||""),s.searchParams.set("color",(r==null?void 0:r.color)||"#000"),s.searchParams.set("placeholderColor",(r==null?void 0:r.placeholderColor)||"#ccc"),s.searchParams.set("backgroundColor",(r==null?void 0:r.backgroundColor)||"transparent"),s.searchParams.set("fontSize",(r==null?void 0:r.fontSize)||""),s.searchParams.set("padding",(r==null?void 0:r.padding)||"");const n=document.createElement("iframe");n.src=s.toString(),n.style.height=(p=r==null?void 0:r.height)!=null?p:"40px",n.style.setProperty("overflow","hidden","important"),n.style.setProperty("display","block","important"),n.style.setProperty("width","100%","important"),n.style.setProperty("maxWidth","100%","important"),n.style.setProperty("border","0","important"),n.style.setProperty("margin","0","important"),n.style.setProperty("padding","0","important"),n.style.setProperty("userSelect","none","important"),n.style.setProperty("colorScheme","light only","important"),e.replaceChildren(n)},R=new WeakSet,Q=function(e){const t=x(),a=se(),r=new URL(`${t}/vaultSubmit/vaultSubmit.html`);r.searchParams.set("host",btoa(window.location.origin)),r.searchParams.set("vault_api_url",`${a}/api/v1/tokens/`),r.searchParams.set("access_token",e),r.searchParams.set("lang",this.sdkEmbed.lang);const d=document.createElement("iframe");return d.id="moneyhash-submit-iframe",d.src=r.toString(),d.hidden=!0,document.body.appendChild(d),d};module.exports=ce; |
@@ -114,3 +114,3 @@ export declare interface AbstractIntent { | ||
styles?: ElementStyles; | ||
classNames?: Partial<Record<ElementClassNames, string>>; | ||
classes?: Partial<Record<ElementClassNames, string>>; | ||
}; | ||
@@ -500,3 +500,3 @@ | ||
*/ | ||
elements({ styles, classNames }: ElementsProps): Elements; | ||
elements({ styles, classes }: ElementsProps): Elements; | ||
/** | ||
@@ -503,0 +503,0 @@ * Submits the form with the form fields data (card, billing, shipping) |
@@ -1,41 +0,41 @@ | ||
var K = Object.defineProperty, G = Object.defineProperties; | ||
var Q = Object.getOwnPropertyDescriptors; | ||
var H = Object.getOwnPropertySymbols; | ||
var X = Object.prototype.hasOwnProperty, Z = Object.prototype.propertyIsEnumerable; | ||
var _ = (s, e, t) => e in s ? K(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, b = (s, e) => { | ||
var X = Object.defineProperty, Z = Object.defineProperties; | ||
var ee = Object.getOwnPropertyDescriptors; | ||
var T = Object.getOwnPropertySymbols; | ||
var te = Object.prototype.hasOwnProperty, re = Object.prototype.propertyIsEnumerable; | ||
var M = (i, e, t) => e in i ? X(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, P = (i, e) => { | ||
for (var t in e || (e = {})) | ||
X.call(e, t) && _(s, t, e[t]); | ||
if (H) | ||
for (var t of H(e)) | ||
Z.call(e, t) && _(s, t, e[t]); | ||
return s; | ||
}, V = (s, e) => G(s, Q(e)); | ||
var h = (s, e, t) => (_(s, typeof e != "symbol" ? e + "" : e, t), t), ee = (s, e, t) => { | ||
if (!e.has(s)) | ||
te.call(e, t) && M(i, t, e[t]); | ||
if (T) | ||
for (var t of T(e)) | ||
re.call(e, t) && M(i, t, e[t]); | ||
return i; | ||
}, j = (i, e) => Z(i, ee(e)); | ||
var g = (i, e, t) => (M(i, typeof e != "symbol" ? e + "" : e, t), t), ae = (i, e, t) => { | ||
if (!e.has(i)) | ||
throw TypeError("Cannot " + t); | ||
}; | ||
var w = (s, e, t) => { | ||
if (e.has(s)) | ||
var w = (i, e, t) => { | ||
if (e.has(i)) | ||
throw TypeError("Cannot add the same private member more than once"); | ||
e instanceof WeakSet ? e.add(s) : e.set(s, t); | ||
e instanceof WeakSet ? e.add(i) : e.set(i, t); | ||
}; | ||
var f = (s, e, t) => (ee(s, e, "access private method"), t); | ||
var y = (s, e, t) => new Promise((n, r) => { | ||
var o = (d) => { | ||
var f = (i, e, t) => (ae(i, e, "access private method"), t); | ||
var y = (i, e, t) => new Promise((a, r) => { | ||
var d = (o) => { | ||
try { | ||
a(t.next(d)); | ||
} catch (l) { | ||
r(l); | ||
n(t.next(o)); | ||
} catch (c) { | ||
r(c); | ||
} | ||
}, i = (d) => { | ||
}, s = (o) => { | ||
try { | ||
a(t.throw(d)); | ||
} catch (l) { | ||
r(l); | ||
n(t.throw(o)); | ||
} catch (c) { | ||
r(c); | ||
} | ||
}, a = (d) => d.done ? n(d.value) : Promise.resolve(d.value).then(o, i); | ||
a((t = t.apply(s, e)).next()); | ||
}, n = (o) => o.done ? a(o.value) : Promise.resolve(o.value).then(d, s); | ||
n((t = t.apply(i, e)).next()); | ||
}); | ||
import { M as te, g as re, S as ne, t as P } from "./sdkEmbed-f5156d5c.js"; | ||
function ae() { | ||
import { M as ne, g as se, S as ie, t as b } from "./sdkEmbed-2c378aeb.js"; | ||
function oe() { | ||
return typeof window != "undefined"; | ||
@@ -45,3 +45,3 @@ } | ||
constructor() { | ||
ae() && this.initSDKCommunicationIframe(); | ||
oe() && this.initSDKCommunicationIframe(); | ||
} | ||
@@ -51,18 +51,18 @@ initSDKCommunicationIframe() { | ||
return; | ||
const e = re(), t = new URL(`${e}/embed/headless-sdk`); | ||
t.searchParams.set("sdk", "true"), t.searchParams.set("parent", window.location.origin), t.searchParams.set("version", "js@1.1.0"); | ||
const n = document.createElement("iframe"); | ||
n.id = "moneyhash-headless-sdk", n.src = t.toString(), n.hidden = !0, document.body.appendChild(n), v.messagingService = new te({ | ||
target: n.contentWindow, | ||
const e = se(), t = new URL(`${e}/embed/headless-sdk`); | ||
t.searchParams.set("sdk", "true"), t.searchParams.set("parent", window.location.origin), t.searchParams.set("version", "js@1.1.1"); | ||
const a = document.createElement("iframe"); | ||
a.id = "moneyhash-headless-sdk", a.src = t.toString(), a.hidden = !0, document.body.appendChild(a), v.messagingService = new ne({ | ||
target: a.contentWindow, | ||
targetOrigin: e | ||
}), v.isCommunicationReady = new Promise((r) => { | ||
var i; | ||
const o = (a) => { | ||
var d; | ||
a.data.type === "headlessSDK:init" && (r(), (d = v.messagingService) == null || d.removeListener(o)); | ||
var s; | ||
const d = (n) => { | ||
var o; | ||
n.data.type === "headlessSDK:init" && (r(), (o = v.messagingService) == null || o.removeListener(d)); | ||
}; | ||
(i = v.messagingService) == null || i.onReceive(o); | ||
(s = v.messagingService) == null || s.onReceive(d); | ||
}); | ||
} | ||
request(n) { | ||
request(a) { | ||
return y(this, arguments, function* ({ | ||
@@ -72,14 +72,14 @@ api: e, | ||
}) { | ||
return yield v.isCommunicationReady, new Promise((r, o) => { | ||
var a, d; | ||
(a = v.messagingService) == null || a.send({ | ||
return yield v.isCommunicationReady, new Promise((r, d) => { | ||
var n, o; | ||
(n = v.messagingService) == null || n.send({ | ||
type: e, | ||
data: t | ||
}); | ||
const i = (l) => { | ||
var p; | ||
const { type: c, data: m } = l.data; | ||
c === e && (m.status === "resolved" ? r(m.payload) : o(m.payload), (p = v.messagingService) == null || p.removeListener(i)); | ||
const s = (c) => { | ||
var u; | ||
const { type: l, data: h } = c.data; | ||
l === e && (h.status === "resolved" ? r(h.payload) : d(h.payload), (u = v.messagingService) == null || u.removeListener(s)); | ||
}; | ||
(d = v.messagingService) == null || d.onReceive(i); | ||
(o = v.messagingService) == null || o.onReceive(s); | ||
}); | ||
@@ -90,8 +90,8 @@ }); | ||
let E = v; | ||
h(E, "messagingService", null), h(E, "isCommunicationReady"); | ||
class T { | ||
g(E, "messagingService", null), g(E, "isCommunicationReady"); | ||
class W { | ||
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) => { | ||
@@ -102,15 +102,15 @@ this.resolve = e, this.reject = t; | ||
} | ||
function ie() { | ||
function de() { | ||
var e; | ||
return (e = window.MONEYHASH_VAULT_API_URL) != null ? e : "https://vault.moneyhash.io"; | ||
} | ||
function j() { | ||
function x() { | ||
var e; | ||
return (e = window.MONEYHASH_VAULT_INPUT_IFRAME_URL) != null ? e : "https://vault-form.moneyhash.io"; | ||
} | ||
function N() { | ||
function D() { | ||
var e; | ||
return (e = window.API_URL) != null ? e : "https://web.moneyhash.io"; | ||
} | ||
function se(s) { | ||
function ce(i) { | ||
const e = [ | ||
@@ -123,11 +123,11 @@ "cardNumber", | ||
for (const t of e) | ||
if (!s.includes(t)) | ||
if (!i.includes(t)) | ||
return t; | ||
return null; | ||
} | ||
function oe(s) { | ||
return (Array.isArray(s) ? s.length : Object.keys(s).length) === 0; | ||
function le(i) { | ||
return (Array.isArray(i) ? i.length : Object.keys(i).length) === 0; | ||
} | ||
function de(s, e) { | ||
return new Promise((t, n) => { | ||
function me(i, e) { | ||
return new Promise((t, a) => { | ||
if (document.getElementById(e)) { | ||
@@ -137,11 +137,11 @@ t(void 0); | ||
} | ||
const o = document.createElement("script"); | ||
o.src = s, o.id = e, o.addEventListener("load", () => { | ||
const d = document.createElement("script"); | ||
d.src = i, d.id = e, d.addEventListener("load", () => { | ||
t(void 0); | ||
}), o.addEventListener("error", () => { | ||
n(new Error("Script failed to load")); | ||
}), document.body.appendChild(o); | ||
}), d.addEventListener("error", () => { | ||
a(new Error("Script failed to load")); | ||
}), document.body.appendChild(d); | ||
}); | ||
} | ||
const W = /* @__PURE__ */ new Set([ | ||
const Y = /* @__PURE__ */ new Set([ | ||
"method", | ||
@@ -151,4 +151,4 @@ "customerBalance", | ||
]); | ||
var L, x, S, D, A, Y, k, M, I, B, C, z, U, O, R, J; | ||
class me { | ||
var L, B, S, z, A, J, k, $, I, O, U, K, C, G, R, Q; | ||
class ue { | ||
constructor(e) { | ||
@@ -160,13 +160,13 @@ w(this, L); | ||
w(this, I); | ||
w(this, U); | ||
w(this, C); | ||
w(this, U); | ||
w(this, R); | ||
h(this, "options"); | ||
h(this, "sdkApiHandler", new E()); | ||
h(this, "sdkEmbed"); | ||
h(this, "vaultSubmitListener", { | ||
g(this, "options"); | ||
g(this, "sdkApiHandler", new E()); | ||
g(this, "sdkEmbed"); | ||
g(this, "vaultSubmitListener", { | ||
current: null | ||
}); | ||
h(this, "mountedCardElements", []); | ||
this.options = e, this.sdkEmbed = new ne(V(b({}, e), { headless: !0 })), f(this, C, z).call(this, this.vaultSubmitListener); | ||
g(this, "mountedCardElements", []); | ||
this.options = e, this.sdkEmbed = new ie(j(P({}, e), { headless: !0 })), f(this, U, K).call(this, this.vaultSubmitListener); | ||
} | ||
@@ -262,8 +262,8 @@ /** | ||
type: t, | ||
id: n, | ||
id: a, | ||
metaData: r | ||
}) { | ||
return P( | ||
!W.has(t), | ||
`type must be a valid one (${[...W].join( | ||
return b( | ||
!Y.has(t), | ||
`type must be a valid one (${[...Y].join( | ||
" | " | ||
@@ -277,3 +277,3 @@ )})` | ||
intentId: e, | ||
id: n, | ||
id: a, | ||
lang: this.sdkEmbed.lang, | ||
@@ -326,3 +326,3 @@ metaData: r | ||
}) { | ||
return P( | ||
return b( | ||
this.options.type === "payout", | ||
@@ -377,15 +377,15 @@ "deleteCard is allowed only for payment intent!" | ||
*/ | ||
payWithApplePay(l) { | ||
payWithApplePay(c) { | ||
return y(this, arguments, function* ({ | ||
intentId: e, | ||
currency: t, | ||
amount: n, | ||
amount: a, | ||
countryCode: r, | ||
onCancel: o = () => { | ||
onCancel: d = () => { | ||
}, | ||
onError: i, | ||
onComplete: a, | ||
billingData: d = {} | ||
onError: s, | ||
onComplete: n, | ||
billingData: o = {} | ||
}) { | ||
if (yield de( | ||
if (yield me( | ||
"https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js", | ||
@@ -395,3 +395,3 @@ "moneyHash-apple-pay-sdk" | ||
return; | ||
const c = new ApplePaySession(3, { | ||
const l = new ApplePaySession(3, { | ||
countryCode: r, | ||
@@ -404,5 +404,5 @@ currencyCode: t, | ||
type: "final", | ||
amount: `${n}` | ||
amount: `${a}` | ||
} | ||
}), { state: m, intent: p } = yield this.proceedWith({ | ||
}), { state: h, intent: u } = yield this.proceedWith({ | ||
intentId: e, | ||
@@ -413,4 +413,4 @@ type: "method", | ||
try { | ||
if (m === "INTENT_FORM") { | ||
if (oe(d)) | ||
if (h === "INTENT_FORM") { | ||
if (le(o)) | ||
throw new Error( | ||
@@ -425,11 +425,11 @@ "Billing data is missing while calling payWithApplePay" | ||
lang: this.sdkEmbed.lang, | ||
billingData: d | ||
billingData: o | ||
} | ||
}); | ||
} | ||
} catch (u) { | ||
throw yield this.resetSelectedMethod(e), u; | ||
} catch (p) { | ||
throw yield this.resetSelectedMethod(e), p; | ||
} | ||
c.onvalidatemerchant = (u) => { | ||
fetch(`${N()}/api/v1/providers/applepay/session/`, { | ||
l.onvalidatemerchant = (p) => { | ||
fetch(`${D()}/api/v1/providers/applepay/session/`, { | ||
method: "post", | ||
@@ -440,10 +440,10 @@ headers: { | ||
body: JSON.stringify({ | ||
secret: p.secret, | ||
validation_url: u.validationURL | ||
secret: u.secret, | ||
validation_url: p.validationURL | ||
}) | ||
}).then((g) => g.ok ? g.json() : Promise.reject()).then( | ||
(g) => c.completeMerchantValidation(g) | ||
).catch(i); | ||
}, c.onpaymentauthorized = (u) => { | ||
fetch(`${N()}/api/v1/providers/applepay/token/`, { | ||
}).then((m) => m.ok ? m.json() : Promise.reject()).then( | ||
(m) => l.completeMerchantValidation(m) | ||
).catch(s); | ||
}, l.onpaymentauthorized = (p) => { | ||
fetch(`${D()}/api/v1/providers/applepay/token/`, { | ||
method: "post", | ||
@@ -454,11 +454,11 @@ headers: { | ||
body: JSON.stringify({ | ||
token_data: u.payment.token, | ||
secret: p.secret | ||
token_data: p.payment.token, | ||
secret: u.secret | ||
}) | ||
}).then((g) => g.ok ? g.json() : Promise.reject()).then(() => { | ||
c.completePayment(ApplePaySession.STATUS_SUCCESS), a(); | ||
}).then((m) => m.ok ? m.json() : Promise.reject()).then(() => { | ||
l.completePayment(ApplePaySession.STATUS_SUCCESS), n(); | ||
}).catch(() => { | ||
c.completePayment(ApplePaySession.STATUS_FAILURE), i(); | ||
l.completePayment(ApplePaySession.STATUS_FAILURE), s(); | ||
}); | ||
}, c.oncancel = o, c.begin(); | ||
}, l.oncancel = d, l.begin(); | ||
}); | ||
@@ -483,3 +483,3 @@ } | ||
renderForm({ selector: e, intentId: t }) { | ||
return P(!e, "selector is required for renderForm"), P(!t, "intentId is required for renderForm"), this.sdkEmbed.render({ selector: e, intentId: t }); | ||
return b(!e, "selector is required for renderForm"), b(!t, "intentId is required for renderForm"), this.sdkEmbed.render({ selector: e, intentId: t }); | ||
} | ||
@@ -520,5 +520,5 @@ /** | ||
*/ | ||
elements({ styles: e, classNames: t }) { | ||
const n = []; | ||
return f(this, I, B).call(this, n), { | ||
elements({ styles: e, classes: t }) { | ||
const a = []; | ||
return f(this, I, O).call(this, a), { | ||
/** | ||
@@ -545,44 +545,49 @@ * Creates card field element | ||
*/ | ||
create: ({ elementType: r, elementOptions: o }) => { | ||
const i = /* @__PURE__ */ new Map(), a = document.querySelector( | ||
o.selector | ||
create: ({ elementType: r, elementOptions: d }) => { | ||
var h, u; | ||
const s = /* @__PURE__ */ new Map(), n = document.querySelector( | ||
d.selector | ||
); | ||
P( | ||
!a, | ||
`Couldn't find an element with selector ${o.selector}!` | ||
), a.classList.add("MoneyHashElement"); | ||
const d = (t == null ? void 0 : t.focus) || "MoneyHashElement--focus", l = (t == null ? void 0 : t.error) || "MoneyHashElement--error"; | ||
return n.push((c) => { | ||
var u, g, $, F, q; | ||
const { type: m, data: p } = c.data; | ||
b( | ||
!n, | ||
`Couldn't find an element with selector ${d.selector}!` | ||
), n.classList.add("MoneyHashElement"); | ||
const o = P(P({}, t), d.classes), c = ((h = o == null ? void 0 : o.focus) == null ? void 0 : h.split(" ")) || [ | ||
"MoneyHashElement--focus" | ||
], l = ((u = o == null ? void 0 : o.error) == null ? void 0 : u.split(" ")) || [ | ||
"MoneyHashElement--error" | ||
]; | ||
return a.push((p) => { | ||
var F, N, q, H, V; | ||
const { type: m, data: _ } = p.data; | ||
if (m === `${r}@focus`) { | ||
a.classList.add(d), (u = i.get(`${r}@focus`)) == null || u(); | ||
n.classList.add(...c), (F = s.get(`${r}@focus`)) == null || F(); | ||
return; | ||
} | ||
if (m === `${r}@blur`) { | ||
a.classList.remove(d), (g = i.get(`${r}@blur`)) == null || g(); | ||
n.classList.remove(...c), (N = s.get(`${r}@blur`)) == null || N(); | ||
return; | ||
} | ||
if (m === `${r}@error`) { | ||
p.isValid ? a.classList.remove(l) : a.classList.add(l), ($ = i.get(`${r}@error`)) == null || $(p); | ||
_.isValid ? n.classList.remove(...l) : n.classList.add(...l), (q = s.get(`${r}@error`)) == null || q(_); | ||
return; | ||
} | ||
if (m === `${r}@changeInput`) { | ||
(F = i.get(`${r}@changeInput`)) == null || F(); | ||
(H = s.get(`${r}@changeInput`)) == null || H(); | ||
return; | ||
} | ||
m === `${r}@cardNumberChange` && ((q = i.get(`${r}@cardNumberChange`)) == null || q(p)); | ||
m === `${r}@cardNumberChange` && ((V = s.get(`${r}@cardNumberChange`)) == null || V(_)); | ||
}), { | ||
mount: () => { | ||
this.mountedCardElements.push(r), f(this, U, O).call(this, { | ||
container: a, | ||
this.mountedCardElements.push(r), f(this, C, G).call(this, { | ||
container: n, | ||
elementType: r, | ||
elementOptions: o, | ||
styles: b(b({}, e), o.styles) | ||
elementOptions: d, | ||
styles: P(P({}, e), d.styles) | ||
}); | ||
}, | ||
on: (c, m) => { | ||
i.set(`${r}@${c}`, m); | ||
on: (p, m) => { | ||
s.set(`${r}@${p}`, m); | ||
}, | ||
off: (c) => i.delete(`${r}@${c}`) | ||
off: (p) => s.delete(`${r}@${p}`) | ||
}; | ||
@@ -606,21 +611,21 @@ } | ||
*/ | ||
submitForm(o) { | ||
submitForm(d) { | ||
return y(this, arguments, function* ({ | ||
intentId: e, | ||
accessToken: t, | ||
billingData: n, | ||
billingData: a, | ||
shippingData: r | ||
}) { | ||
const i = se(this.mountedCardElements); | ||
P( | ||
!!i, | ||
`You must mount ${i} element!` | ||
const s = ce(this.mountedCardElements); | ||
b( | ||
!!s, | ||
`You must mount ${s} element!` | ||
); | ||
const a = new T(); | ||
let d, l; | ||
t && (this.vaultSubmitListener.current = (m) => { | ||
const { type: p, data: u } = m.data; | ||
p === "vaultSubmit:success" && a.resolve(u), p === "vaultSubmit:error" && a.reject(u); | ||
}, l = f(this, R, J).call(this, t), d = yield a.promise); | ||
const c = yield this.sdkApiHandler.request({ | ||
const n = new W(); | ||
let o, c; | ||
t && (this.vaultSubmitListener.current = (h) => { | ||
const { type: u, data: p } = h.data; | ||
u === "vaultSubmit:success" && n.resolve(p), u === "vaultSubmit:error" && n.reject(p); | ||
}, c = f(this, R, Q).call(this, t), o = yield n.promise); | ||
const l = yield this.sdkApiHandler.request({ | ||
api: "sdk:submitNativeForm", | ||
@@ -631,8 +636,8 @@ payload: { | ||
lang: this.sdkEmbed.lang, | ||
billingData: n, | ||
billingData: a, | ||
shippingData: r, | ||
cardEmbed: d | ||
cardEmbed: o | ||
} | ||
}); | ||
return l && l.remove(), c; | ||
return c && c.remove(), l; | ||
}); | ||
@@ -650,3 +655,3 @@ } | ||
*/ | ||
submitCvv(n) { | ||
submitCvv(a) { | ||
return y(this, arguments, function* ({ | ||
@@ -666,11 +671,11 @@ intentId: e, | ||
} | ||
renderUrl(e, t, n) { | ||
renderUrl(e, t, a) { | ||
return y(this, null, function* () { | ||
switch (t) { | ||
case "IFRAME": | ||
return f(this, L, x).call(this, e); | ||
return f(this, L, B).call(this, e); | ||
case "POPUP_IFRAME": | ||
return f(this, S, D).call(this, e); | ||
return f(this, S, z).call(this, e); | ||
case "REDIRECT": | ||
return f(this, A, Y).call(this, e, n); | ||
return f(this, A, J).call(this, e, a); | ||
default: | ||
@@ -682,13 +687,13 @@ return null; | ||
} | ||
L = new WeakSet(), x = function(e) { | ||
L = new WeakSet(), B = function(e) { | ||
return y(this, null, function* () { | ||
const t = document.querySelector("#rendered-url-iframe-container"); | ||
P( | ||
b( | ||
!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 f(this, k, M).call(this), n.remove(); | ||
const a = document.createElement("iframe"); | ||
a.src = e, a.style.setProperty("border", "0", "important"), a.style.setProperty("width", "100%", "important"), a.style.setProperty("height", "100%", "important"), t == null || t.replaceChildren(a), yield f(this, k, $).call(this), a.remove(); | ||
}); | ||
}, S = new WeakSet(), D = function(e) { | ||
}, S = new WeakSet(), z = function(e) { | ||
return y(this, null, function* () { | ||
@@ -700,5 +705,5 @@ const t = window.open( | ||
); | ||
P(!t, "Popup blocked by browser!"), yield f(this, k, M).call(this), t == null || t.close(); | ||
b(!t, "Popup blocked by browser!"), yield f(this, k, $).call(this), t == null || t.close(); | ||
}); | ||
}, A = new WeakSet(), Y = function(e, t) { | ||
}, A = new WeakSet(), J = function(e, t) { | ||
return y(this, null, function* () { | ||
@@ -711,17 +716,17 @@ if (!t || !t.redirectToNewWindow) { | ||
}); | ||
}, k = new WeakSet(), M = function() { | ||
}, k = new WeakSet(), $ = function() { | ||
return y(this, null, function* () { | ||
const e = new T(), t = (n) => { | ||
var i, a, d, l; | ||
const { type: r, data: o } = n.data; | ||
const e = new W(), t = (a) => { | ||
var s, n, o, c; | ||
const { type: r, data: d } = a.data; | ||
switch (r) { | ||
case "onComplete": | ||
(a = (i = this.options).onComplete) == null || a.call(i, b({ | ||
(n = (s = this.options).onComplete) == null || n.call(s, P({ | ||
type: this.options.type | ||
}, o)), e.resolve(() => null), window.removeEventListener("message", t); | ||
}, d)), e.resolve(() => null), window.removeEventListener("message", t); | ||
break; | ||
case "onFail": | ||
(l = (d = this.options).onFail) == null || l.call(d, b({ | ||
(c = (o = this.options).onFail) == null || c.call(o, P({ | ||
type: this.options.type | ||
}, o)), e.resolve(() => null), window.removeEventListener("message", t); | ||
}, d)), e.resolve(() => null), window.removeEventListener("message", t); | ||
break; | ||
@@ -735,44 +740,44 @@ default: | ||
}); | ||
}, I = new WeakSet(), B = function(e) { | ||
const t = (n) => { | ||
}, I = new WeakSet(), O = function(e) { | ||
const t = (a) => { | ||
e.forEach((r) => { | ||
r(n); | ||
r(a); | ||
}); | ||
}; | ||
window.addEventListener("message", t); | ||
}, C = new WeakSet(), z = function(e) { | ||
const t = (n) => { | ||
e.current && e.current(n); | ||
}, U = new WeakSet(), K = function(e) { | ||
const t = (a) => { | ||
e.current && e.current(a); | ||
}; | ||
window.addEventListener("message", t); | ||
}, U = new WeakSet(), O = function({ | ||
}, C = new WeakSet(), G = function({ | ||
container: e, | ||
elementType: t, | ||
elementOptions: n, | ||
elementOptions: a, | ||
styles: r | ||
}) { | ||
var d, l, c, m; | ||
const o = j(), i = new URL(`${o}/vaultField/vaultField.html`); | ||
i.searchParams.set("host", btoa(window.location.origin)), i.searchParams.set("type", t), ((d = n.validation) == null ? void 0 : d.required) !== void 0 && i.searchParams.set( | ||
var o, c, l, h; | ||
const d = x(), s = new URL(`${d}/vaultField/vaultField.html`); | ||
s.searchParams.set("host", btoa(window.location.origin)), s.searchParams.set("type", t), ((o = a.validation) == null ? void 0 : o.required) !== void 0 && s.searchParams.set( | ||
"required", | ||
`${(l = n.validation) == null ? void 0 : l.required}` | ||
), i.searchParams.set("placeholder", (c = n.placeholder) != null ? c : ""), i.searchParams.set("lang", this.sdkEmbed.lang), i.searchParams.set("direction", (r == null ? void 0 : r.direction) || ""), i.searchParams.set("color", (r == null ? void 0 : r.color) || "#000"), i.searchParams.set( | ||
`${(c = a.validation) == null ? void 0 : c.required}` | ||
), s.searchParams.set("placeholder", (l = a.placeholder) != null ? l : ""), s.searchParams.set("lang", this.sdkEmbed.lang), s.searchParams.set("direction", (r == null ? void 0 : r.direction) || ""), s.searchParams.set("color", (r == null ? void 0 : r.color) || "#000"), s.searchParams.set( | ||
"placeholderColor", | ||
(r == null ? void 0 : r.placeholderColor) || "#ccc" | ||
), i.searchParams.set( | ||
), s.searchParams.set( | ||
"backgroundColor", | ||
(r == null ? void 0 : r.backgroundColor) || "transparent" | ||
), i.searchParams.set("fontSize", (r == null ? void 0 : r.fontSize) || ""), i.searchParams.set("padding", (r == null ? void 0 : r.padding) || ""); | ||
const a = document.createElement("iframe"); | ||
a.src = i.toString(), a.style.height = (m = r == null ? void 0 : r.height) != null ? m : "40px", a.style.setProperty("overflow", "hidden", "important"), a.style.setProperty("display", "block", "important"), a.style.setProperty("width", "100%", "important"), a.style.setProperty("maxWidth", "100%", "important"), a.style.setProperty("border", "0", "important"), a.style.setProperty("margin", "0", "important"), a.style.setProperty("padding", "0", "important"), a.style.setProperty("userSelect", "none", "important"), a.style.setProperty("colorScheme", "light only", "important"), e.replaceChildren(a); | ||
}, R = new WeakSet(), J = function(e) { | ||
const t = j(), n = ie(), r = new URL( | ||
), s.searchParams.set("fontSize", (r == null ? void 0 : r.fontSize) || ""), s.searchParams.set("padding", (r == null ? void 0 : r.padding) || ""); | ||
const n = document.createElement("iframe"); | ||
n.src = s.toString(), n.style.height = (h = r == null ? void 0 : r.height) != null ? h : "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); | ||
}, R = new WeakSet(), Q = function(e) { | ||
const t = x(), a = de(), r = new URL( | ||
`${t}/vaultSubmit/vaultSubmit.html` | ||
); | ||
r.searchParams.set("host", btoa(window.location.origin)), r.searchParams.set("vault_api_url", `${n}/api/v1/tokens/`), r.searchParams.set("access_token", e), r.searchParams.set("lang", this.sdkEmbed.lang); | ||
const o = document.createElement("iframe"); | ||
return o.id = "moneyhash-submit-iframe", o.src = r.toString(), o.hidden = !0, document.body.appendChild(o), o; | ||
r.searchParams.set("host", btoa(window.location.origin)), r.searchParams.set("vault_api_url", `${a}/api/v1/tokens/`), r.searchParams.set("access_token", e), r.searchParams.set("lang", this.sdkEmbed.lang); | ||
const d = document.createElement("iframe"); | ||
return d.id = "moneyhash-submit-iframe", d.src = r.toString(), d.hidden = !0, document.body.appendChild(d), d; | ||
}; | ||
export { | ||
me as default | ||
ue as default | ||
}; |
@@ -1,1 +0,1 @@ | ||
(function(d,a){typeof exports=="object"&&typeof module!="undefined"?module.exports=a():typeof define=="function"&&define.amd?define(a):(d=typeof globalThis!="undefined"?globalThis:d||self,d.MoneyHash=a())})(this,function(){var $,K,F,G,H,Q,C,x,j,X,q,Z,T,ee,V,te;"use strict";var oe=Object.defineProperty,de=Object.defineProperties;var ce=Object.getOwnPropertyDescriptors;var z=Object.getOwnPropertySymbols;var he=Object.prototype.hasOwnProperty,le=Object.prototype.propertyIsEnumerable;var W=(d,a,c)=>a in d?oe(d,a,{enumerable:!0,configurable:!0,writable:!0,value:c}):d[a]=c,k=(d,a)=>{for(var c in a||(a={}))he.call(a,c)&&W(d,c,a[c]);if(z)for(var c of z(a))le.call(a,c)&&W(d,c,a[c]);return d},J=(d,a)=>de(d,ce(a));var u=(d,a,c)=>(W(d,typeof a!="symbol"?a+"":a,c),c),me=(d,a,c)=>{if(!a.has(d))throw TypeError("Cannot "+c)};var L=(d,a,c)=>{if(a.has(d))throw TypeError("Cannot add the same private member more than once");a instanceof WeakSet?a.add(d):a.set(d,c)};var E=(d,a,c)=>(me(d,a,"access private method"),c);var b=(d,a,c)=>new Promise((R,v)=>{var N=S=>{try{A(c.next(S))}catch(I){v(I)}},_=S=>{try{A(c.throw(S))}catch(I){v(I)}},A=S=>S.done?R(S.value):Promise.resolve(S.value).then(N,_);A((c=c.apply(d,a)).next())});class d{constructor(e){u(this,"target");u(this,"targetOrigin");u(this,"listeners");u(this,"onIncomingMessageBind",this.onIncomingMessage.bind(this));this.target=e.target,this.targetOrigin=e.targetOrigin,this.listeners=[],window.addEventListener("message",this.onIncomingMessageBind)}send(e){this.target.postMessage(e,this.targetOrigin)}onReceive(e){this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter(t=>t!==e)}onIncomingMessage(e){e.origin===this.targetOrigin&&this.listeners.forEach(t=>{t(e,this.send.bind(this))})}abortService(){window.removeEventListener("message",this.onIncomingMessageBind)}}function a(){var e;return(e=window.MONEYHASH_IFRAME_URL)!=null?e:"https://embed.moneyhash.io"}function c(){return typeof window!="undefined"}const P=class{constructor(){c()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=a(),t=new URL(`${e}/embed/headless-sdk`);t.searchParams.set("sdk","true"),t.searchParams.set("parent",window.location.origin),t.searchParams.set("version","js@1.1.0");const r=document.createElement("iframe");r.id="moneyhash-headless-sdk",r.src=t.toString(),r.hidden=!0,document.body.appendChild(r),P.messagingService=new d({target:r.contentWindow,targetOrigin:e}),P.isCommunicationReady=new Promise(i=>{var n;const o=s=>{var l;s.data.type==="headlessSDK:init"&&(i(),(l=P.messagingService)==null||l.removeListener(o))};(n=P.messagingService)==null||n.onReceive(o)})}request(r){return b(this,arguments,function*({api:e,payload:t}){return yield P.isCommunicationReady,new Promise((i,o)=>{var s,l;(s=P.messagingService)==null||s.send({type:e,data:t});const n=g=>{var f;const{type:h,data:m}=g.data;h===e&&(m.status==="resolved"?i(m.payload):o(m.payload),(f=P.messagingService)==null||f.removeListener(n))};(l=P.messagingService)==null||l.onReceive(n)})})}};let R=P;u(R,"messagingService",null),u(R,"isCommunicationReady");function v(p,e){if(p)throw new Error(e)}function N(p,e){p&&console.warn(e)}const _=new Set(["payment","payout"]),A=new Set(["en","fr","ar"]);class S{constructor(e){u(this,"options");u(this,"messagingService",null);u(this,"iframe",null);u(this,"isCommunicationReady",null);v(!_.has(e.type),`MoneyHash constructor must be called with valid type (${[..._].join(" | ")})!`),this.options=e}get lang(){var t;const e=(t=this.options.locale)==null?void 0:t.split("-")[0];return N(!!e&&!A.has(e),`Supported languages (${[...A].join(" | ")})`),e||"en"}render({selector:e,intentId:t}){var s,l;(s=this.messagingService)==null||s.abortService();const r=a(),i=new URL(`${r}/embed/${this.options.type}/${t}`);i.searchParams.set("sdk","true"),i.searchParams.set("parent",window.location.origin),i.searchParams.set("version","js@1.1.0");const o=(l=this.options.locale)==null?void 0:l.split("-")[0];o&&i.searchParams.set("lang",o),this.iframe=document.createElement("iframe"),this.iframe.src=i.toString(),this.iframe.style.height="100%",this.iframe.style.width="100%",this.iframe.style.border="0";const n=document.querySelector(e);return v(!n,`Couldn't find an element with selector ${e}!`),n.replaceChildren(this.iframe),this.messagingService=new d({target:this.iframe.contentWindow,targetOrigin:r}),this.isCommunicationReady=new Promise(g=>{var m;const h=f=>{var y;f.data.type==="sdk:init"&&(g(),(y=this.messagingService)==null||y.removeListener(h))};(m=this.messagingService)==null||m.onReceive(h)}),this.messagingService.onReceive((g,h)=>{var y,w,U,M;const{type:m,data:f}=g.data;switch(m){case"sdk:init":{h({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(w=(y=this.options).onComplete)==null||w.call(y,k({type:this.options.type},f)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{(M=(U=this.options).onFail)==null||M.call(U,k({type:this.options.type},f)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}}}),this.isCommunicationReady}setLocale(e){return b(this,null,function*(){var t;yield this==null?void 0:this.isCommunicationReady,this.options.locale=e,(t=this.messagingService)==null||t.send({type:"changeLanguage",data:{locale:e}})})}abortService(){return b(this,null,function*(){var e;yield this==null?void 0:this.isCommunicationReady,(e=this.messagingService)==null||e.abortService()})}}class I{constructor(){u(this,"promise");u(this,"resolve");u(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function ie(){var e;return(e=window.MONEYHASH_VAULT_API_URL)!=null?e:"https://vault.moneyhash.io"}function O(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function B(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}function re(p){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!p.includes(t))return t;return null}function ne(p){return(Array.isArray(p)?p.length:Object.keys(p).length)===0}function se(p,e){return new Promise((t,r)=>{if(document.getElementById(e)){t(void 0);return}const o=document.createElement("script");o.src=p,o.id=e,o.addEventListener("load",()=>{t(void 0)}),o.addEventListener("error",()=>{r(new Error("Script failed to load"))}),document.body.appendChild(o)})}const D=new Set(["method","customerBalance","savedCard"]);class ae{constructor(e){L(this,$);L(this,F);L(this,H);L(this,C);L(this,j);L(this,q);L(this,T);L(this,V);u(this,"options");u(this,"sdkApiHandler",new R);u(this,"sdkEmbed");u(this,"vaultSubmitListener",{current:null});u(this,"mountedCardElements",[]);this.options=e,this.sdkEmbed=new S(J(k({},e),{headless:!0})),E(this,q,Z).call(this,this.vaultSubmitListener)}getIntentDetails(e){return this.sdkApiHandler.request({api:"sdk:getIntentDetails",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}getIntentMethods(e){return this.sdkApiHandler.request({api:"sdk:getIntentMethods",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}proceedWith({intentId:e,type:t,id:r,metaData:i}){return v(!D.has(t),`type must be a valid one (${[...D].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:r,lang:this.sdkEmbed.lang,metaData:i}})}resetSelectedMethod(e){return this.sdkApiHandler.request({api:"sdk:resetSelectedMethod",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}deleteCard({cardId:e,intentSecret:t}){return v(this.options.type==="payout","deleteCard is allowed only for payment intent!"),this.sdkApiHandler.request({api:"sdk:deleteCard",payload:{cardId:e,intentSecret:t,lang:this.sdkEmbed.lang}})}payWithApplePay(g){return b(this,arguments,function*({intentId:e,currency:t,amount:r,countryCode:i,onCancel:o=()=>{},onError:n,onComplete:s,billingData:l={}}){if(yield se("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)return;const h=new ApplePaySession(3,{countryCode:i,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${r}`}}),{state:m,intent:f}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(m==="INTENT_FORM"){if(ne(l))throw new Error("Billing data is missing while calling payWithApplePay");yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"APPLE_PAY",lang:this.sdkEmbed.lang,billingData:l}})}}catch(y){throw yield this.resetSelectedMethod(e),y}h.onvalidatemerchant=y=>{fetch(`${B()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:f.secret,validation_url:y.validationURL})}).then(w=>w.ok?w.json():Promise.reject()).then(w=>h.completeMerchantValidation(w)).catch(n)},h.onpaymentauthorized=y=>{fetch(`${B()}/api/v1/providers/applepay/token/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({token_data:y.payment.token,secret:f.secret})}).then(w=>w.ok?w.json():Promise.reject()).then(()=>{h.completePayment(ApplePaySession.STATUS_SUCCESS),s()}).catch(()=>{h.completePayment(ApplePaySession.STATUS_FAILURE),n()})},h.oncancel=o,h.begin()})}renderForm({selector:e,intentId:t}){return v(!e,"selector is required for renderForm"),v(!t,"intentId is required for renderForm"),this.sdkEmbed.render({selector:e,intentId:t})}setLocale(e){return this.sdkEmbed.setLocale(e)}removeEventListeners(){return this.sdkEmbed.abortService()}elements({styles:e,classNames:t}){const r=[];return E(this,j,X).call(this,r),{create:({elementType:i,elementOptions:o})=>{const n=new Map,s=document.querySelector(o.selector);v(!s,`Couldn't find an element with selector ${o.selector}!`),s.classList.add("MoneyHashElement");const l=(t==null?void 0:t.focus)||"MoneyHashElement--focus",g=(t==null?void 0:t.error)||"MoneyHashElement--error";return r.push(h=>{var y,w,U,M,Y;const{type:m,data:f}=h.data;if(m===`${i}@focus`){s.classList.add(l),(y=n.get(`${i}@focus`))==null||y();return}if(m===`${i}@blur`){s.classList.remove(l),(w=n.get(`${i}@blur`))==null||w();return}if(m===`${i}@error`){f.isValid?s.classList.remove(g):s.classList.add(g),(U=n.get(`${i}@error`))==null||U(f);return}if(m===`${i}@changeInput`){(M=n.get(`${i}@changeInput`))==null||M();return}m===`${i}@cardNumberChange`&&((Y=n.get(`${i}@cardNumberChange`))==null||Y(f))}),{mount:()=>{this.mountedCardElements.push(i),E(this,T,ee).call(this,{container:s,elementType:i,elementOptions:o,styles:k(k({},e),o.styles)})},on:(h,m)=>{n.set(`${i}@${h}`,m)},off:h=>n.delete(`${i}@${h}`)}}}}submitForm(o){return b(this,arguments,function*({intentId:e,accessToken:t,billingData:r,shippingData:i}){const n=re(this.mountedCardElements);v(!!n,`You must mount ${n} element!`);const s=new I;let l,g;t&&(this.vaultSubmitListener.current=m=>{const{type:f,data:y}=m.data;f==="vaultSubmit:success"&&s.resolve(y),f==="vaultSubmit:error"&&s.reject(y)},g=E(this,V,te).call(this,t),l=yield s.promise);const h=yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"CARD",lang:this.sdkEmbed.lang,billingData:r,shippingData:i,cardEmbed:l}});return g&&g.remove(),h})}submitCvv(r){return b(this,arguments,function*({intentId:e,cvv:t}){return this.sdkApiHandler.request({api:"sdk:submitCardCvv",payload:{intentId:e,cvv:t,lang:this.sdkEmbed.lang}})})}renderUrl(e,t,r){return b(this,null,function*(){switch(t){case"IFRAME":return E(this,$,K).call(this,e);case"POPUP_IFRAME":return E(this,F,G).call(this,e);case"REDIRECT":return E(this,H,Q).call(this,e,r);default:return null}})}}return $=new WeakSet,K=function(e){return b(this,null,function*(){const t=document.querySelector("#rendered-url-iframe-container");v(!t,"Couldn't find an element with id rendered-url-iframe-container to render the iframe!");const r=document.createElement("iframe");r.src=e,r.style.setProperty("border","0","important"),r.style.setProperty("width","100%","important"),r.style.setProperty("height","100%","important"),t==null||t.replaceChildren(r),yield E(this,C,x).call(this),r.remove()})},F=new WeakSet,G=function(e){return b(this,null,function*(){const t=window.open(`${e}`,"","width=600,height=400,left=200,top=200");v(!t,"Popup blocked by browser!"),yield E(this,C,x).call(this),t==null||t.close()})},H=new WeakSet,Q=function(e,t){return b(this,null,function*(){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},C=new WeakSet,x=function(){return b(this,null,function*(){const e=new I,t=r=>{var n,s,l,g;const{type:i,data:o}=r.data;switch(i){case"onComplete":(s=(n=this.options).onComplete)==null||s.call(n,k({type:this.options.type},o)),e.resolve(()=>null),window.removeEventListener("message",t);break;case"onFail":(g=(l=this.options).onFail)==null||g.call(l,k({type:this.options.type},o)),e.resolve(()=>null),window.removeEventListener("message",t);break;default:e.resolve(()=>null);break}};return window.addEventListener("message",t),e.promise})},j=new WeakSet,X=function(e){const t=r=>{e.forEach(i=>{i(r)})};window.addEventListener("message",t)},q=new WeakSet,Z=function(e){const t=r=>{e.current&&e.current(r)};window.addEventListener("message",t)},T=new WeakSet,ee=function({container:e,elementType:t,elementOptions:r,styles:i}){var l,g,h,m;const o=O(),n=new URL(`${o}/vaultField/vaultField.html`);n.searchParams.set("host",btoa(window.location.origin)),n.searchParams.set("type",t),((l=r.validation)==null?void 0:l.required)!==void 0&&n.searchParams.set("required",`${(g=r.validation)==null?void 0:g.required}`),n.searchParams.set("placeholder",(h=r.placeholder)!=null?h:""),n.searchParams.set("lang",this.sdkEmbed.lang),n.searchParams.set("direction",(i==null?void 0:i.direction)||""),n.searchParams.set("color",(i==null?void 0:i.color)||"#000"),n.searchParams.set("placeholderColor",(i==null?void 0:i.placeholderColor)||"#ccc"),n.searchParams.set("backgroundColor",(i==null?void 0:i.backgroundColor)||"transparent"),n.searchParams.set("fontSize",(i==null?void 0:i.fontSize)||""),n.searchParams.set("padding",(i==null?void 0:i.padding)||"");const s=document.createElement("iframe");s.src=n.toString(),s.style.height=(m=i==null?void 0:i.height)!=null?m:"40px",s.style.setProperty("overflow","hidden","important"),s.style.setProperty("display","block","important"),s.style.setProperty("width","100%","important"),s.style.setProperty("maxWidth","100%","important"),s.style.setProperty("border","0","important"),s.style.setProperty("margin","0","important"),s.style.setProperty("padding","0","important"),s.style.setProperty("userSelect","none","important"),s.style.setProperty("colorScheme","light only","important"),e.replaceChildren(s)},V=new WeakSet,te=function(e){const t=O(),r=ie(),i=new URL(`${t}/vaultSubmit/vaultSubmit.html`);i.searchParams.set("host",btoa(window.location.origin)),i.searchParams.set("vault_api_url",`${r}/api/v1/tokens/`),i.searchParams.set("access_token",e),i.searchParams.set("lang",this.sdkEmbed.lang);const o=document.createElement("iframe");return o.id="moneyhash-submit-iframe",o.src=i.toString(),o.hidden=!0,document.body.appendChild(o),o},ae}); | ||
(function(d,a){typeof exports=="object"&&typeof module!="undefined"?module.exports=a():typeof define=="function"&&define.amd?define(a):(d=typeof globalThis!="undefined"?globalThis:d||self,d.MoneyHash=a())})(this,function(){var $,X,F,Z,N,ee,U,x,H,te,j,se,q,ie,T,re;"use strict";var le=Object.defineProperty,he=Object.defineProperties;var me=Object.getOwnPropertyDescriptors;var G=Object.getOwnPropertySymbols;var pe=Object.prototype.hasOwnProperty,ue=Object.prototype.propertyIsEnumerable;var W=(d,a,l)=>a in d?le(d,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):d[a]=l,E=(d,a)=>{for(var l in a||(a={}))pe.call(a,l)&&W(d,l,a[l]);if(G)for(var l of G(a))ue.call(a,l)&&W(d,l,a[l]);return d},Q=(d,a)=>he(d,me(a));var u=(d,a,l)=>(W(d,typeof a!="symbol"?a+"":a,l),l),ge=(d,a,l)=>{if(!a.has(d))throw TypeError("Cannot "+l)};var k=(d,a,l)=>{if(a.has(d))throw TypeError("Cannot add the same private member more than once");a instanceof WeakSet?a.add(d):a.set(d,l)};var S=(d,a,l)=>(ge(d,a,"access private method"),l);var b=(d,a,l)=>new Promise((R,w)=>{var V=L=>{try{A(l.next(L))}catch(I){w(I)}},_=L=>{try{A(l.throw(L))}catch(I){w(I)}},A=L=>L.done?R(L.value):Promise.resolve(L.value).then(V,_);A((l=l.apply(d,a)).next())});class d{constructor(e){u(this,"target");u(this,"targetOrigin");u(this,"listeners");u(this,"onIncomingMessageBind",this.onIncomingMessage.bind(this));this.target=e.target,this.targetOrigin=e.targetOrigin,this.listeners=[],window.addEventListener("message",this.onIncomingMessageBind)}send(e){this.target.postMessage(e,this.targetOrigin)}onReceive(e){this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter(t=>t!==e)}onIncomingMessage(e){e.origin===this.targetOrigin&&this.listeners.forEach(t=>{t(e,this.send.bind(this))})}abortService(){window.removeEventListener("message",this.onIncomingMessageBind)}}function a(){var e;return(e=window.MONEYHASH_IFRAME_URL)!=null?e:"https://embed.moneyhash.io"}function 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.1.1");const i=document.createElement("iframe");i.id="moneyhash-headless-sdk",i.src=t.toString(),i.hidden=!0,document.body.appendChild(i),P.messagingService=new d({target:i.contentWindow,targetOrigin:e}),P.isCommunicationReady=new Promise(s=>{var r;const o=n=>{var c;n.data.type==="headlessSDK:init"&&(s(),(c=P.messagingService)==null||c.removeListener(o))};(r=P.messagingService)==null||r.onReceive(o)})}request(i){return b(this,arguments,function*({api:e,payload:t}){return yield P.isCommunicationReady,new Promise((s,o)=>{var n,c;(n=P.messagingService)==null||n.send({type:e,data:t});const r=g=>{var v;const{type:h,data:f}=g.data;h===e&&(f.status==="resolved"?s(f.payload):o(f.payload),(v=P.messagingService)==null||v.removeListener(r))};(c=P.messagingService)==null||c.onReceive(r)})})}};let R=P;u(R,"messagingService",null),u(R,"isCommunicationReady");function w(p,e){if(p)throw new Error(e)}function V(p,e){p&&console.warn(e)}const _=new Set(["payment","payout"]),A=new Set(["en","fr","ar"]);class L{constructor(e){u(this,"options");u(this,"messagingService",null);u(this,"iframe",null);u(this,"isCommunicationReady",null);w(!_.has(e.type),`MoneyHash constructor must be called with valid type (${[..._].join(" | ")})!`),this.options=e}get lang(){var t;const e=(t=this.options.locale)==null?void 0:t.split("-")[0];return V(!!e&&!A.has(e),`Supported languages (${[...A].join(" | ")})`),e||"en"}render({selector:e,intentId:t}){var n,c;(n=this.messagingService)==null||n.abortService();const i=a(),s=new URL(`${i}/embed/${this.options.type}/${t}`);s.searchParams.set("sdk","true"),s.searchParams.set("parent",window.location.origin),s.searchParams.set("version","js@1.1.1");const o=(c=this.options.locale)==null?void 0:c.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 d({target:this.iframe.contentWindow,targetOrigin:i}),this.isCommunicationReady=new Promise(g=>{var f;const h=v=>{var m;v.data.type==="sdk:init"&&(g(),(m=this.messagingService)==null||m.removeListener(h))};(f=this.messagingService)==null||f.onReceive(h)}),this.messagingService.onReceive((g,h)=>{var m,y,C,M;const{type:f,data:v}=g.data;switch(f){case"sdk:init":{h({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(y=(m=this.options).onComplete)==null||y.call(m,E({type:this.options.type},v)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{(M=(C=this.options).onFail)==null||M.call(C,E({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 I{constructor(){u(this,"promise");u(this,"resolve");u(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function ne(){var e;return(e=window.MONEYHASH_VAULT_API_URL)!=null?e:"https://vault.moneyhash.io"}function B(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function D(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}function ae(p){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!p.includes(t))return t;return null}function oe(p){return(Array.isArray(p)?p.length:Object.keys(p).length)===0}function de(p,e){return new Promise((t,i)=>{if(document.getElementById(e)){t(void 0);return}const o=document.createElement("script");o.src=p,o.id=e,o.addEventListener("load",()=>{t(void 0)}),o.addEventListener("error",()=>{i(new Error("Script failed to load"))}),document.body.appendChild(o)})}const O=new Set(["method","customerBalance","savedCard"]);class ce{constructor(e){k(this,$);k(this,F);k(this,N);k(this,U);k(this,H);k(this,j);k(this,q);k(this,T);u(this,"options");u(this,"sdkApiHandler",new R);u(this,"sdkEmbed");u(this,"vaultSubmitListener",{current:null});u(this,"mountedCardElements",[]);this.options=e,this.sdkEmbed=new L(Q(E({},e),{headless:!0})),S(this,j,se).call(this,this.vaultSubmitListener)}getIntentDetails(e){return this.sdkApiHandler.request({api:"sdk:getIntentDetails",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}getIntentMethods(e){return this.sdkApiHandler.request({api:"sdk:getIntentMethods",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}proceedWith({intentId:e,type:t,id:i,metaData:s}){return w(!O.has(t),`type must be a valid one (${[...O].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:i,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(g){return b(this,arguments,function*({intentId:e,currency:t,amount:i,countryCode:s,onCancel:o=()=>{},onError:r,onComplete:n,billingData:c={}}){if(yield de("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)return;const h=new ApplePaySession(3,{countryCode:s,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${i}`}}),{state:f,intent:v}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(f==="INTENT_FORM"){if(oe(c))throw new Error("Billing data is missing while calling payWithApplePay");yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"APPLE_PAY",lang:this.sdkEmbed.lang,billingData:c}})}}catch(m){throw yield this.resetSelectedMethod(e),m}h.onvalidatemerchant=m=>{fetch(`${D()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:v.secret,validation_url:m.validationURL})}).then(y=>y.ok?y.json():Promise.reject()).then(y=>h.completeMerchantValidation(y)).catch(r)},h.onpaymentauthorized=m=>{fetch(`${D()}/api/v1/providers/applepay/token/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({token_data:m.payment.token,secret:v.secret})}).then(y=>y.ok?y.json():Promise.reject()).then(()=>{h.completePayment(ApplePaySession.STATUS_SUCCESS),n()}).catch(()=>{h.completePayment(ApplePaySession.STATUS_FAILURE),r()})},h.oncancel=o,h.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){return this.sdkEmbed.setLocale(e)}removeEventListeners(){return this.sdkEmbed.abortService()}elements({styles:e,classes:t}){const i=[];return S(this,H,te).call(this,i),{create:({elementType:s,elementOptions:o})=>{var f,v;const r=new Map,n=document.querySelector(o.selector);w(!n,`Couldn't find an element with selector ${o.selector}!`),n.classList.add("MoneyHashElement");const c=E(E({},t),o.classes),g=((f=c==null?void 0:c.focus)==null?void 0:f.split(" "))||["MoneyHashElement--focus"],h=((v=c==null?void 0:c.error)==null?void 0:v.split(" "))||["MoneyHashElement--error"];return i.push(m=>{var M,Y,z,J,K;const{type:y,data:C}=m.data;if(y===`${s}@focus`){n.classList.add(...g),(M=r.get(`${s}@focus`))==null||M();return}if(y===`${s}@blur`){n.classList.remove(...g),(Y=r.get(`${s}@blur`))==null||Y();return}if(y===`${s}@error`){C.isValid?n.classList.remove(...h):n.classList.add(...h),(z=r.get(`${s}@error`))==null||z(C);return}if(y===`${s}@changeInput`){(J=r.get(`${s}@changeInput`))==null||J();return}y===`${s}@cardNumberChange`&&((K=r.get(`${s}@cardNumberChange`))==null||K(C))}),{mount:()=>{this.mountedCardElements.push(s),S(this,q,ie).call(this,{container:n,elementType:s,elementOptions:o,styles:E(E({},e),o.styles)})},on:(m,y)=>{r.set(`${s}@${m}`,y)},off:m=>r.delete(`${s}@${m}`)}}}}submitForm(o){return b(this,arguments,function*({intentId:e,accessToken:t,billingData:i,shippingData:s}){const r=ae(this.mountedCardElements);w(!!r,`You must mount ${r} element!`);const n=new I;let c,g;t&&(this.vaultSubmitListener.current=f=>{const{type:v,data:m}=f.data;v==="vaultSubmit:success"&&n.resolve(m),v==="vaultSubmit:error"&&n.reject(m)},g=S(this,T,re).call(this,t),c=yield n.promise);const h=yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"CARD",lang:this.sdkEmbed.lang,billingData:i,shippingData:s,cardEmbed:c}});return g&&g.remove(),h})}submitCvv(i){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,i){return b(this,null,function*(){switch(t){case"IFRAME":return S(this,$,X).call(this,e);case"POPUP_IFRAME":return S(this,F,Z).call(this,e);case"REDIRECT":return S(this,N,ee).call(this,e,i);default:return null}})}}return $=new WeakSet,X=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 i=document.createElement("iframe");i.src=e,i.style.setProperty("border","0","important"),i.style.setProperty("width","100%","important"),i.style.setProperty("height","100%","important"),t==null||t.replaceChildren(i),yield S(this,U,x).call(this),i.remove()})},F=new WeakSet,Z=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,U,x).call(this),t==null||t.close()})},N=new WeakSet,ee=function(e,t){return b(this,null,function*(){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},U=new WeakSet,x=function(){return b(this,null,function*(){const e=new I,t=i=>{var r,n,c,g;const{type:s,data:o}=i.data;switch(s){case"onComplete":(n=(r=this.options).onComplete)==null||n.call(r,E({type:this.options.type},o)),e.resolve(()=>null),window.removeEventListener("message",t);break;case"onFail":(g=(c=this.options).onFail)==null||g.call(c,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})},H=new WeakSet,te=function(e){const t=i=>{e.forEach(s=>{s(i)})};window.addEventListener("message",t)},j=new WeakSet,se=function(e){const t=i=>{e.current&&e.current(i)};window.addEventListener("message",t)},q=new WeakSet,ie=function({container:e,elementType:t,elementOptions:i,styles:s}){var c,g,h,f;const o=B(),r=new URL(`${o}/vaultField/vaultField.html`);r.searchParams.set("host",btoa(window.location.origin)),r.searchParams.set("type",t),((c=i.validation)==null?void 0:c.required)!==void 0&&r.searchParams.set("required",`${(g=i.validation)==null?void 0:g.required}`),r.searchParams.set("placeholder",(h=i.placeholder)!=null?h:""),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 n=document.createElement("iframe");n.src=r.toString(),n.style.height=(f=s==null?void 0:s.height)!=null?f:"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)},T=new WeakSet,re=function(e){const t=B(),i=ne(),s=new URL(`${t}/vaultSubmit/vaultSubmit.html`);s.searchParams.set("host",btoa(window.location.origin)),s.searchParams.set("vault_api_url",`${i}/api/v1/tokens/`),s.searchParams.set("access_token",e),s.searchParams.set("lang",this.sdkEmbed.lang);const o=document.createElement("iframe");return o.id="moneyhash-submit-iframe",o.src=s.toString(),o.hidden=!0,document.body.appendChild(o),o},ce}); |
@@ -1,1 +0,1 @@ | ||
"use strict";var o=Object.defineProperty;var i=(s,e,r)=>e in s?o(s,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):s[e]=r;var t=(s,e,r)=>(i(s,typeof e!="symbol"?e+"":e,r),r);const d=require("./sdkEmbed-2ce660d7.cjs");class n{constructor(e){t(this,"options");t(this,"sdkEmbed");this.options=e,this.sdkEmbed=new d.SDKEmbed(e)}start({selector:e,intentId:r}){return d.throwIf(!e,"selector is required for start"),d.throwIf(!r,"intentId is required for start"),this.sdkEmbed.render({selector:e,intentId:r})}setLocale(e){return this.sdkEmbed.setLocale(e)}removeEventListeners(){return this.sdkEmbed.abortService()}}module.exports=n; | ||
"use strict";var o=Object.defineProperty;var i=(s,e,r)=>e in s?o(s,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):s[e]=r;var t=(s,e,r)=>(i(s,typeof e!="symbol"?e+"":e,r),r);const d=require("./sdkEmbed-0ff1d36a.cjs");class n{constructor(e){t(this,"options");t(this,"sdkEmbed");this.options=e,this.sdkEmbed=new d.SDKEmbed(e)}start({selector:e,intentId:r}){return d.throwIf(!e,"selector is required for start"),d.throwIf(!r,"intentId is required for start"),this.sdkEmbed.render({selector:e,intentId:r})}setLocale(e){return this.sdkEmbed.setLocale(e)}removeEventListeners(){return this.sdkEmbed.abortService()}}module.exports=n; |
var o = Object.defineProperty; | ||
var i = (s, e, r) => e in s ? o(s, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : s[e] = r; | ||
var t = (s, e, r) => (i(s, typeof e != "symbol" ? e + "" : e, r), r); | ||
import { S as a, t as d } from "./sdkEmbed-f5156d5c.js"; | ||
import { S as a, t as d } from "./sdkEmbed-2c378aeb.js"; | ||
class b { | ||
@@ -6,0 +6,0 @@ constructor(e) { |
@@ -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((p,o)=>{var m=n=>{try{h(t.next(n))}catch(e){o(e)}},f=n=>{try{h(t.throw(n))}catch(e){o(e)}},h=n=>n.done?p(n.value):Promise.resolve(n.value).then(m,f);h((t=t.apply(i,s)).next())});class i{constructor(e){a(this,"target");a(this,"targetOrigin");a(this,"listeners");a(this,"onIncomingMessageBind",this.onIncomingMessage.bind(this));this.target=e.target,this.targetOrigin=e.targetOrigin,this.listeners=[],window.addEventListener("message",this.onIncomingMessageBind)}send(e){this.target.postMessage(e,this.targetOrigin)}onReceive(e){this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter(r=>r!==e)}onIncomingMessage(e){e.origin===this.targetOrigin&&this.listeners.forEach(r=>{r(e,this.send.bind(this))})}abortService(){window.removeEventListener("message",this.onIncomingMessageBind)}}function s(){var e;return(e=window.MONEYHASH_IFRAME_URL)!=null?e:"https://embed.moneyhash.io"}function t(n,e){if(n)throw new Error(e)}function p(n,e){n&&console.warn(e)}const o=new Set(["payment","payout"]),m=new Set(["en","fr","ar"]);class f{constructor(e){a(this,"options");a(this,"messagingService",null);a(this,"iframe",null);a(this,"isCommunicationReady",null);t(!o.has(e.type),`MoneyHash constructor must be called with valid type (${[...o].join(" | ")})!`),this.options=e}get lang(){var r;const e=(r=this.options.locale)==null?void 0:r.split("-")[0];return p(!!e&&!m.has(e),`Supported languages (${[...m].join(" | ")})`),e||"en"}render({selector:e,intentId:r}){var L,M;(L=this.messagingService)==null||L.abortService();const S=s(),c=new URL(`${S}/embed/${this.options.type}/${r}`);c.searchParams.set("sdk","true"),c.searchParams.set("parent",window.location.origin),c.searchParams.set("version","js@1.1.0");const R=(M=this.options.locale)==null?void 0:M.split("-")[0];R&&c.searchParams.set("lang",R),this.iframe=document.createElement("iframe"),this.iframe.src=c.toString(),this.iframe.style.height="100%",this.iframe.style.width="100%",this.iframe.style.border="0";const E=document.querySelector(e);return t(!E,`Couldn't find an element with selector ${e}!`),E.replaceChildren(this.iframe),this.messagingService=new i({target:this.iframe.contentWindow,targetOrigin:S}),this.isCommunicationReady=new Promise(y=>{var l;const g=u=>{var d;u.data.type==="sdk:init"&&(y(),(d=this.messagingService)==null||d.removeListener(g))};(l=this.messagingService)==null||l.onReceive(g)}),this.messagingService.onReceive((y,g)=>{var d,k,I,C;const{type:l,data:u}=y.data;switch(l){case"sdk:init":{g({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(k=(d=this.options).onComplete)==null||k.call(d,w({type:this.options.type},u)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{(C=(I=this.options).onFail)==null||C.call(I,w({type:this.options.type},u)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}}}),this.isCommunicationReady}setLocale(e){return b(this,null,function*(){var r;yield this==null?void 0:this.isCommunicationReady,this.options.locale=e,(r=this.messagingService)==null||r.send({type:"changeLanguage",data:{locale:e}})})}abortService(){return b(this,null,function*(){var e;yield this==null?void 0:this.isCommunicationReady,(e=this.messagingService)==null||e.abortService()})}}class h{constructor(e){a(this,"options");a(this,"sdkEmbed");this.options=e,this.sdkEmbed=new f(e)}start({selector:e,intentId:r}){return t(!e,"selector is required for start"),t(!r,"intentId is required for start"),this.sdkEmbed.render({selector:e,intentId:r})}setLocale(e){return this.sdkEmbed.setLocale(e)}removeEventListeners(){return this.sdkEmbed.abortService()}}return h}); | ||
(function(i,s){typeof exports=="object"&&typeof module!="undefined"?module.exports=s():typeof define=="function"&&define.amd?define(s):(i=typeof globalThis!="undefined"?globalThis:i||self,i.MoneyHash=s())})(this,function(){"use strict";var F=Object.defineProperty;var O=Object.getOwnPropertySymbols;var U=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable;var v=(i,s,t)=>s in i?F(i,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[s]=t,w=(i,s)=>{for(var t in s||(s={}))U.call(s,t)&&v(i,t,s[t]);if(O)for(var t of O(s))$.call(s,t)&&v(i,t,s[t]);return i};var a=(i,s,t)=>(v(i,typeof s!="symbol"?s+"":s,t),t);var b=(i,s,t)=>new Promise((p,o)=>{var m=n=>{try{h(t.next(n))}catch(e){o(e)}},f=n=>{try{h(t.throw(n))}catch(e){o(e)}},h=n=>n.done?p(n.value):Promise.resolve(n.value).then(m,f);h((t=t.apply(i,s)).next())});class i{constructor(e){a(this,"target");a(this,"targetOrigin");a(this,"listeners");a(this,"onIncomingMessageBind",this.onIncomingMessage.bind(this));this.target=e.target,this.targetOrigin=e.targetOrigin,this.listeners=[],window.addEventListener("message",this.onIncomingMessageBind)}send(e){this.target.postMessage(e,this.targetOrigin)}onReceive(e){this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter(r=>r!==e)}onIncomingMessage(e){e.origin===this.targetOrigin&&this.listeners.forEach(r=>{r(e,this.send.bind(this))})}abortService(){window.removeEventListener("message",this.onIncomingMessageBind)}}function s(){var e;return(e=window.MONEYHASH_IFRAME_URL)!=null?e:"https://embed.moneyhash.io"}function t(n,e){if(n)throw new Error(e)}function p(n,e){n&&console.warn(e)}const o=new Set(["payment","payout"]),m=new Set(["en","fr","ar"]);class f{constructor(e){a(this,"options");a(this,"messagingService",null);a(this,"iframe",null);a(this,"isCommunicationReady",null);t(!o.has(e.type),`MoneyHash constructor must be called with valid type (${[...o].join(" | ")})!`),this.options=e}get lang(){var r;const e=(r=this.options.locale)==null?void 0:r.split("-")[0];return p(!!e&&!m.has(e),`Supported languages (${[...m].join(" | ")})`),e||"en"}render({selector:e,intentId:r}){var L,M;(L=this.messagingService)==null||L.abortService();const S=s(),c=new URL(`${S}/embed/${this.options.type}/${r}`);c.searchParams.set("sdk","true"),c.searchParams.set("parent",window.location.origin),c.searchParams.set("version","js@1.1.1");const R=(M=this.options.locale)==null?void 0:M.split("-")[0];R&&c.searchParams.set("lang",R),this.iframe=document.createElement("iframe"),this.iframe.src=c.toString(),this.iframe.style.height="100%",this.iframe.style.width="100%",this.iframe.style.border="0";const E=document.querySelector(e);return t(!E,`Couldn't find an element with selector ${e}!`),E.replaceChildren(this.iframe),this.messagingService=new i({target:this.iframe.contentWindow,targetOrigin:S}),this.isCommunicationReady=new Promise(y=>{var l;const g=u=>{var d;u.data.type==="sdk:init"&&(y(),(d=this.messagingService)==null||d.removeListener(g))};(l=this.messagingService)==null||l.onReceive(g)}),this.messagingService.onReceive((y,g)=>{var d,k,I,C;const{type:l,data:u}=y.data;switch(l){case"sdk:init":{g({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(k=(d=this.options).onComplete)==null||k.call(d,w({type:this.options.type},u)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{(C=(I=this.options).onFail)==null||C.call(I,w({type:this.options.type},u)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}}}),this.isCommunicationReady}setLocale(e){return b(this,null,function*(){var r;yield this==null?void 0:this.isCommunicationReady,this.options.locale=e,(r=this.messagingService)==null||r.send({type:"changeLanguage",data:{locale:e}})})}abortService(){return b(this,null,function*(){var e;yield this==null?void 0:this.isCommunicationReady,(e=this.messagingService)==null||e.abortService()})}}class h{constructor(e){a(this,"options");a(this,"sdkEmbed");this.options=e,this.sdkEmbed=new f(e)}start({selector:e,intentId:r}){return t(!e,"selector is required for start"),t(!r,"intentId is required for start"),this.sdkEmbed.render({selector:e,intentId:r})}setLocale(e){return this.sdkEmbed.setLocale(e)}removeEventListeners(){return this.sdkEmbed.abortService()}}return h}); |
{ | ||
"name": "@moneyhash/js-sdk", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "MoneyHash JavaScript SDK", | ||
@@ -5,0 +5,0 @@ "type": "module", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
362510
2136