@moneyhash/js-sdk
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -1,1 +0,1 @@ | ||
"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; | ||
"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-f3e40f38.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.2");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; |
@@ -86,3 +86,8 @@ export declare interface AbstractIntent { | ||
mount: () => void; | ||
on<T extends ElementEvents>(event: T, callback: (data: T extends "cardNumberChange" ? CardNumberChangeData : never) => void): void; | ||
on<T extends Extract<ElementEvents, "cardNumberChange">>(event: T, callback: (data: CardNumberChangeData) => void): void; | ||
on<T extends Extract<ElementEvents, "error">>(event: T, callback: (data: { | ||
isValid: boolean; | ||
error: string | null; | ||
}) => void): void; | ||
on<T extends Exclude<ElementEvents, "cardNumberChange" | "error">>(event: T, callback: () => void): void; | ||
off: (event: ElementEvents) => boolean; | ||
@@ -89,0 +94,0 @@ }; |
@@ -39,3 +39,3 @@ var X = Object.defineProperty, Z = Object.defineProperties; | ||
}); | ||
import { M as ne, g as se, S as ie, t as b } from "./sdkEmbed-2c378aeb.js"; | ||
import { M as ne, g as se, S as ie, t as b } from "./sdkEmbed-e0041728.js"; | ||
function oe() { | ||
@@ -52,3 +52,3 @@ return typeof window != "undefined"; | ||
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"); | ||
t.searchParams.set("sdk", "true"), t.searchParams.set("parent", window.location.origin), t.searchParams.set("version", "js@1.1.2"); | ||
const a = document.createElement("iframe"); | ||
@@ -55,0 +55,0 @@ a.id = "moneyhash-headless-sdk", a.src = t.toString(), a.hidden = !0, document.body.appendChild(a), v.messagingService = new ne({ |
@@ -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 $,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}); | ||
(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.2");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.2");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-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; | ||
"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-f3e40f38.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-2c378aeb.js"; | ||
import { S as a, t as d } from "./sdkEmbed-e0041728.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.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}); | ||
(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.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 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.1", | ||
"version": "1.1.2", | ||
"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
362773
2141