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