Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@moneyhash/js-sdk

Package Overview
Dependencies
Maintainers
0
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@moneyhash/js-sdk - npm Package Compare versions

Comparing version 1.1.2 to 1.2.0

dist/warnIf-2e22d8b1.js

2

dist/headless.cjs.js

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

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

@@ -11,3 +11,3 @@ export declare interface AbstractIntent {

subtotalAmount: string | null;
fees: Array<FeesItem> | null;
fees: Array<Fee> | null;
totalDiscounts: string | null;

@@ -50,2 +50,3 @@ secret: string;

logo: string;
first6Digits: string;
last4: string;

@@ -86,2 +87,8 @@ expiryMonth: string;

export declare interface Discount {
title: Record<SupportedLanguages, string>;
type: "amount" | "percentage";
value: string | number;
}
declare type Element_2 = {

@@ -118,2 +125,5 @@ mount: () => void;

create: (elementProps: ElementProps) => Element_2;
on: (event: FormEvents, callback: (data: {
isValid: boolean;
}) => void) => void;
};

@@ -143,5 +153,5 @@

export declare interface FeesItem {
export declare interface Fee {
title: Record<SupportedLanguages, string>;
value: string;
value: string | number;
}

@@ -174,2 +184,4 @@

declare type FormEvents = "validityChange";
export declare type FormField = {

@@ -499,2 +511,40 @@ choices?: Record<string, string> | null;

/**
* Update the intent discount
*
* @description Can be used for updating discount on the intent level
*
* @example
* ```
* await moneyHash.updateIntentDiscount({
* intentId: '<intent_id>',
* discount: Discount,
* });
* ```
*
* @returns Promise<{@link IntentDetails}>
*/
updateIntentDiscount({ intentId, discount, }: {
intentId: string;
discount: Discount;
}): Promise<IntentDetails<TType>>;
/**
* Update the intent fees
*
* @description Can be used for updating intent fees
*
* @example
* ```
* await moneyHash.updateIntentFees({
* intentId: '<intent_id>',
* fees: Array<Fee>,
* });
* ```
*
* @returns Promise<{@link IntentDetails}>
*/
updateIntentFees({ intentId, fees }: {
intentId: string;
fees: Array<Fee>;
}): Promise<IntentDetails<TType>>;
/**
* Creates Elements context used to render each card field

@@ -526,3 +576,3 @@ * @description Elements context is used to create and manage card fields

*/
submitForm({ intentId, accessToken, billingData, shippingData, }: {
submitForm({ intentId, accessToken, billingData, shippingData, saveCard, }: {
intentId: string;

@@ -532,2 +582,3 @@ accessToken?: string | null;

shippingData?: Record<string, unknown>;
saveCard?: boolean;
}): Promise<IntentDetails<TType>>;

@@ -534,0 +585,0 @@ /**

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

var X = Object.defineProperty, Z = Object.defineProperties;
var ee = Object.getOwnPropertyDescriptors;
var T = Object.getOwnPropertySymbols;
var te = Object.prototype.hasOwnProperty, re = Object.prototype.propertyIsEnumerable;
var M = (i, e, t) => e in i ? X(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, P = (i, e) => {
var se = Object.defineProperty, ne = Object.defineProperties;
var ie = Object.getOwnPropertyDescriptors;
var z = Object.getOwnPropertySymbols;
var oe = Object.prototype.hasOwnProperty, de = Object.prototype.propertyIsEnumerable;
var V = (i, e, t) => e in i ? se(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, P = (i, e) => {
for (var t in e || (e = {}))
te.call(e, t) && M(i, t, e[t]);
if (T)
for (var t of T(e))
re.call(e, t) && M(i, t, e[t]);
oe.call(e, t) && V(i, t, e[t]);
if (z)
for (var t of z(e))
de.call(e, t) && V(i, t, e[t]);
return i;
}, j = (i, e) => Z(i, ee(e));
var g = (i, e, t) => (M(i, typeof e != "symbol" ? e + "" : e, t), t), ae = (i, e, t) => {
}, O = (i, e) => ne(i, ie(e));
var h = (i, e, t) => (V(i, typeof e != "symbol" ? e + "" : e, t), t), ce = (i, e, t) => {
if (!e.has(i))

@@ -22,21 +22,21 @@ throw TypeError("Cannot " + t);

};
var f = (i, e, t) => (ae(i, e, "access private method"), t);
var y = (i, e, t) => new Promise((a, r) => {
var f = (i, e, t) => (ce(i, e, "access private method"), t);
var y = (i, e, t) => new Promise((s, a) => {
var d = (o) => {
try {
n(t.next(o));
} catch (c) {
r(c);
r(t.next(o));
} catch (l) {
a(l);
}
}, s = (o) => {
}, n = (o) => {
try {
n(t.throw(o));
} catch (c) {
r(c);
r(t.throw(o));
} catch (l) {
a(l);
}
}, n = (o) => o.done ? a(o.value) : Promise.resolve(o.value).then(d, s);
n((t = t.apply(i, e)).next());
}, r = (o) => o.done ? s(o.value) : Promise.resolve(o.value).then(d, n);
r((t = t.apply(i, e)).next());
});
import { M as ne, g as se, S as ie, t as b } from "./sdkEmbed-e0041728.js";
function oe() {
import { M as le, g as me, S as pe, t as E, w as ue, s as N } from "./warnIf-2e22d8b1.js";
function he() {
return typeof window != "undefined";

@@ -46,3 +46,3 @@ }

constructor() {
oe() && this.initSDKCommunicationIframe();
he() && this.initSDKCommunicationIframe();
}

@@ -52,18 +52,18 @@ initSDKCommunicationIframe() {

return;
const e = se(), t = new URL(`${e}/embed/headless-sdk`);
t.searchParams.set("sdk", "true"), t.searchParams.set("parent", window.location.origin), t.searchParams.set("version", "js@1.1.2");
const a = document.createElement("iframe");
a.id = "moneyhash-headless-sdk", a.src = t.toString(), a.hidden = !0, document.body.appendChild(a), v.messagingService = new ne({
target: a.contentWindow,
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.0");
const s = document.createElement("iframe");
s.id = "moneyhash-headless-sdk", s.src = t.toString(), s.hidden = !0, document.body.appendChild(s), v.messagingService = new le({
target: s.contentWindow,
targetOrigin: e
}), v.isCommunicationReady = new Promise((r) => {
var s;
const d = (n) => {
}), v.isCommunicationReady = new Promise((a) => {
var n;
const d = (r) => {
var o;
n.data.type === "headlessSDK:init" && (r(), (o = v.messagingService) == null || o.removeListener(d));
r.data.type === "headlessSDK:init" && (a(), (o = v.messagingService) == null || o.removeListener(d));
};
(s = v.messagingService) == null || s.onReceive(d);
(n = v.messagingService) == null || n.onReceive(d);
});
}
request(a) {
request(s) {
return y(this, arguments, function* ({

@@ -73,14 +73,14 @@ api: e,

}) {
return yield v.isCommunicationReady, new Promise((r, d) => {
var n, o;
(n = v.messagingService) == null || n.send({
return yield v.isCommunicationReady, new Promise((a, d) => {
var r, o;
(r = v.messagingService) == null || r.send({
type: e,
data: t
});
const s = (c) => {
var u;
const { type: l, data: h } = c.data;
l === e && (h.status === "resolved" ? r(h.payload) : d(h.payload), (u = v.messagingService) == null || u.removeListener(s));
const n = (l) => {
var g;
const { type: c, data: m } = l.data;
c === e && (m.status === "resolved" ? a(m.payload) : d(m.payload), (g = v.messagingService) == null || g.removeListener(n));
};
(o = v.messagingService) == null || o.onReceive(s);
(o = v.messagingService) == null || o.onReceive(n);
});

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

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

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

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

@@ -128,7 +128,7 @@ "cardNumber",

}
function le(i) {
function ye(i) {
return (Array.isArray(i) ? i.length : Object.keys(i).length) === 0;
}
function me(i, e) {
return new Promise((t, a) => {
function ve(i, e) {
return new Promise((t, s) => {
if (document.getElementById(e)) {

@@ -142,7 +142,7 @@ t(void 0);

}), d.addEventListener("error", () => {
a(new Error("Script failed to load"));
s(new Error("Script failed to load"));
}), document.body.appendChild(d);
});
}
const Y = /* @__PURE__ */ new Set([
const G = /* @__PURE__ */ new Set([
"method",

@@ -152,21 +152,21 @@ "customerBalance",

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

@@ -262,8 +262,8 @@ /**

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

@@ -277,5 +277,5 @@ )})`

intentId: e,
id: a,
id: s,
lang: this.sdkEmbed.lang,
metaData: r
metaData: a
}

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

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

@@ -377,15 +377,15 @@ "deleteCard is allowed only for payment intent!"

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

@@ -395,4 +395,4 @@ "moneyHash-apple-pay-sdk"

return;
const l = new ApplePaySession(3, {
countryCode: r,
const c = new ApplePaySession(3, {
countryCode: a,
currencyCode: t,

@@ -404,5 +404,5 @@ supportedNetworks: ["visa", "masterCard", "amex", "discover", "mada"],

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

@@ -413,4 +413,4 @@ type: "method",

try {
if (h === "INTENT_FORM") {
if (le(o))
if (m === "INTENT_FORM") {
if (ye(o))
throw new Error(

@@ -429,7 +429,7 @@ "Billing data is missing while calling payWithApplePay"

}
} catch (p) {
throw yield this.resetSelectedMethod(e), p;
} catch (u) {
throw yield this.resetSelectedMethod(e), u;
}
l.onvalidatemerchant = (p) => {
fetch(`${D()}/api/v1/providers/applepay/session/`, {
c.onvalidatemerchant = (u) => {
fetch(`${K()}/api/v1/providers/applepay/session/`, {
method: "post",

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

body: JSON.stringify({
secret: u.secret,
validation_url: p.validationURL
secret: g.secret,
validation_url: u.validationURL
})
}).then((m) => m.ok ? m.json() : Promise.reject()).then(
(m) => l.completeMerchantValidation(m)
).catch(s);
}, l.onpaymentauthorized = (p) => {
fetch(`${D()}/api/v1/providers/applepay/token/`, {
}).then((p) => p.ok ? p.json() : Promise.reject()).then(
(p) => c.completeMerchantValidation(p)
).catch(n);
}, c.onpaymentauthorized = (u) => {
fetch(`${K()}/api/v1/providers/applepay/token/`, {
method: "post",

@@ -454,11 +454,11 @@ headers: {

body: JSON.stringify({
token_data: p.payment.token,
secret: u.secret
token_data: u.payment.token,
secret: g.secret
})
}).then((m) => m.ok ? m.json() : Promise.reject()).then(() => {
l.completePayment(ApplePaySession.STATUS_SUCCESS), n();
}).then((p) => p.ok ? p.json() : Promise.reject()).then(() => {
c.completePayment(ApplePaySession.STATUS_SUCCESS), r();
}).catch(() => {
l.completePayment(ApplePaySession.STATUS_FAILURE), s();
c.completePayment(ApplePaySession.STATUS_FAILURE), n();
});
}, l.oncancel = d, l.begin();
}, c.oncancel = d, c.begin();
});

@@ -483,3 +483,3 @@ }

renderForm({ selector: e, intentId: t }) {
return b(!e, "selector is required for renderForm"), b(!t, "intentId is required for renderForm"), this.sdkEmbed.render({ selector: e, intentId: t });
return E(!e, "selector is required for renderForm"), E(!t, "intentId is required for renderForm"), this.sdkEmbed.render({ selector: e, intentId: t });
}

@@ -499,3 +499,10 @@ /**

setLocale(e) {
return this.sdkEmbed.setLocale(e);
ue(
!!e && !N.has(e),
`Invalid locale. Supported languages (${[...N].join(
" | "
)})`
);
const t = N.has(e) ? e : "en";
return this.sdkEmbed.setLocale(t);
}

@@ -510,2 +517,55 @@ /**

/**
* Update the intent discount
*
* @description Can be used for updating discount on the intent level
*
* @example
* ```
* await moneyHash.updateIntentDiscount({
* intentId: '<intent_id>',
* discount: Discount,
* });
* ```
*
* @returns Promise<{@link IntentDetails}>
*/
updateIntentDiscount({
intentId: e,
discount: t
}) {
return this.sdkApiHandler.request({
api: "sdk:updateIntentDiscount",
payload: {
intentId: e,
discount: t,
lang: this.sdkEmbed.lang
}
});
}
/**
* Update the intent fees
*
* @description Can be used for updating intent fees
*
* @example
* ```
* await moneyHash.updateIntentFees({
* intentId: '<intent_id>',
* fees: Array<Fee>,
* });
* ```
*
* @returns Promise<{@link IntentDetails}>
*/
updateIntentFees({ intentId: e, fees: t }) {
return this.sdkApiHandler.request({
api: "sdk:updateIntentFees",
payload: {
intentId: e,
fees: t,
lang: this.sdkEmbed.lang
}
});
}
/**
* Creates Elements context used to render each card field

@@ -523,4 +583,5 @@ * @description Elements context is used to create and manage card fields

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

@@ -547,50 +608,56 @@ * Creates card field element

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

@@ -613,21 +680,22 @@ };

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

@@ -638,8 +706,8 @@ payload: {

lang: this.sdkEmbed.lang,
billingData: a,
shippingData: r,
cardEmbed: o
billingData: s,
shippingData: a,
cardEmbed: l
}
});
return c && c.remove(), l;
return c && c.remove(), m;
});

@@ -657,3 +725,3 @@ }

*/
submitCvv(a) {
submitCvv(s) {
return y(this, arguments, function* ({

@@ -673,11 +741,11 @@ intentId: e,

}
renderUrl(e, t, a) {
renderUrl(e, t, s) {
return y(this, null, function* () {
switch (t) {
case "IFRAME":
return f(this, L, B).call(this, e);
return f(this, I, Q).call(this, e);
case "POPUP_IFRAME":
return f(this, S, z).call(this, e);
return f(this, C, X).call(this, e);
case "REDIRECT":
return f(this, A, J).call(this, e, a);
return f(this, U, Z).call(this, e, s);
default:

@@ -689,13 +757,13 @@ return null;

}
L = new WeakSet(), B = function(e) {
I = new WeakSet(), Q = function(e) {
return y(this, null, function* () {
const t = document.querySelector("#rendered-url-iframe-container");
b(
E(
!t,
"Couldn't find an element with id rendered-url-iframe-container to render the iframe!"
);
const a = document.createElement("iframe");
a.src = e, a.style.setProperty("border", "0", "important"), a.style.setProperty("width", "100%", "important"), a.style.setProperty("height", "100%", "important"), t == null || t.replaceChildren(a), yield f(this, k, $).call(this), a.remove();
const s = document.createElement("iframe");
s.src = e, s.style.setProperty("border", "0", "important"), s.style.setProperty("width", "100%", "important"), s.style.setProperty("height", "100%", "important"), t == null || t.replaceChildren(s), yield f(this, S, H).call(this), s.remove();
});
}, S = new WeakSet(), z = function(e) {
}, C = new WeakSet(), X = function(e) {
return y(this, null, function* () {

@@ -707,5 +775,5 @@ const t = window.open(

);
b(!t, "Popup blocked by browser!"), yield f(this, k, $).call(this), t == null || t.close();
E(!t, "Popup blocked by browser!"), yield f(this, S, H).call(this), t == null || t.close();
});
}, A = new WeakSet(), J = function(e, t) {
}, U = new WeakSet(), Z = function(e, t) {
return y(this, null, function* () {

@@ -718,10 +786,10 @@ if (!t || !t.redirectToNewWindow) {

});
}, k = new WeakSet(), $ = function() {
}, S = new WeakSet(), H = function() {
return y(this, null, function* () {
const e = new W(), t = (a) => {
var s, n, o, c;
const { type: r, data: d } = a.data;
switch (r) {
const e = new J(), t = (s) => {
var n, r, o, l;
const { type: a, data: d } = s.data;
switch (a) {
case "onComplete":
(n = (s = this.options).onComplete) == null || n.call(s, P({
(r = (n = this.options).onComplete) == null || r.call(n, P({
type: this.options.type

@@ -731,3 +799,3 @@ }, d)), e.resolve(() => null), window.removeEventListener("message", t);

case "onFail":
(c = (o = this.options).onFail) == null || c.call(o, P({
(l = (o = this.options).onFail) == null || l.call(o, P({
type: this.options.type

@@ -743,44 +811,47 @@ }, d)), e.resolve(() => null), window.removeEventListener("message", t);

});
}, I = new WeakSet(), O = function(e) {
const t = (a) => {
e.forEach((r) => {
r(a);
}, R = new WeakSet(), ee = function(e) {
const t = (s) => {
s.origin === q() && e.forEach((a) => {
a(s);
});
};
window.addEventListener("message", t);
}, U = new WeakSet(), K = function(e) {
const t = (a) => {
e.current && e.current(a);
}, _ = new WeakSet(), te = function(e) {
const t = (s) => {
e.current && e.current(s);
};
window.addEventListener("message", t);
}, C = new WeakSet(), G = function({
}, M = new WeakSet(), re = function({
container: e,
elementType: t,
elementOptions: a,
styles: r
elementOptions: s,
styles: a
}) {
var o, c, l, h;
const d = x(), s = new URL(`${d}/vaultField/vaultField.html`);
s.searchParams.set("host", btoa(window.location.origin)), s.searchParams.set("type", t), ((o = a.validation) == null ? void 0 : o.required) !== void 0 && s.searchParams.set(
var o, l, c, m;
const d = q(), n = new URL(`${d}/vaultField/vaultField.html`);
n.searchParams.set("host", btoa(window.location.origin)), n.searchParams.set("type", t), ((o = s.validation) == null ? void 0 : o.required) !== void 0 && n.searchParams.set(
"required",
`${(c = a.validation) == null ? void 0 : c.required}`
), s.searchParams.set("placeholder", (l = a.placeholder) != null ? l : ""), s.searchParams.set("lang", this.sdkEmbed.lang), s.searchParams.set("direction", (r == null ? void 0 : r.direction) || ""), s.searchParams.set("color", (r == null ? void 0 : r.color) || "#000"), s.searchParams.set(
`${(l = s.validation) == null ? void 0 : l.required}`
), n.searchParams.set("placeholder", (c = s.placeholder) != null ? c : ""), n.searchParams.set("lang", this.sdkEmbed.lang), n.searchParams.set("direction", (a == null ? void 0 : a.direction) || ""), n.searchParams.set("color", (a == null ? void 0 : a.color) || "#000"), n.searchParams.set(
"placeholderColor",
(r == null ? void 0 : r.placeholderColor) || "#ccc"
), s.searchParams.set(
(a == null ? void 0 : a.placeholderColor) || "#ccc"
), n.searchParams.set(
"backgroundColor",
(r == null ? void 0 : r.backgroundColor) || "transparent"
), s.searchParams.set("fontSize", (r == null ? void 0 : r.fontSize) || ""), s.searchParams.set("padding", (r == null ? void 0 : r.padding) || "");
(a == null ? void 0 : a.backgroundColor) || "transparent"
), n.searchParams.set("fontSize", (a == null ? void 0 : a.fontSize) || ""), n.searchParams.set("padding", (a == null ? void 0 : a.padding) || "");
const r = document.createElement("iframe");
r.src = n.toString(), r.style.height = (m = a == null ? void 0 : a.height) != null ? m : "40px", r.style.setProperty("overflow", "hidden", "important"), r.style.setProperty("display", "block", "important"), r.style.setProperty("width", "100%", "important"), r.style.setProperty("maxWidth", "100%", "important"), r.style.setProperty("border", "0", "important"), r.style.setProperty("margin", "0", "important"), r.style.setProperty("padding", "0", "important"), r.style.setProperty("userSelect", "none", "important"), r.style.setProperty("colorScheme", "light only", "important"), e.replaceChildren(r);
}, $ = new WeakSet(), ae = function({
accessToken: e,
saveCard: t
}) {
const s = q(), a = ge(), d = new URL(
`${s}/vaultSubmit/vaultSubmit.html`
);
d.searchParams.set("host", btoa(window.location.origin)), d.searchParams.set("vault_api_url", `${a}/api/v1/tokens/`), d.searchParams.set("access_token", e), d.searchParams.set("lang", this.sdkEmbed.lang), t !== void 0 && d.searchParams.set("save_card", `${t}`);
const n = document.createElement("iframe");
n.src = s.toString(), n.style.height = (h = r == null ? void 0 : r.height) != null ? h : "40px", n.style.setProperty("overflow", "hidden", "important"), n.style.setProperty("display", "block", "important"), n.style.setProperty("width", "100%", "important"), n.style.setProperty("maxWidth", "100%", "important"), n.style.setProperty("border", "0", "important"), n.style.setProperty("margin", "0", "important"), n.style.setProperty("padding", "0", "important"), n.style.setProperty("userSelect", "none", "important"), n.style.setProperty("colorScheme", "light only", "important"), e.replaceChildren(n);
}, R = new WeakSet(), Q = function(e) {
const t = x(), a = de(), r = new URL(
`${t}/vaultSubmit/vaultSubmit.html`
);
r.searchParams.set("host", btoa(window.location.origin)), r.searchParams.set("vault_api_url", `${a}/api/v1/tokens/`), r.searchParams.set("access_token", e), r.searchParams.set("lang", this.sdkEmbed.lang);
const d = document.createElement("iframe");
return d.id = "moneyhash-submit-iframe", d.src = r.toString(), d.hidden = !0, document.body.appendChild(d), d;
return n.id = "moneyhash-submit-iframe", n.src = d.toString(), n.hidden = !0, document.body.appendChild(n), n;
};
export {
ue as default
Ee as default
};

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

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

@@ -11,3 +11,3 @@ export declare interface AbstractIntent {

subtotalAmount: string | null;
fees: Array<FeesItem> | null;
fees: Array<Fee> | null;
totalDiscounts: string | null;

@@ -52,7 +52,13 @@ secret: string;

export declare interface FeesItem {
export declare interface Discount {
title: Record<SupportedLanguages, string>;
value: string;
type: "amount" | "percentage";
value: string | number;
}
export declare interface Fee {
title: Record<SupportedLanguages, string>;
value: string | number;
}
export declare type Field = {

@@ -59,0 +65,0 @@ type: FieldType;

var o = Object.defineProperty;
var i = (s, e, r) => e in s ? o(s, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : s[e] = r;
var t = (s, e, r) => (i(s, typeof e != "symbol" ? e + "" : e, r), r);
import { S as a, t as d } from "./sdkEmbed-e0041728.js";
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-2e22d8b1.js";
class b {
constructor(e) {
constructor(s) {
t(this, "options");
t(this, "sdkEmbed");
this.options = e, this.sdkEmbed = new a(e);
this.options = s, this.sdkEmbed = new i(s);
}

@@ -26,4 +26,4 @@ /**

*/
start({ selector: e, intentId: r }) {
return d(!e, "selector is required for start"), d(!r, "intentId is required for start"), this.sdkEmbed.render({ selector: e, intentId: r });
start({ selector: s, intentId: e }) {
return d(!s, "selector is required for start"), d(!e, "intentId is required for start"), this.sdkEmbed.render({ selector: s, intentId: e });
}

@@ -42,3 +42,10 @@ /**

*/
setLocale(e) {
setLocale(s) {
u(
!!s && !a.has(s),
`Invalid locale. Supported languages (${[...a].join(
" | "
)})`
);
const e = a.has(s) ? s : "en";
return this.sdkEmbed.setLocale(e);

@@ -45,0 +52,0 @@ }

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

(function(i,s){typeof exports=="object"&&typeof module!="undefined"?module.exports=s():typeof define=="function"&&define.amd?define(s):(i=typeof globalThis!="undefined"?globalThis:i||self,i.MoneyHash=s())})(this,function(){"use strict";var F=Object.defineProperty;var O=Object.getOwnPropertySymbols;var U=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable;var v=(i,s,t)=>s in i?F(i,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[s]=t,w=(i,s)=>{for(var t in s||(s={}))U.call(s,t)&&v(i,t,s[t]);if(O)for(var t of O(s))$.call(s,t)&&v(i,t,s[t]);return i};var a=(i,s,t)=>(v(i,typeof s!="symbol"?s+"":s,t),t);var b=(i,s,t)=>new Promise((p,o)=>{var m=n=>{try{h(t.next(n))}catch(e){o(e)}},f=n=>{try{h(t.throw(n))}catch(e){o(e)}},h=n=>n.done?p(n.value):Promise.resolve(n.value).then(m,f);h((t=t.apply(i,s)).next())});class i{constructor(e){a(this,"target");a(this,"targetOrigin");a(this,"listeners");a(this,"onIncomingMessageBind",this.onIncomingMessage.bind(this));this.target=e.target,this.targetOrigin=e.targetOrigin,this.listeners=[],window.addEventListener("message",this.onIncomingMessageBind)}send(e){this.target.postMessage(e,this.targetOrigin)}onReceive(e){this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter(r=>r!==e)}onIncomingMessage(e){e.origin===this.targetOrigin&&this.listeners.forEach(r=>{r(e,this.send.bind(this))})}abortService(){window.removeEventListener("message",this.onIncomingMessageBind)}}function s(){var e;return(e=window.MONEYHASH_IFRAME_URL)!=null?e:"https://embed.moneyhash.io"}function t(n,e){if(n)throw new Error(e)}function p(n,e){n&&console.warn(e)}const o=new Set(["payment","payout"]),m=new Set(["en","fr","ar"]);class f{constructor(e){a(this,"options");a(this,"messagingService",null);a(this,"iframe",null);a(this,"isCommunicationReady",null);t(!o.has(e.type),`MoneyHash constructor must be called with valid type (${[...o].join(" | ")})!`),this.options=e}get lang(){var r;const e=(r=this.options.locale)==null?void 0:r.split("-")[0];return p(!!e&&!m.has(e),`Supported languages (${[...m].join(" | ")})`),e||"en"}render({selector:e,intentId:r}){var L,M;(L=this.messagingService)==null||L.abortService();const S=s(),c=new URL(`${S}/embed/${this.options.type}/${r}`);c.searchParams.set("sdk","true"),c.searchParams.set("parent",window.location.origin),c.searchParams.set("version","js@1.1.2");const R=(M=this.options.locale)==null?void 0:M.split("-")[0];R&&c.searchParams.set("lang",R),this.iframe=document.createElement("iframe"),this.iframe.src=c.toString(),this.iframe.style.height="100%",this.iframe.style.width="100%",this.iframe.style.border="0";const E=document.querySelector(e);return t(!E,`Couldn't find an element with selector ${e}!`),E.replaceChildren(this.iframe),this.messagingService=new i({target:this.iframe.contentWindow,targetOrigin:S}),this.isCommunicationReady=new Promise(y=>{var l;const g=u=>{var d;u.data.type==="sdk:init"&&(y(),(d=this.messagingService)==null||d.removeListener(g))};(l=this.messagingService)==null||l.onReceive(g)}),this.messagingService.onReceive((y,g)=>{var d,k,I,C;const{type:l,data:u}=y.data;switch(l){case"sdk:init":{g({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(k=(d=this.options).onComplete)==null||k.call(d,w({type:this.options.type},u)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{(C=(I=this.options).onFail)==null||C.call(I,w({type:this.options.type},u)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}}}),this.isCommunicationReady}setLocale(e){return b(this,null,function*(){var r;yield this==null?void 0:this.isCommunicationReady,this.options.locale=e,(r=this.messagingService)==null||r.send({type:"changeLanguage",data:{locale:e}})})}abortService(){return b(this,null,function*(){var e;yield this==null?void 0:this.isCommunicationReady,(e=this.messagingService)==null||e.abortService()})}}class h{constructor(e){a(this,"options");a(this,"sdkEmbed");this.options=e,this.sdkEmbed=new f(e)}start({selector:e,intentId:r}){return t(!e,"selector is required for start"),t(!r,"intentId is required for start"),this.sdkEmbed.render({selector:e,intentId:r})}setLocale(e){return this.sdkEmbed.setLocale(e)}removeEventListeners(){return this.sdkEmbed.abortService()}}return h});
(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.0");const R=(M=this.options.locale)==null?void 0:M.split("-")[0];R&&c.searchParams.set("lang",R),this.iframe=document.createElement("iframe"),this.iframe.src=c.toString(),this.iframe.style.height="100%",this.iframe.style.width="100%",this.iframe.style.border="0";const E=document.querySelector(e);return t(!E,`Couldn't find an element with selector ${e}!`),E.replaceChildren(this.iframe),this.messagingService=new i({target:this.iframe.contentWindow,targetOrigin:S}),this.isCommunicationReady=new Promise(y=>{var l;const m=u=>{var d;u.data.type==="sdk:init"&&(y(),(d=this.messagingService)==null||d.removeListener(m))};(l=this.messagingService)==null||l.onReceive(m)}),this.messagingService.onReceive((y,m)=>{var d,I,k,C;const{type:l,data:u}=y.data;switch(l){case"sdk:init":{m({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(I=(d=this.options).onComplete)==null||I.call(d,w({type:this.options.type},u)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{(C=(k=this.options).onFail)==null||C.call(k,w({type:this.options.type},u)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}}}),this.isCommunicationReady}setLocale(e){return b(this,null,function*(){var n;yield this==null?void 0:this.isCommunicationReady,this.options.locale=e,(n=this.messagingService)==null||n.send({type:"changeLanguage",data:{locale:e}})})}abortService(){return b(this,null,function*(){var e;yield this==null?void 0:this.isCommunicationReady,(e=this.messagingService)==null||e.abortService()})}}function f(r,e){r&&console.warn(e)}class h{constructor(e){a(this,"options");a(this,"sdkEmbed");this.options=e,this.sdkEmbed=new p(e)}start({selector:e,intentId:n}){return t(!e,"selector is required for start"),t(!n,"intentId is required for start"),this.sdkEmbed.render({selector:e,intentId:n})}setLocale(e){f(!!e&&!o.has(e),`Invalid locale. Supported languages (${[...o].join(" | ")})`);const n=o.has(e)?e:"en";return this.sdkEmbed.setLocale(n)}removeEventListeners(){return this.sdkEmbed.abortService()}}return h});
{
"name": "@moneyhash/js-sdk",
"version": "1.1.2",
"version": "1.2.0",
"description": "MoneyHash JavaScript SDK",

@@ -5,0 +5,0 @@ "type": "module",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc