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.3.1 to 1.4.0

dist/warnIf-8078d446.js

2

dist/headless.cjs.js

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

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

@@ -171,2 +171,3 @@ export declare interface AbstractIntent {

value: string | number;
discount?: Discount;
}

@@ -625,4 +626,20 @@

*/
renderUrl(url: string, renderStrategy: UrlRenderStrategy): Promise<void>;
renderUrl(url: string, renderStrategy: UrlRenderStrategy, options?: RenderOptions): Promise<void>;
renderUrl({ intentId, url, renderStrategy, options, }: {
intentId: string;
url: string;
renderStrategy: UrlRenderStrategy;
options?: RenderOptions;
}): Promise<void | null>;
/**
* Listen to expiration date of the intent passed or not and execute the callback
* @example
* ```
* moneyHash.onExpiration('<expiration_date>', () => {
* console.log('intent expired!');
* });
* ```
* @see {@link IntentDetails} - for \<expiration_date>
* @returns Cleanup function
*/
onExpiration(expirationDate: string, callback: () => void): () => void;
}

@@ -703,3 +720,16 @@ export default MoneyHashHeadless;

export declare type RenderOptions = {
redirectToNewWindow: boolean;
/**
* Redirect to new window for `renderStrategy: "REDIRECT"`
*/
redirectToNewWindow?: boolean;
/**
* Popup window size and positions for `renderStrategy: "POPUP_IFRAME"`
* @default "width=600,height=400,left=200,top=200"
*/
window?: {
width?: number;
height?: number;
left?: number;
top?: number;
};
};

@@ -706,0 +736,0 @@

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

