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