var ie = Object.defineProperty, se = Object.defineProperties;
var oe = Object.getOwnPropertyDescriptors;
var se = Object.defineProperty, oe = Object.defineProperties;
var de = Object.getOwnPropertyDescriptors;
var z = Object.getOwnPropertySymbols;
var de = Object.prototype.hasOwnProperty, ce = Object.prototype.propertyIsEnumerable;
var q = (s, e, t) => e in s ? ie(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, E = (s, e) => {
var ce = Object.prototype.hasOwnProperty, le = Object.prototype.propertyIsEnumerable;
var q = (o, e, t) => e in o ? se(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t, b = (o, e) => {
for (var t in e || (e = {}))
de.call(e, t) && q(s, t, e[t]);
ce.call(e, t) && q(o, t, e[t]);
if (z)
for (var t of z(e))
ce.call(e, t) && q(s, t, e[t]);
return s;
}, J = (s, e) => se(s, oe(e));
var g = (s, e, t) => (q(s, typeof e != "symbol" ? e + "" : e, t), t), le = (s, e, t) => {
if (!e.has(s))
le.call(e, t) && q(o, t, e[t]);
return o;
}, J = (o, e) => oe(o, de(e));
var f = (o, e, t) => (q(o, typeof e != "symbol" ? e + "" : e, t), t), me = (o, e, t) => {
if (!e.has(o))
throw TypeError("Cannot " + t);
};
var P = (s, e, t) => {
if (e.has(s))
var P = (o, e, t) => {
if (e.has(o))
throw TypeError("Cannot add the same private member more than once");
e instanceof WeakSet ? e.add(s) : e.set(s, t);
e instanceof WeakSet ? e.add(o) : e.set(o, t);
};
var f = (s, e, t) => (le(s, e, "access private method"), t);
var v = (s, e, t) => new Promise((n, a) => {
var o = (r) => {
var v = (o, e, t) => (me(o, e, "access private method"), t);
var p = (o, e, t) => new Promise((i, r) => {
var n = (a) => {
try {
i(t.next(r));
s(t.next(a));
} catch (l) {
a(l);
r(l);
}
}, d = (r) => {
}, c = (a) => {
try {
i(t.throw(r));
s(t.throw(a));
} catch (l) {
a(l);
r(l);
}
}, i = (r) => r.done ? n(r.value) : Promise.resolve(r.value).then(o, d);
i((t = t.apply(s, e)).next());
}, s = (a) => a.done ? i(a.value) : Promise.resolve(a.value).then(n, c);
s((t = t.apply(o, e)).next());
});
import { M as me, g as he, S as pe, t as w, w as ue, s as N } from "./warnIf-5bb0d6ca.js";
import { M as he, g as X, S as ue, t as w, w as pe, s as N } from "./warnIf-8078d446.js";
function ge() {

@@ -50,34 +50,34 @@ return typeof window != "undefined";

return;
const e = he(), 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.3.1");
const n = document.createElement("iframe");
n.id = "moneyhash-headless-sdk", n.src = t.toString(), n.hidden = !0, document.body.appendChild(n), y.messagingService = new me({
target: n.contentWindow,
const e = X(), t = new URL(`${e}/embed/headless-sdk`);
t.searchParams.set("sdk", "true"), t.searchParams.set("parent", window.location.origin), t.searchParams.set("version", "js@1.4.0");
const i = document.createElement("iframe");
i.id = "moneyhash-headless-sdk", i.src = t.toString(), i.hidden = !0, document.body.appendChild(i), y.messagingService = new he({
target: i.contentWindow,
targetOrigin: e
}), y.isCommunicationReady = new Promise((a) => {
var d;
const o = (i) => {
var r;
i.data.type === "headlessSDK:init" && (a(), (r = y.messagingService) == null || r.removeListener(o));
}), y.isCommunicationReady = new Promise((r) => {
var c;
const n = (s) => {
var a;
s.data.type === "headlessSDK:init" && (r(), (a = y.messagingService) == null || a.removeListener(n));
};
(d = y.messagingService) == null || d.onReceive(o);
(c = y.messagingService) == null || c.onReceive(n);
});
}
request(n) {
return v(this, arguments, function* ({
request(i) {
return p(this, arguments, function* ({
api: e,
payload: t
}) {
return yield y.isCommunicationReady, new Promise((a, o) => {
var i, r;
(i = y.messagingService) == null || i.send({
return yield y.isCommunicationReady, new Promise((r, n) => {
var s, a;
(s = y.messagingService) == null || s.send({
type: e,
data: t
});
const d = (l) => {
const c = (l) => {
var h;
const { type: c, data: m } = l.data;
c === e && (m.status === "resolved" ? a(m.payload) : o(m.payload), (h = y.messagingService) == null || h.removeListener(d));
const { type: d, data: m } = l.data;
d === e && (m.status === "resolved" ? r(m.payload) : n(m.payload), (h = y.messagingService) == null || h.removeListener(c));
};
(r = y.messagingService) == null || r.onReceive(d);
(a = y.messagingService) == null || a.onReceive(c);
});

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

};
let L = y;
g(L, "messagingService", null), g(L, "isCommunicationReady");
let I = y;
f(I, "messagingService", null), f(I, "isCommunicationReady");
class K {
constructor() {
g(this, "promise");
g(this, "resolve");
g(this, "reject");
f(this, "promise");
f(this, "resolve");
f(this, "reject");
this.promise = new Promise((e, t) => {

@@ -112,3 +112,3 @@ this.resolve = e, this.reject = t;

}
function ve(s) {
function ve(o) {
const e = [

@@ -121,11 +121,11 @@ "cardNumber",

for (const t of e)
if (!s.includes(t))
if (!o.includes(t))
return t;
return null;
}
function we(s) {
return (Array.isArray(s) ? s.length : Object.keys(s).length) === 0;
function we(o) {
return (Array.isArray(o) ? o.length : Object.keys(o).length) === 0;
}
function ye(s, e) {
return new Promise((t, n) => {
function ye(o, e) {
return new Promise((t, i) => {
if (document.getElementById(e)) {

@@ -135,10 +135,17 @@ t(void 0);

}
const o = document.createElement("script");
o.src = s, o.id = e, o.addEventListener("load", () => {
const n = document.createElement("script");
n.src = o, n.id = e, n.addEventListener("load", () => {
t(void 0);
}), o.addEventListener("error", () => {
n(new Error("Script failed to load"));
}), document.body.appendChild(o);
}), n.addEventListener("error", () => {
i(new Error("Script failed to load"));
}), document.body.appendChild(n);
});
}
function Pe(o) {
return new Promise((e) => {
setTimeout(() => {
e("done");
}, o * 1e3);
});
}
const Q = /* @__PURE__ */ new Set([

@@ -149,6 +156,6 @@ "method",

]);
var I, X, C, Z, U, ee, A, H, R, te, _, re, M, ae, $, ne;
class ke {
var L, Z, C, ee, U, te, A, H, R, re, _, ae, $, ne, M, ie;
class Se {
constructor(e) {
P(this, I);
P(this, L);
P(this, C);

@@ -159,12 +166,12 @@ P(this, U);

P(this, _);
P(this, $);
P(this, M);
P(this, $);
g(this, "options");
g(this, "sdkApiHandler", new L());
g(this, "sdkEmbed");
g(this, "vaultSubmitListener", {
f(this, "options");
f(this, "sdkApiHandler", new I());
f(this, "sdkEmbed");
f(this, "vaultSubmitListener", {
current: null
});
g(this, "mountedCardElements", []);
this.options = e, this.sdkEmbed = new pe(J(E({}, e), { headless: !0 })), f(this, _, re).call(this, this.vaultSubmitListener);
f(this, "mountedCardElements", []);
this.options = e, this.sdkEmbed = new ue(J(b({}, e), { headless: !0 })), v(this, _, ae).call(this, this.vaultSubmitListener);
}

@@ -260,4 +267,4 @@ /**

type: t,
id: n,
metaData: a
id: i,
metaData: r
}) {

@@ -275,5 +282,5 @@ return w(

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

@@ -375,12 +382,12 @@ });

payWithApplePay(l) {
return v(this, arguments, function* ({
return p(this, arguments, function* ({
intentId: e,
currency: t,
amount: n,
countryCode: a,
onCancel: o = () => {
amount: i,
countryCode: r,
onCancel: n = () => {
},
onError: d,
onComplete: i,
billingData: r = {}
onError: c,
onComplete: s,
billingData: a = {}
}) {

@@ -392,4 +399,4 @@ if (yield ye(

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

@@ -401,3 +408,3 @@ supportedNetworks: ["visa", "masterCard", "amex", "discover", "mada"],

type: "final",
amount: `${n}`
amount: `${i}`
}

@@ -411,3 +418,3 @@ }), { state: m, intent: h } = yield this.proceedWith({

if (m === "INTENT_FORM") {
if (we(r))
if (we(a))
throw new Error(

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

lang: this.sdkEmbed.lang,
billingData: r
billingData: a
}
});
}
} catch (u) {
throw yield this.resetSelectedMethod(e), u;
} catch (g) {
throw yield this.resetSelectedMethod(e), g;
}
c.onvalidatemerchant = (u) => {
d.onvalidatemerchant = (g) => {
fetch(`${G()}/api/v1/providers/applepay/session/`, {

@@ -438,8 +445,8 @@ method: "post",

secret: h.secret,
validation_url: u.validationURL
validation_url: g.validationURL
})
}).then((p) => p.ok ? p.json() : Promise.reject()).then(
(p) => c.completeMerchantValidation(p)
).catch(d);
}, c.onpaymentauthorized = (u) => {
}).then((u) => u.ok ? u.json() : Promise.reject()).then(
(u) => d.completeMerchantValidation(u)
).catch(c);
}, d.onpaymentauthorized = (g) => {
fetch(`${G()}/api/v1/providers/applepay/token/`, {

@@ -451,11 +458,11 @@ method: "post",

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

@@ -495,3 +502,3 @@ }

setLocale(e) {
ue(
pe(
!!e && !N.has(e),

@@ -556,4 +563,4 @@ `Invalid locale. Supported languages (${[...N].join(

updateIntentFees({ intentId: e, fees: t }) {
return t.forEach((n) => {
w(!n.title.en, "English fee title is required!");
return t.forEach((i) => {
w(!i.title.en, "English fee title is required!");
}), this.sdkApiHandler.request({

@@ -580,6 +587,6 @@ api: "sdk:updateIntentFees",

*/
elements({ styles: e, classes: t, fontSourceCss: n }) {
const a = [], o = {}, d = /* @__PURE__ */ new Map();
let i = !1;
return f(this, R, te).call(this, a), {
elements({ styles: e, classes: t, fontSourceCss: i }) {
const r = [], n = {}, c = /* @__PURE__ */ new Map();
let s = !1;
return v(this, R, re).call(this, r), {
/**

@@ -606,5 +613,5 @@ * Creates card field element

*/
create: ({ elementType: r, elementOptions: l }) => {
var j, W;
const c = /* @__PURE__ */ new Map(), m = document.querySelector(
create: ({ elementType: a, elementOptions: l }) => {
var j, D;
const d = /* @__PURE__ */ new Map(), m = document.querySelector(
l.selector

@@ -616,48 +623,48 @@ );

), m.classList.add("MoneyHashElement");
const h = E(E({}, t), l.classes), u = ((j = h == null ? void 0 : h.focus) == null ? void 0 : j.split(" ")) || [
const h = b(b({}, t), l.classes), g = ((j = h == null ? void 0 : h.focus) == null ? void 0 : j.split(" ")) || [
"MoneyHashElement--focus"
], p = ((W = h == null ? void 0 : h.error) == null ? void 0 : W.split(" ")) || [
], u = ((D = h == null ? void 0 : h.error) == null ? void 0 : D.split(" ")) || [
"MoneyHashElement--error"
];
return a.push((k) => {
var T, D, x, B, Y, O;
const { type: b, data: S } = k.data;
if (b === `${r}:init` && (o[r] = S.isValid), b === `${r}@focus`) {
m.classList.add(...u), (T = c.get(`${r}@focus`)) == null || T();
return r.push((k) => {
var W, T, x, B, Y, O;
const { type: E, data: S } = k.data;
if (E === `${a}:init` && (n[a] = S.isValid), E === `${a}@focus`) {
m.classList.add(...g), (W = d.get(`${a}@focus`)) == null || W();
return;
}
if (b === `${r}@blur`) {
m.classList.remove(...u), (D = c.get(`${r}@blur`)) == null || D();
if (E === `${a}@blur`) {
m.classList.remove(...g), (T = d.get(`${a}@blur`)) == null || T();
return;
}
if (b === `${r}@error`) {
S.isValid ? m.classList.remove(...p) : m.classList.add(...p), (x = c.get(`${r}@error`)) == null || x(S);
if (E === `${a}@error`) {
S.isValid ? m.classList.remove(...u) : m.classList.add(...u), (x = d.get(`${a}@error`)) == null || x(S);
return;
}
if (b === `${r}@changeInput`) {
if ((B = c.get(`${r}@changeInput`)) == null || B(), o[r] = S.isValid, d.get("validityChange")) {
const F = Object.values(o).every(Boolean);
F !== i && ((Y = d.get("validityChange")) == null || Y(F), i = F);
if (E === `${a}@changeInput`) {
if ((B = d.get(`${a}@changeInput`)) == null || B(), n[a] = S.isValid, c.get("validityChange")) {
const F = Object.values(n).every(Boolean);
F !== s && ((Y = c.get("validityChange")) == null || Y(F), s = F);
}
return;
}
b === `${r}@cardNumberChange` && ((O = c.get(`${r}@cardNumberChange`)) == null || O(S));
E === `${a}@cardNumberChange` && ((O = d.get(`${a}@cardNumberChange`)) == null || O(S));
}), {
mount: () => {
this.mountedCardElements.push(r), f(this, M, ae).call(this, {
this.mountedCardElements.push(a), v(this, $, ne).call(this, {
container: m,
elementType: r,
elementType: a,
elementOptions: l,
styles: E(E({}, e), l.styles),
fontSourceCss: n
styles: b(b({}, e), l.styles),
fontSourceCss: i
});
},
on: (k, b) => {
c.set(`${r}@${k}`, b);
on: (k, E) => {
d.set(`${a}@${k}`, E);
},
off: (k) => c.delete(`${r}@${k}`)
off: (k) => d.delete(`${a}@${k}`)
};
},
on: (r, l) => {
d.set(r, l);
on: (a, l) => {
c.set(a, l);
}

@@ -680,21 +687,21 @@ };

*/
submitForm(d) {
return v(this, arguments, function* ({
submitForm(c) {
return p(this, arguments, function* ({
intentId: e,
accessToken: t,
billingData: n,
shippingData: a,
saveCard: o
billingData: i,
shippingData: r,
saveCard: n
}) {
const i = ve(this.mountedCardElements);
const s = ve(this.mountedCardElements);
w(
!!i,
`You must mount ${i} element!`
!!s,
`You must mount ${s} element!`
);
const r = new K();
let l, c;
const a = new K();
let l, d;
t && (this.vaultSubmitListener.current = (h) => {
const { type: u, data: p } = h.data;
u === "vaultSubmit:success" && r.resolve(p), u === "vaultSubmit:error" && r.reject(p);
}, c = f(this, $, ne).call(this, { accessToken: t, saveCard: o }), l = yield r.promise);
const { type: g, data: u } = h.data;
g === "vaultSubmit:success" && a.resolve(u), g === "vaultSubmit:error" && a.reject(u);
}, d = v(this, M, ie).call(this, { accessToken: t, saveCard: n }), l = yield a.promise);
const m = yield this.sdkApiHandler.request({

@@ -706,8 +713,8 @@ api: "sdk:submitNativeForm",

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

@@ -725,4 +732,4 @@ }

*/
submitCvv(n) {
return v(this, arguments, function* ({
submitCvv(i) {
return p(this, arguments, function* ({
intentId: e,

@@ -741,11 +748,25 @@ cvv: t

}
renderUrl(e, t, n) {
return v(this, null, function* () {
switch (t) {
/**
* Render the received url in an iframe, popup iframe or redirect
*
* @example
* ```
* moneyHash.renderUrl('<url>', 'IFRAME');
* ```
*
*/
renderUrl(n) {
return p(this, arguments, function* ({
intentId: e,
url: t,
renderStrategy: i,
options: r
}) {
switch (i) {
case "IFRAME":
return f(this, I, X).call(this, e);
return v(this, L, Z).call(this, { url: t, intentId: e });
case "POPUP_IFRAME":
return f(this, C, Z).call(this, e);
return v(this, C, ee).call(this, { url: t, intentId: e, options: r });
case "REDIRECT":
return f(this, U, ee).call(this, e, n);
return v(this, U, te).call(this, { url: t, options: r });
default:

@@ -756,24 +777,57 @@ return null;

}
/**
* Listen to expiration date of the intent passed or not and execute the callback
* @example
* ```
* moneyHash.onExpiration('<expiration_date>', () => {
* console.log('intent expired!');
* });
* ```
* @see {@link IntentDetails} - for \<expiration_date>
* @returns Cleanup function
*/
onExpiration(e, t) {
const i = new Date(e), r = setInterval(() => p(this, null, function* () {
const n = new Date();
i < n && (clearInterval(r), t());
}), 1e3);
return () => clearInterval(r);
}
}
I = new WeakSet(), X = function(e) {
return v(this, null, function* () {
const t = document.querySelector("#rendered-url-iframe-container");
L = new WeakSet(), Z = function(i) {
return p(this, arguments, function* ({
intentId: e,
url: t
}) {
const r = document.querySelector("#rendered-url-iframe-container");
w(
!t,
!r,
"Couldn't find an element with id rendered-url-iframe-container to render the iframe!"
);
const n = document.createElement("iframe");
n.src = e, n.style.setProperty("border", "0", "important"), n.style.setProperty("width", "100%", "important"), n.style.setProperty("height", "100%", "important"), t == null || t.replaceChildren(n), yield f(this, A, H).call(this), n.remove();
n.src = t, n.style.setProperty("border", "0", "important"), n.style.setProperty("width", "100%", "important"), n.style.setProperty("height", "100%", "important"), r == null || r.replaceChildren(n), yield v(this, A, H).call(this, e), n.remove();
});
}, C = new WeakSet(), Z = function(e) {
return v(this, null, function* () {
const t = window.open(
`${e}`,
}, C = new WeakSet(), ee = function(r) {
return p(this, arguments, function* ({
intentId: e,
url: t,
options: i = {}
}) {
const {
width: n = 600,
height: c = 400,
left: s = 200,
top: a = 200
} = i.window || {}, l = window.open(
`${t}`,
"",
"width=600,height=400,left=200,top=200"
`width=${n},height=${c},left=${s},top=${a}`
);
w(!t, "Popup blocked by browser!"), yield f(this, A, H).call(this), t == null || t.close();
w(!l, "Popup blocked by browser!"), yield v(this, A, H).call(this, e), l == null || l.close();
});
}, U = new WeakSet(), ee = function(e, t) {
return v(this, null, function* () {
}, U = new WeakSet(), te = function(i) {
return p(this, arguments, function* ({
url: e,
options: t
}) {
if (!t || !t.redirectToNewWindow) {

@@ -785,74 +839,72 @@ window.location.href = e;

});
}, A = new WeakSet(), H = function() {
return v(this, null, function* () {
const e = new K(), t = (n) => {
var d, i, r, l;
const { type: a, data: o } = n.data;
switch (a) {
case "onComplete":
(i = (d = this.options).onComplete) == null || i.call(d, E({
type: this.options.type
}, o)), e.resolve(() => null), window.removeEventListener("message", t);
break;
case "onFail":
(l = (r = this.options).onFail) == null || l.call(r, E({
type: this.options.type
}, o)), e.resolve(() => null), window.removeEventListener("message", t);
break;
default:
e.resolve(() => null);
break;
}, A = new WeakSet(), H = function(e) {
return p(this, null, function* () {
const t = new K(), i = (r) => p(this, null, function* () {
var c, s, a, l;
if (r.origin !== X())
return;
const { type: n } = r.data;
if (n === "intentResult") {
const [d] = yield Promise.all([
this.getIntentDetails(e),
Pe(1)
]), m = d.transaction.status.split(".")[1];
m === "successful" || m.startsWith("pending") ? (s = (c = this.options).onComplete) == null || s.call(c, b({
type: this.options.type
}, d)) : (l = (a = this.options).onFail) == null || l.call(a, b({
type: this.options.type
}, d)), t.resolve(() => null), window.removeEventListener("message", i);
}
};
return window.addEventListener("message", t), e.promise;
});
return window.addEventListener("message", i), t.promise;
});
}, R = new WeakSet(), te = function(e) {
const t = (n) => {
n.origin === V() && e.forEach((a) => {
a(n);
}, R = new WeakSet(), re = function(e) {
const t = (i) => {
i.origin === V() && e.forEach((r) => {
r(i);
});
};
window.addEventListener("message", t);
}, _ = new WeakSet(), re = function(e) {
const t = (n) => {
e.current && e.current(n);
}, _ = new WeakSet(), ae = function(e) {
const t = (i) => {
e.current && e.current(i);
};
window.addEventListener("message", t);
}, M = new WeakSet(), ae = function({
}, $ = new WeakSet(), ne = function({
container: e,
elementType: t,
elementOptions: n,
styles: a,
fontSourceCss: o
elementOptions: i,
styles: r,
fontSourceCss: n
}) {
var l, c, m, h;
const d = V(), i = new URL(`${d}/vaultField/vaultField.html`);
o && i.searchParams.set("fontSourceCss", o), i.searchParams.set("host", btoa(window.location.origin)), i.searchParams.set("type", t), ((l = n.validation) == null ? void 0 : l.required) !== void 0 && i.searchParams.set(
var l, d, m, h;
const c = V(), s = new URL(`${c}/vaultField/vaultField.html`);
n && s.searchParams.set("fontSourceCss", n), s.searchParams.set("host", btoa(window.location.origin)), s.searchParams.set("type", t), ((l = i.validation) == null ? void 0 : l.required) !== void 0 && s.searchParams.set(
"required",
`${(c = n.validation) == null ? void 0 : c.required}`
), i.searchParams.set("placeholder", (m = n.placeholder) != null ? m : ""), i.searchParams.set("lang", this.sdkEmbed.lang), i.searchParams.set("direction", (a == null ? void 0 : a.direction) || ""), i.searchParams.set(
`${(d = i.validation) == null ? void 0 : d.required}`
), s.searchParams.set("placeholder", (m = i.placeholder) != null ? m : ""), s.searchParams.set("lang", this.sdkEmbed.lang), s.searchParams.set("direction", (r == null ? void 0 : r.direction) || ""), s.searchParams.set(
"color",
JSON.stringify(a != null && a.color ? a.color : "#000")
), i.searchParams.set(
JSON.stringify(r != null && r.color ? r.color : "#000")
), s.searchParams.set(
"placeholderColor",
(a == null ? void 0 : a.placeholderColor) || "#ccc"
), i.searchParams.set(
(r == null ? void 0 : r.placeholderColor) || "#ccc"
), s.searchParams.set(
"backgroundColor",
(a == null ? void 0 : a.backgroundColor) || "transparent"
), i.searchParams.set("fontSize", (a == null ? void 0 : a.fontSize) || ""), i.searchParams.set("fontFamily", (a == null ? void 0 : a.fontFamily) || ""), i.searchParams.set("fontWeight", `${a == null ? void 0 : a.fontWeight}`), i.searchParams.set("fontStyle", (a == null ? void 0 : a.fontStyle) || ""), i.searchParams.set("padding", (a == null ? void 0 : a.padding) || "");
const r = document.createElement("iframe");
r.src = i.toString(), r.style.height = (h = a == null ? void 0 : a.height) != null ? h : "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(), ne = function({
(r == null ? void 0 : r.backgroundColor) || "transparent"
), s.searchParams.set("fontSize", (r == null ? void 0 : r.fontSize) || ""), s.searchParams.set("fontFamily", (r == null ? void 0 : r.fontFamily) || ""), s.searchParams.set("fontWeight", `${r == null ? void 0 : r.fontWeight}`), s.searchParams.set("fontStyle", (r == null ? void 0 : r.fontStyle) || ""), s.searchParams.set("padding", (r == null ? void 0 : r.padding) || "");
const a = document.createElement("iframe");
a.src = s.toString(), a.style.height = (h = r == null ? void 0 : r.height) != null ? h : "40px", a.style.setProperty("overflow", "hidden", "important"), a.style.setProperty("display", "block", "important"), a.style.setProperty("width", "100%", "important"), a.style.setProperty("maxWidth", "100%", "important"), a.style.setProperty("border", "0", "important"), a.style.setProperty("margin", "0", "important"), a.style.setProperty("padding", "0", "important"), a.style.setProperty("userSelect", "none", "important"), a.style.setProperty("colorScheme", "light only", "important"), e.replaceChildren(a);
}, M = new WeakSet(), ie = function({
accessToken: e,
saveCard: t
}) {
const n = V(), a = fe(), o = new URL(
`${n}/vaultSubmit/vaultSubmit.html`
const i = V(), r = fe(), n = new URL(
`${i}/vaultSubmit/vaultSubmit.html`
);
o.searchParams.set("host", btoa(window.location.origin)), o.searchParams.set("vault_api_url", `${a}/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 d = document.createElement("iframe");
return d.id = "moneyhash-submit-iframe", d.src = o.toString(), d.hidden = !0, document.body.appendChild(d), d;
n.searchParams.set("host", btoa(window.location.origin)), n.searchParams.set("vault_api_url", `${r}/api/v1/tokens/`), n.searchParams.set("access_token", e), n.searchParams.set("lang", this.sdkEmbed.lang), t !== void 0 && n.searchParams.set("save_card", `${t}`);
const c = document.createElement("iframe");
return c.id = "moneyhash-submit-iframe", c.src = n.toString(), c.hidden = !0, document.body.appendChild(c), c;
};
export {
ke as default
Se as default
};

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

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

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

"use strict";var n=Object.defineProperty;var d=(t,e,s)=>e in t?n(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var a=(t,e,s)=>(d(t,typeof e!="symbol"?e+"":e,s),s);const r=require("./warnIf-d5e4457f.cjs");class o{constructor(e){a(this,"options");a(this,"sdkEmbed");this.options=e,this.sdkEmbed=new r.SDKEmbed(e)}start({selector:e,intentId:s}){return r.throwIf(!e,"selector is required for start"),r.throwIf(!s,"intentId is required for start"),this.sdkEmbed.render({selector:e,intentId:s})}setLocale(e){r.warnIf(!!e&&!r.supportedLanguages.has(e),`Invalid locale. Supported languages (${[...r.supportedLanguages].join(" | ")})`);const s=r.supportedLanguages.has(e)?e:"en";return this.sdkEmbed.setLocale(s)}removeEventListeners(){return this.sdkEmbed.abortService()}}module.exports=o;
"use strict";var n=Object.defineProperty;var d=(t,e,s)=>e in t?n(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var a=(t,e,s)=>(d(t,typeof e!="symbol"?e+"":e,s),s);const r=require("./warnIf-c918cfab.cjs");class o{constructor(e){a(this,"options");a(this,"sdkEmbed");this.options=e,this.sdkEmbed=new r.SDKEmbed(e)}start({selector:e,intentId:s}){return r.throwIf(!e,"selector is required for start"),r.throwIf(!s,"intentId is required for start"),this.sdkEmbed.render({selector:e,intentId:s})}setLocale(e){r.warnIf(!!e&&!r.supportedLanguages.has(e),`Invalid locale. Supported languages (${[...r.supportedLanguages].join(" | ")})`);const s=r.supportedLanguages.has(e)?e:"en";return this.sdkEmbed.setLocale(s)}removeEventListeners(){return this.sdkEmbed.abortService()}}module.exports=o;

@@ -68,2 +68,3 @@ export declare interface AbstractIntent {

value: string | number;
discount?: Discount;
}

@@ -70,0 +71,0 @@

var o = Object.defineProperty;
var n = (r, s, e) => s in r ? o(r, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[s] = e;
var t = (r, s, e) => (n(r, typeof s != "symbol" ? s + "" : s, e), e);
import { S as i, t as d, w as u, s as a } from "./warnIf-5bb0d6ca.js";
import { S as i, t as d, w as u, s as a } from "./warnIf-8078d446.js";
class b {

@@ -6,0 +6,0 @@ constructor(s) {

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

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