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
62
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.7.0 to 1.7.1

dist/warnIf-1e9cc55c.cjs

2

dist/headless.cjs.js

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

"use strict";var we=Object.defineProperty,Pe=Object.defineProperties;var be=Object.getOwnPropertyDescriptors;var U=Object.getOwnPropertySymbols;var ne=Object.prototype.hasOwnProperty,re=Object.prototype.propertyIsEnumerable;var T=(o,e,t)=>e in o?we(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,w=(o,e)=>{for(var t in e||(e={}))ne.call(e,t)&&T(o,t,e[t]);if(U)for(var t of U(e))re.call(e,t)&&T(o,t,e[t]);return o},_=(o,e)=>Pe(o,be(e));var se=(o,e)=>{var t={};for(var r in o)ne.call(o,r)&&e.indexOf(r)<0&&(t[r]=o[r]);if(o!=null&&U)for(var r of U(o))e.indexOf(r)<0&&re.call(o,r)&&(t[r]=o[r]);return t};var f=(o,e,t)=>(T(o,typeof e!="symbol"?e+"":e,t),t),ke=(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 y=(o,e,t)=>(ke(o,e,"access private method"),t);var g=(o,e,t)=>new Promise((r,a)=>{var s=n=>{try{i(t.next(n))}catch(c){a(c)}},d=n=>{try{i(t.throw(n))}catch(c){a(c)}},i=n=>n.done?r(n.value):Promise.resolve(n.value).then(s,d);i((t=t.apply(o,e)).next())});const p=require("./warnIf-97d3456f.cjs");function Ee(){return typeof window!="undefined"}const b=class{constructor(){Ee()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=p.getIframeUrl(),t=new URL(`${e}/embed/headless-sdk`);t.searchParams.set("sdk","true"),t.searchParams.set("parent",window.location.origin),t.searchParams.set("version","js@1.7.0");const r=document.createElement("iframe");r.id="moneyhash-headless-sdk",r.src=t.toString(),r.hidden=!0,document.body.appendChild(r),b.messagingService=new p.MessagingService({target:r.contentWindow,targetOrigin:e}),b.isCommunicationReady=new Promise(a=>{var d;const s=i=>{var n;i.data.type==="headlessSDK:init"&&(a(),(n=b.messagingService)==null||n.removeListener(s))};(d=b.messagingService)==null||d.onReceive(s)})}request(r){return g(this,arguments,function*({api:e,payload:t}){return yield b.isCommunicationReady,new Promise((a,s)=>{var i,n;(i=b.messagingService)==null||i.send({type:e,data:t});const d=c=>{var m;const{type:l,data:h}=c.data;l===e&&(h.status==="resolved"?a(h.payload):s(h.payload),(m=b.messagingService)==null||m.removeListener(d))};(n=b.messagingService)==null||n.onReceive(d)})})}postMessage(e){var t;(t=b.messagingService)==null||t.send({type:e})}};let S=b;f(S,"messagingService",null),f(S,"isCommunicationReady");class G{constructor(){f(this,"promise");f(this,"resolve");f(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function Ae(){var e;return(e=window.MONEYHASH_VAULT_API_URL)!=null?e:"https://vault.moneyhash.io"}function C(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function ie(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}function oe(o){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!o.includes(t))return t;return null}function de(o){return(Array.isArray(o)?o.length:Object.keys(o).length)===0}function ce(o,e){return new Promise((t,r)=>{if(document.getElementById(e)){t(void 0);return}const s=document.createElement("script");s.src=o,s.id=e,s.addEventListener("load",()=>{t(void 0)}),s.addEventListener("error",()=>{r(new Error("Script failed to load"))}),document.body.appendChild(s)})}function ve(o){return new Promise(e=>{setTimeout(()=>{e("done")},o*1e3)})}const le=new Set(["method","customerBalance","savedCard"]);var L,O,M,Y,$,he,F,pe,q,ue,R,B,H,me,N,ge,D,ye,V,fe;class Ie{constructor(e){P(this,L);P(this,M);P(this,$);P(this,F);P(this,q);P(this,R);P(this,H);P(this,N);P(this,D);P(this,V);f(this,"options");f(this,"sdkApiHandler",new S);f(this,"sdkEmbed");f(this,"vaultSubmitListener",{current:null});f(this,"mountedCardElements",[]);f(this,"googlePaymentsClient",null);f(this,"cardForm",{collect:()=>g(this,null,function*(){p.throwIf(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to collect card!");const e=oe(this.mountedCardElements);p.throwIf(!!e,`You must mount ${e} element!`);const t=yield this.sdkApiHandler.request({api:"sdk:generateAccessToken",payload:{publicApiKey:this.options.publicApiKey}});return y(this,M,Y).call(this,{accessToken:t})}),pay:d=>g(this,[d],function*({intentId:e,cardData:t,saveCard:r,billingData:a,shippingData:s}){return this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,lang:this.sdkEmbed.lang,paymentMethod:"CARD",billingData:a,shippingData:s,cardEmbed:t,saveCard:r}})}),createCardToken:r=>g(this,[r],function*({cardIntentId:e,cardData:t}){return this.sdkApiHandler.request({api:"sdk:createCardToken",payload:{cardIntentId:e,lang:this.sdkEmbed.lang,paymentMethod:"CARD",cardEmbed:t}})})});this.options=e,this.sdkEmbed=new p.SDKEmbed(_(w({},e),{headless:!0})),y(this,N,ge).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}})}getMethods(e){return"intentId"in e?this.getIntentMethods(e.intentId):(p.throwIf(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to get methods!"),p.throwIf(this.options.type==="payout","getMethods is not allowed for payout!"),this.sdkApiHandler.request({api:"sdk:getMethods",payload:w({intentType:this.options.type,lang:this.sdkEmbed.lang,publicApiKey:this.options.publicApiKey},e)}))}proceedWith({intentId:e,type:t,id:r,useWalletBalance:a,metaData:s}){return p.throwIf(!le.has(t),`type must be a valid one (${[...le].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:r,lang:this.sdkEmbed.lang,useWalletBalance:a,metaData:s}})}resetSelectedMethod(e){return this.sdkApiHandler.request({api:"sdk:resetSelectedMethod",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}deleteCard({cardId:e,intentSecret:t}){return p.throwIf(this.options.type==="payout","deleteCard is allowed only for payment intent!"),this.sdkApiHandler.request({api:"sdk:deleteCard",payload:{cardId:e,intentSecret:t,lang:this.sdkEmbed.lang}})}payWithApplePay(c){return g(this,arguments,function*({intentId:e,currency:t,amount:r,countryCode:a,onCancel:s=()=>{},onError:d,onComplete:i,billingData:n={}}){if(yield ce("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)return;const l=new ApplePaySession(3,{countryCode:a,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${r}`}}),{state:h,intent:m}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(h==="FORM_FIELDS"){if(de(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(A){throw yield this.resetSelectedMethod(e),A}const E=new G;l.onvalidatemerchant=A=>{fetch(`${ie()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:m.secret,validation_url:A.validationURL})}).then(k=>k.ok?k.json():Promise.reject()).then(k=>l.completeMerchantValidation(k)).catch(d)},l.onpaymentauthorized=A=>{fetch(`${ie()}/api/v1/providers/applepay/token/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({token_data:{token:A.payment.token},secret:m.secret})}).then(k=>k.ok?k.json():Promise.reject()).then(()=>{l.completePayment(ApplePaySession.STATUS_SUCCESS),i==null||i(),E.resolve(void 0)}).catch(()=>{l.completePayment(ApplePaySession.STATUS_FAILURE),d(),E.reject(void 0)})},l.oncancel=s,l.begin(),yield E.promise})}renderGooglePayButton(r){return g(this,null,function*(){var a=r,{onClick:e}=a,t=se(a,["onClick"]);var i;const s=document.getElementById("moneyHash-google-pay-button");p.throwIf(!s,"Couldn't find an element with id moneyHash-google-pay-button to render the google pay button!"),yield ce("https://pay.google.com/gp/p/js/pay.js","moneyHash-google-pay-sdk"),this.googlePaymentsClient=new window.google.payments.api.PaymentsClient({environment:((i=this.options.googlePay)==null?void 0:i.environment)||"PRODUCTION"});const d=y(this,L,O).call(this);this.googlePaymentsClient.isReadyToPay(d).then(n=>{if(n.result){const c=this.googlePaymentsClient.createButton(_(w({buttonSizeMode:"fill",buttonType:"pay"},t),{allowedPaymentMethods:d.allowedPaymentMethods,onClick:e}));s==null||s.replaceChildren(c)}else throw new Error("Google Pay is not ready to pay!")}).catch(n=>{console.dir(n)})})}payWithGooglePay(a){return g(this,arguments,function*({intentId:e,billingData:t={},onCancel:r}){p.throwIf(!this.googlePaymentsClient,'Google Payments Client is not initialized! Make sure to call "renderGooglePay" before calling "payWithGooglePay"');const{state:s,__nativePayData__:d}=yield this.proceedWith({intentId:e,type:"method",id:"GOOGLE_PAY"});try{if(s==="FORM_FIELDS"){if(de(t))throw new Error("Billing data is missing while calling payWithGooglePay");yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"GOOGLE_PAY",lang:this.sdkEmbed.lang,billingData:t}})}}catch(i){throw yield this.resetSelectedMethod(e),i}return this.googlePaymentsClient.loadPaymentData(_(w({},y(this,L,O).call(this,d)),{transactionInfo:{totalPriceStatus:"FINAL",totalPriceLabel:"Total",totalPrice:`${d.amount}`,currencyCode:d.currency_code,countryCode:d.country_code},merchantInfo:{merchantName:d==null?void 0:d.merchant_name,merchantId:d==null?void 0:d.merchant_id}})).then(i=>{const n=i.paymentMethodData.tokenizationData.token;return this.sdkApiHandler.request({api:"sdk:submitReceipt",payload:{intentId:e,paymentMethod:"GOOGLE_PAY",lang:this.sdkEmbed.lang,receipt:n}})}).catch(i=>(i.statusCode==="CANCELED"?r==null||r():console.dir(i),Promise.reject(i)))})}renderForm(e){return p.throwIf(!e.selector,"selector is required for renderForm"),p.throwIf(!e.intentId,"intentId is required for renderForm"),this.sdkEmbed.render(e)}setLocale(e){p.warnIf(!!e&&!p.supportedLanguages.has(e),`Invalid locale. Supported languages (${[...p.supportedLanguages].join(" | ")})`);const t=p.supportedLanguages.has(e)?e:"en";return this.sdkEmbed.setLocale(t)}removeEventListeners(){return this.sdkEmbed.abortService()}updateIntentDiscount({intentId:e,discount:t}){return p.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(r=>{p.throwIf(!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 a=[],s={},d=new Map;let i=!1;return y(this,H,me).call(this,a),{create:({elementType:n,elementOptions:c})=>{var k,x;const l=new Map;let h=null;const m=w(w({},t),c.classes),E=((k=m==null?void 0:m.focus)==null?void 0:k.split(" "))||["MoneyHashElement--focus"],A=((x=m==null?void 0:m.error)==null?void 0:x.split(" "))||["MoneyHashElement--error"];return{mount:()=>{const u=document.querySelector(c.selector);p.throwIf(!u,`Couldn't find an element with selector ${c.selector}!`),u.classList.add("MoneyHashElement"),a.push(W=>{var K,z,J,X,Q,Z,ee,te,ae;const{type:v,data:I}=W.data;if(v===`${n}@mount`&&(s[n]=I.isValid,(K=l.get(`${n}@mount`))==null||K()),v===`${n}@focus`){u.classList.add(...E),(z=l.get(`${n}@focus`))==null||z();return}if(v===`${n}@blur`){u.classList.remove(...E),(J=l.get(`${n}@blur`))==null||J();return}if(v===`${n}@error`){I.isValid?u.classList.remove(...A):u.classList.add(...A),(X=l.get(`${n}@error`))==null||X(I);return}if(v===`${n}@changeInput`){if((Q=l.get(`${n}@changeInput`))==null||Q({isValid:I.isValid,length:I.length}),s[n]=I.isValid,d.get("validityChange")){const j=Object.values(s).every(Boolean);j!==i&&((Z=d.get("validityChange"))==null||Z(j),i=j)}return}if(v===`${n}@cardNumberChange`){(ee=l.get(`${n}@cardNumberChange`))==null||ee(I);return}if(v===`${n}@key:Backspace`){(te=l.get(`${n}@key:Backspace`))==null||te();return}v===`${n}@key:Enter`&&((ae=l.get(`${n}@key:Enter`))==null||ae())}),h=y(this,D,ye).call(this,{container:u,elementType:n,elementOptions:c,styles:w(w({},e),c.styles),fontSourceCss:r}),this.mountedCardElements.push(n)},on:(u,W)=>{l.set(`${n}@${u}`,W)},off:u=>l.delete(`${n}@${u}`),focus:()=>{var u;(u=h==null?void 0:h.contentWindow)==null||u.postMessage({type:"focus"},C())},blur:()=>{var u;(u=h==null?void 0:h.contentWindow)==null||u.postMessage({type:"blur"},C())},clear:()=>{var u;(u=h==null?void 0:h.contentWindow)==null||u.postMessage({type:"clear"},C())}}},on:(n,c)=>{d.set(n,c)}}}submitForm(n){return g(this,arguments,function*({intentId:e,accessToken:t,billingData:r,shippingData:a,saveCard:s,paymentMethod:d="CARD",useWalletBalance:i}){let c;if(t){const h=oe(this.mountedCardElements);p.throwIf(!!h,`You must mount ${h} element!`),c=yield y(this,M,Y).call(this,{accessToken:t})}return yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:d,lang:this.sdkEmbed.lang,billingData:r,shippingData:a,cardEmbed:c,useWalletBalance:i,saveCard:s}})})}submitCvv(r){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(s){return g(this,arguments,function*({intentId:e,url:t,renderStrategy:r,options:a}){switch(this.sdkApiHandler.postMessage("SDKRenderUrl"),r){case"IFRAME":return y(this,$,he).call(this,{url:t,intentId:e});case"POPUP_IFRAME":return y(this,F,pe).call(this,{url:t,intentId:e,options:a});case"REDIRECT":return y(this,q,ue).call(this,{url:t,options:a});default:return null}})}onExpiration(e,t){if(!e)return()=>{};const r=new Date(e),a=setInterval(()=>g(this,null,function*(){const s=new Date;r<s&&(clearInterval(a),t())}),1e3);return()=>clearInterval(a)}}L=new WeakSet,O=function(e){var r,a;return{apiVersion:2,apiVersionMinor:0,allowedPaymentMethods:[w({type:"CARD",parameters:{allowedAuthMethods:((r=this.options.googlePay)==null?void 0:r.allowedAuthMethods)||["PAN_ONLY","CRYPTOGRAM_3DS"],allowedCardNetworks:((a=this.options.googlePay)==null?void 0:a.allowedCardNetworks)||["AMEX","DISCOVER","JCB","MASTERCARD","VISA"]}},e?{tokenizationSpecification:{type:"PAYMENT_GATEWAY",parameters:{gateway:e.gateway,gatewayMerchantId:e.gateway_merchant_id}}}:{})]}},M=new WeakSet,Y=function(t){return g(this,arguments,function*({accessToken:e}){const r=new G;this.vaultSubmitListener.current=d=>{const{type:i,data:n}=d.data;i==="vaultSubmit:success"&&r.resolve(n),i==="vaultSubmit:error"&&r.reject(n)};const a=y(this,V,fe).call(this,{accessToken:e}),s=yield r.promise;return a.remove(),s})},$=new WeakSet,he=function(r){return g(this,arguments,function*({intentId:e,url:t}){const a=document.querySelector("#rendered-url-iframe-container");p.throwIf(!a,"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"),a==null||a.replaceChildren(s),yield y(this,R,B).call(this,{intentId:e}),s.remove()})},F=new WeakSet,pe=function(a){return g(this,arguments,function*({intentId:e,url:t,options:r={}}){const{width:s=600,height:d=400,left:i=200,top:n=200}=r.window||{},c=window.open(t,"",`width=${s},height=${d},left=${i},top=${n}`);p.throwIf(!c,"Popup blocked by browser!"),yield y(this,R,B).call(this,{intentId:e,isUsingPopUp:!0}),c==null||c.close()})},q=new WeakSet,ue=function(r){return g(this,arguments,function*({url:e,options:t}){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},R=new WeakSet,B=function(r){return g(this,arguments,function*({intentId:e,isUsingPopUp:t=!1}){const a=new G,s=d=>g(this,null,function*(){var n,c,l,h;if(d.origin!==p.getIframeUrl())return;const{type:i}=d.data;if(i==="intentResult"){t&&this.sdkApiHandler.postMessage("EmbedResultClose");const[m]=yield Promise.all([this.getIntentDetails(e),ve(2)]),E=m.transaction.status.split(".")[1];E==="successful"||E.startsWith("pending")?(c=(n=this.options).onComplete)==null||c.call(n,w({type:this.options.type},m)):(h=(l=this.options).onFail)==null||h.call(l,w({type:this.options.type},m)),a.resolve(()=>null),window.removeEventListener("message",s)}});return window.addEventListener("message",s),a.promise})},H=new WeakSet,me=function(e){const t=r=>{r.origin===C()&&e.forEach(a=>{a(r)})};window.addEventListener("message",t)},N=new WeakSet,ge=function(e){const t=r=>{e.current&&e.current(r)};window.addEventListener("message",t)},D=new WeakSet,ye=function({container:e,elementType:t,elementOptions:r,styles:a,fontSourceCss:s}){var c,l,h,m;const d=C(),i=new URL(`${d}/vaultField/vaultField.html`);s&&i.searchParams.set("fontSourceCss",s),i.searchParams.set("host",btoa(window.location.origin)),i.searchParams.set("type",t),((c=r.validation)==null?void 0:c.required)!==void 0&&i.searchParams.set("required",`${(l=r.validation)==null?void 0:l.required}`),i.searchParams.set("placeholder",(h=r.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 n=document.createElement("iframe");return n.src=i.toString(),n.style.height=(m=a==null?void 0:a.height)!=null?m:"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),n},V=new WeakSet,fe=function({accessToken:e}){const t=C(),r=Ae(),a=new URL(`${t}/vaultSubmit/vaultSubmit.html`);a.searchParams.set("host",btoa(window.location.origin)),a.searchParams.set("vault_api_url",`${r}/api/v1/tokens/`),a.searchParams.set("access_token",e),a.searchParams.set("lang",this.sdkEmbed.lang);const s=document.createElement("iframe");return s.id="moneyhash-submit-iframe",s.src=a.toString(),s.hidden=!0,document.body.appendChild(s),s};module.exports=Ie;
"use strict";var we=Object.defineProperty,Pe=Object.defineProperties;var be=Object.getOwnPropertyDescriptors;var U=Object.getOwnPropertySymbols;var ne=Object.prototype.hasOwnProperty,re=Object.prototype.propertyIsEnumerable;var T=(o,e,t)=>e in o?we(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,w=(o,e)=>{for(var t in e||(e={}))ne.call(e,t)&&T(o,t,e[t]);if(U)for(var t of U(e))re.call(e,t)&&T(o,t,e[t]);return o},_=(o,e)=>Pe(o,be(e));var se=(o,e)=>{var t={};for(var r in o)ne.call(o,r)&&e.indexOf(r)<0&&(t[r]=o[r]);if(o!=null&&U)for(var r of U(o))e.indexOf(r)<0&&re.call(o,r)&&(t[r]=o[r]);return t};var f=(o,e,t)=>(T(o,typeof e!="symbol"?e+"":e,t),t),ke=(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 y=(o,e,t)=>(ke(o,e,"access private method"),t);var g=(o,e,t)=>new Promise((r,a)=>{var s=n=>{try{i(t.next(n))}catch(c){a(c)}},d=n=>{try{i(t.throw(n))}catch(c){a(c)}},i=n=>n.done?r(n.value):Promise.resolve(n.value).then(s,d);i((t=t.apply(o,e)).next())});const p=require("./warnIf-1e9cc55c.cjs");function Ee(){return typeof window!="undefined"}const b=class{constructor(){Ee()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=p.getIframeUrl(),t=new URL(`${e}/embed/headless-sdk`);t.searchParams.set("sdk","true"),t.searchParams.set("parent",window.location.origin),t.searchParams.set("version","js@1.7.1");const r=document.createElement("iframe");r.id="moneyhash-headless-sdk",r.src=t.toString(),r.hidden=!0,document.body.appendChild(r),b.messagingService=new p.MessagingService({target:r.contentWindow,targetOrigin:e}),b.isCommunicationReady=new Promise(a=>{var d;const s=i=>{var n;i.data.type==="headlessSDK:init"&&(a(),(n=b.messagingService)==null||n.removeListener(s))};(d=b.messagingService)==null||d.onReceive(s)})}request(r){return g(this,arguments,function*({api:e,payload:t}){return yield b.isCommunicationReady,new Promise((a,s)=>{var i,n;(i=b.messagingService)==null||i.send({type:e,data:t});const d=c=>{var m;const{type:l,data:h}=c.data;l===e&&(h.status==="resolved"?a(h.payload):s(h.payload),(m=b.messagingService)==null||m.removeListener(d))};(n=b.messagingService)==null||n.onReceive(d)})})}postMessage(e){var t;(t=b.messagingService)==null||t.send({type:e})}};let S=b;f(S,"messagingService",null),f(S,"isCommunicationReady");class G{constructor(){f(this,"promise");f(this,"resolve");f(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function Ae(){var e;return(e=window.MONEYHASH_VAULT_API_URL)!=null?e:"https://vault.moneyhash.io"}function C(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function ie(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}function oe(o){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!o.includes(t))return t;return null}function de(o){return(Array.isArray(o)?o.length:Object.keys(o).length)===0}function ce(o,e){return new Promise((t,r)=>{if(document.getElementById(e)){t(void 0);return}const s=document.createElement("script");s.src=o,s.id=e,s.addEventListener("load",()=>{t(void 0)}),s.addEventListener("error",()=>{r(new Error("Script failed to load"))}),document.body.appendChild(s)})}function ve(o){return new Promise(e=>{setTimeout(()=>{e("done")},o*1e3)})}const le=new Set(["method","customerBalance","savedCard"]);var L,O,M,Y,$,he,F,pe,q,ue,R,B,H,me,N,ge,D,ye,V,fe;class Ie{constructor(e){P(this,L);P(this,M);P(this,$);P(this,F);P(this,q);P(this,R);P(this,H);P(this,N);P(this,D);P(this,V);f(this,"options");f(this,"sdkApiHandler",new S);f(this,"sdkEmbed");f(this,"vaultSubmitListener",{current:null});f(this,"mountedCardElements",[]);f(this,"googlePaymentsClient",null);f(this,"cardForm",{collect:()=>g(this,null,function*(){p.throwIf(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to collect card!");const e=oe(this.mountedCardElements);p.throwIf(!!e,`You must mount ${e} element!`);const t=yield this.sdkApiHandler.request({api:"sdk:generateAccessToken",payload:{publicApiKey:this.options.publicApiKey}});return y(this,M,Y).call(this,{accessToken:t})}),pay:d=>g(this,[d],function*({intentId:e,cardData:t,saveCard:r,billingData:a,shippingData:s}){return this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,lang:this.sdkEmbed.lang,paymentMethod:"CARD",billingData:a,shippingData:s,cardEmbed:t,saveCard:r}})}),createCardToken:r=>g(this,[r],function*({cardIntentId:e,cardData:t}){return this.sdkApiHandler.request({api:"sdk:createCardToken",payload:{cardIntentId:e,lang:this.sdkEmbed.lang,paymentMethod:"CARD",cardEmbed:t}})})});this.options=e,this.sdkEmbed=new p.SDKEmbed(_(w({},e),{headless:!0})),y(this,N,ge).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}})}getMethods(e){return"intentId"in e?this.getIntentMethods(e.intentId):(p.throwIf(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to get methods!"),p.throwIf(this.options.type==="payout","getMethods is not allowed for payout!"),this.sdkApiHandler.request({api:"sdk:getMethods",payload:w({intentType:this.options.type,lang:this.sdkEmbed.lang,publicApiKey:this.options.publicApiKey},e)}))}proceedWith({intentId:e,type:t,id:r,useWalletBalance:a,metaData:s}){return p.throwIf(!le.has(t),`type must be a valid one (${[...le].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:r,lang:this.sdkEmbed.lang,useWalletBalance:a,metaData:s}})}resetSelectedMethod(e){return this.sdkApiHandler.request({api:"sdk:resetSelectedMethod",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}deleteCard({cardId:e,intentSecret:t}){return p.throwIf(this.options.type==="payout","deleteCard is allowed only for payment intent!"),this.sdkApiHandler.request({api:"sdk:deleteCard",payload:{cardId:e,intentSecret:t,lang:this.sdkEmbed.lang}})}payWithApplePay(c){return g(this,arguments,function*({intentId:e,currency:t,amount:r,countryCode:a,onCancel:s=()=>{},onError:d,onComplete:i,billingData:n={}}){if(yield ce("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)return;const l=new ApplePaySession(3,{countryCode:a,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${r}`}}),{state:h,intent:m}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(h==="FORM_FIELDS"){if(de(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(A){throw yield this.resetSelectedMethod(e),A}const E=new G;l.onvalidatemerchant=A=>{fetch(`${ie()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:m.secret,validation_url:A.validationURL})}).then(k=>k.ok?k.json():Promise.reject()).then(k=>l.completeMerchantValidation(k)).catch(d)},l.onpaymentauthorized=A=>{fetch(`${ie()}/api/v1/providers/applepay/token/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({token_data:{token:A.payment.token},secret:m.secret})}).then(k=>k.ok?k.json():Promise.reject()).then(()=>{l.completePayment(ApplePaySession.STATUS_SUCCESS),i==null||i(),E.resolve(void 0)}).catch(()=>{l.completePayment(ApplePaySession.STATUS_FAILURE),d(),E.reject(void 0)})},l.oncancel=s,l.begin(),yield E.promise})}renderGooglePayButton(r){return g(this,null,function*(){var a=r,{onClick:e}=a,t=se(a,["onClick"]);var i;const s=document.getElementById("moneyHash-google-pay-button");p.throwIf(!s,"Couldn't find an element with id moneyHash-google-pay-button to render the google pay button!"),yield ce("https://pay.google.com/gp/p/js/pay.js","moneyHash-google-pay-sdk"),this.googlePaymentsClient=new window.google.payments.api.PaymentsClient({environment:((i=this.options.googlePay)==null?void 0:i.environment)||"PRODUCTION"});const d=y(this,L,O).call(this);this.googlePaymentsClient.isReadyToPay(d).then(n=>{if(n.result){const c=this.googlePaymentsClient.createButton(_(w({buttonSizeMode:"fill",buttonType:"pay"},t),{allowedPaymentMethods:d.allowedPaymentMethods,onClick:e}));s==null||s.replaceChildren(c)}else throw new Error("Google Pay is not ready to pay!")}).catch(n=>{console.dir(n)})})}payWithGooglePay(a){return g(this,arguments,function*({intentId:e,billingData:t={},onCancel:r}){p.throwIf(!this.googlePaymentsClient,'Google Payments Client is not initialized! Make sure to call "renderGooglePay" before calling "payWithGooglePay"');const{state:s,__nativePayData__:d}=yield this.proceedWith({intentId:e,type:"method",id:"GOOGLE_PAY"});try{if(s==="FORM_FIELDS"){if(de(t))throw new Error("Billing data is missing while calling payWithGooglePay");yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"GOOGLE_PAY",lang:this.sdkEmbed.lang,billingData:t}})}}catch(i){throw yield this.resetSelectedMethod(e),i}return this.googlePaymentsClient.loadPaymentData(_(w({},y(this,L,O).call(this,d)),{transactionInfo:{totalPriceStatus:"FINAL",totalPriceLabel:"Total",totalPrice:`${d.amount}`,currencyCode:d.currency_code,countryCode:d.country_code},merchantInfo:{merchantName:d==null?void 0:d.merchant_name,merchantId:d==null?void 0:d.merchant_id}})).then(i=>{const n=i.paymentMethodData.tokenizationData.token;return this.sdkApiHandler.request({api:"sdk:submitReceipt",payload:{intentId:e,paymentMethod:"GOOGLE_PAY",lang:this.sdkEmbed.lang,receipt:n}})}).catch(i=>(i.statusCode==="CANCELED"?r==null||r():console.dir(i),Promise.reject(i)))})}renderForm(e){return p.throwIf(!e.selector,"selector is required for renderForm"),p.throwIf(!e.intentId,"intentId is required for renderForm"),this.sdkEmbed.render(e)}setLocale(e){p.warnIf(!!e&&!p.supportedLanguages.has(e),`Invalid locale. Supported languages (${[...p.supportedLanguages].join(" | ")})`);const t=p.supportedLanguages.has(e)?e:"en";return this.sdkEmbed.setLocale(t)}removeEventListeners(){return this.sdkEmbed.abortService()}updateIntentDiscount({intentId:e,discount:t}){return p.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(r=>{p.throwIf(!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 a=[],s={},d=new Map;let i=!1;return y(this,H,me).call(this,a),{create:({elementType:n,elementOptions:c})=>{var k,x;const l=new Map;let h=null;const m=w(w({},t),c.classes),E=((k=m==null?void 0:m.focus)==null?void 0:k.split(" "))||["MoneyHashElement--focus"],A=((x=m==null?void 0:m.error)==null?void 0:x.split(" "))||["MoneyHashElement--error"];return{mount:()=>{const u=document.querySelector(c.selector);p.throwIf(!u,`Couldn't find an element with selector ${c.selector}!`),u.classList.add("MoneyHashElement"),a.push(W=>{var K,z,J,X,Q,Z,ee,te,ae;const{type:v,data:I}=W.data;if(v===`${n}@mount`&&(s[n]=I.isValid,(K=l.get(`${n}@mount`))==null||K()),v===`${n}@focus`){u.classList.add(...E),(z=l.get(`${n}@focus`))==null||z();return}if(v===`${n}@blur`){u.classList.remove(...E),(J=l.get(`${n}@blur`))==null||J();return}if(v===`${n}@error`){I.isValid?u.classList.remove(...A):u.classList.add(...A),(X=l.get(`${n}@error`))==null||X(I);return}if(v===`${n}@changeInput`){if((Q=l.get(`${n}@changeInput`))==null||Q({isValid:I.isValid,length:I.length}),s[n]=I.isValid,d.get("validityChange")){const j=Object.values(s).every(Boolean);j!==i&&((Z=d.get("validityChange"))==null||Z(j),i=j)}return}if(v===`${n}@cardNumberChange`){(ee=l.get(`${n}@cardNumberChange`))==null||ee(I);return}if(v===`${n}@key:Backspace`){(te=l.get(`${n}@key:Backspace`))==null||te();return}v===`${n}@key:Enter`&&((ae=l.get(`${n}@key:Enter`))==null||ae())}),h=y(this,D,ye).call(this,{container:u,elementType:n,elementOptions:c,styles:w(w({},e),c.styles),fontSourceCss:r}),this.mountedCardElements.push(n)},on:(u,W)=>{l.set(`${n}@${u}`,W)},off:u=>l.delete(`${n}@${u}`),focus:()=>{var u;(u=h==null?void 0:h.contentWindow)==null||u.postMessage({type:"focus"},C())},blur:()=>{var u;(u=h==null?void 0:h.contentWindow)==null||u.postMessage({type:"blur"},C())},clear:()=>{var u;(u=h==null?void 0:h.contentWindow)==null||u.postMessage({type:"clear"},C())}}},on:(n,c)=>{d.set(n,c)}}}submitForm(n){return g(this,arguments,function*({intentId:e,accessToken:t,billingData:r,shippingData:a,saveCard:s,paymentMethod:d="CARD",useWalletBalance:i}){let c;if(t){const h=oe(this.mountedCardElements);p.throwIf(!!h,`You must mount ${h} element!`),c=yield y(this,M,Y).call(this,{accessToken:t})}return yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:d,lang:this.sdkEmbed.lang,billingData:r,shippingData:a,cardEmbed:c,useWalletBalance:i,saveCard:s}})})}submitCvv(r){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(s){return g(this,arguments,function*({intentId:e,url:t,renderStrategy:r,options:a}){switch(this.sdkApiHandler.postMessage("SDKRenderUrl"),r){case"IFRAME":return y(this,$,he).call(this,{url:t,intentId:e});case"POPUP_IFRAME":return y(this,F,pe).call(this,{url:t,intentId:e,options:a});case"REDIRECT":return y(this,q,ue).call(this,{url:t,options:a});default:return null}})}onExpiration(e,t){if(!e)return()=>{};const r=new Date(e),a=setInterval(()=>g(this,null,function*(){const s=new Date;r<s&&(clearInterval(a),t())}),1e3);return()=>clearInterval(a)}}L=new WeakSet,O=function(e){var r,a;return{apiVersion:2,apiVersionMinor:0,allowedPaymentMethods:[w({type:"CARD",parameters:{allowedAuthMethods:((r=this.options.googlePay)==null?void 0:r.allowedAuthMethods)||["PAN_ONLY","CRYPTOGRAM_3DS"],allowedCardNetworks:((a=this.options.googlePay)==null?void 0:a.allowedCardNetworks)||["AMEX","DISCOVER","JCB","MASTERCARD","VISA"]}},e?{tokenizationSpecification:{type:"PAYMENT_GATEWAY",parameters:{gateway:e.gateway,gatewayMerchantId:e.gateway_merchant_id}}}:{})]}},M=new WeakSet,Y=function(t){return g(this,arguments,function*({accessToken:e}){const r=new G;this.vaultSubmitListener.current=d=>{const{type:i,data:n}=d.data;i==="vaultSubmit:success"&&r.resolve(n),i==="vaultSubmit:error"&&r.reject(n)};const a=y(this,V,fe).call(this,{accessToken:e}),s=yield r.promise;return a.remove(),s})},$=new WeakSet,he=function(r){return g(this,arguments,function*({intentId:e,url:t}){const a=document.querySelector("#rendered-url-iframe-container");p.throwIf(!a,"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"),a==null||a.replaceChildren(s),yield y(this,R,B).call(this,{intentId:e}),s.remove()})},F=new WeakSet,pe=function(a){return g(this,arguments,function*({intentId:e,url:t,options:r={}}){const{width:s=600,height:d=400,left:i=200,top:n=200}=r.window||{},c=window.open(t,"",`width=${s},height=${d},left=${i},top=${n}`);p.throwIf(!c,"Popup blocked by browser!"),yield y(this,R,B).call(this,{intentId:e,isUsingPopUp:!0}),c==null||c.close()})},q=new WeakSet,ue=function(r){return g(this,arguments,function*({url:e,options:t}){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},R=new WeakSet,B=function(r){return g(this,arguments,function*({intentId:e,isUsingPopUp:t=!1}){const a=new G,s=d=>g(this,null,function*(){var n,c,l,h;if(d.origin!==p.getIframeUrl())return;const{type:i}=d.data;if(i==="intentResult"){t&&this.sdkApiHandler.postMessage("EmbedResultClose");const[m]=yield Promise.all([this.getIntentDetails(e),ve(2)]),E=m.transaction.status.split(".")[1];E==="successful"||E.startsWith("pending")?(c=(n=this.options).onComplete)==null||c.call(n,w({type:this.options.type},m)):(h=(l=this.options).onFail)==null||h.call(l,w({type:this.options.type},m)),a.resolve(()=>null),window.removeEventListener("message",s)}});return window.addEventListener("message",s),a.promise})},H=new WeakSet,me=function(e){const t=r=>{r.origin===C()&&e.forEach(a=>{a(r)})};window.addEventListener("message",t)},N=new WeakSet,ge=function(e){const t=r=>{e.current&&e.current(r)};window.addEventListener("message",t)},D=new WeakSet,ye=function({container:e,elementType:t,elementOptions:r,styles:a,fontSourceCss:s}){var c,l,h,m;const d=C(),i=new URL(`${d}/vaultField/vaultField.html`);s&&i.searchParams.set("fontSourceCss",s),i.searchParams.set("host",btoa(window.location.origin)),i.searchParams.set("type",t),((c=r.validation)==null?void 0:c.required)!==void 0&&i.searchParams.set("required",`${(l=r.validation)==null?void 0:l.required}`),i.searchParams.set("placeholder",(h=r.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 n=document.createElement("iframe");return n.src=i.toString(),n.style.height=(m=a==null?void 0:a.height)!=null?m:"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),n},V=new WeakSet,fe=function({accessToken:e}){const t=C(),r=Ae(),a=new URL(`${t}/vaultSubmit/vaultSubmit.html`);a.searchParams.set("host",btoa(window.location.origin)),a.searchParams.set("vault_api_url",`${r}/api/v1/tokens/`),a.searchParams.set("access_token",e),a.searchParams.set("lang",this.sdkEmbed.lang);const s=document.createElement("iframe");return s.id="moneyhash-submit-iframe",s.src=a.toString(),s.hidden=!0,document.body.appendChild(s),s};module.exports=Ie;

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

flowId?: string;
operation?: "purchase" | "authorize";
};

@@ -262,0 +263,0 @@

@@ -48,3 +48,3 @@ var be = Object.defineProperty, ke = Object.defineProperties;

});
import { M as ve, g as he, S as Se, t as g, w as Ce, s as G } from "./warnIf-cd10a9ff.js";
import { M as ve, g as he, S as Se, t as g, w as Ce, s as G } from "./warnIf-6af14c9d.js";
function Le() {

@@ -61,3 +61,3 @@ return typeof window != "undefined";

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.7.0");
t.searchParams.set("sdk", "true"), t.searchParams.set("parent", window.location.origin), t.searchParams.set("version", "js@1.7.1");
const s = document.createElement("iframe");

@@ -64,0 +64,0 @@ s.id = "moneyhash-headless-sdk", s.src = t.toString(), s.hidden = !0, document.body.appendChild(s), b.messagingService = new ve({

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

(function(c,d){typeof exports=="object"&&typeof module!="undefined"?module.exports=d():typeof define=="function"&&define.amd?define(d):(c=typeof globalThis!="undefined"?globalThis:c||self,c.MoneyHash=d())})(this,function(){var q,Q,H,Z,j,we,O,be,T,Pe,N,ee,W,ve,B,Ee,G,ke,Y,Ae;"use strict";var Le=Object.defineProperty,Me=Object.defineProperties;var Ie=Object.getOwnPropertyDescriptors;var x=Object.getOwnPropertySymbols;var ge=Object.prototype.hasOwnProperty,ye=Object.prototype.propertyIsEnumerable;var X=(c,d,h)=>d in c?Le(c,d,{enumerable:!0,configurable:!0,writable:!0,value:h}):c[d]=h,k=(c,d)=>{for(var h in d||(d={}))ge.call(d,h)&&X(c,h,d[h]);if(x)for(var h of x(d))ye.call(d,h)&&X(c,h,d[h]);return c},K=(c,d)=>Me(c,Ie(d));var fe=(c,d)=>{var h={};for(var P in c)ge.call(c,P)&&d.indexOf(P)<0&&(h[P]=c[P]);if(c!=null&&x)for(var P of x(c))d.indexOf(P)<0&&ye.call(c,P)&&(h[P]=c[P]);return h};var w=(c,d,h)=>(X(c,typeof d!="symbol"?d+"":d,h),h),Ue=(c,d,h)=>{if(!d.has(c))throw TypeError("Cannot "+h)};var L=(c,d,h)=>{if(d.has(c))throw TypeError("Cannot add the same private member more than once");d instanceof WeakSet?d.add(c):d.set(c,h)};var A=(c,d,h)=>(Ue(c,d,"access private method"),h);var b=(c,d,h)=>new Promise((P,y)=>{var V=R=>{try{$(h.next(R))}catch(F){y(F)}},_=R=>{try{$(h.throw(R))}catch(F){y(F)}},$=R=>R.done?P(R.value):Promise.resolve(R.value).then(V,_);$((h=h.apply(c,d)).next())});class c{constructor(e){w(this,"target");w(this,"targetOrigin");w(this,"listeners");w(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 d(){var e;return(e=window.MONEYHASH_IFRAME_URL)!=null?e:"https://embed.moneyhash.io"}function h(){return typeof window!="undefined"}const C=class{constructor(){h()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=d(),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.7.0");const a=document.createElement("iframe");a.id="moneyhash-headless-sdk",a.src=t.toString(),a.hidden=!0,document.body.appendChild(a),C.messagingService=new c({target:a.contentWindow,targetOrigin:e}),C.isCommunicationReady=new Promise(s=>{var o;const n=r=>{var i;r.data.type==="headlessSDK:init"&&(s(),(i=C.messagingService)==null||i.removeListener(n))};(o=C.messagingService)==null||o.onReceive(n)})}request(a){return b(this,arguments,function*({api:e,payload:t}){return yield C.isCommunicationReady,new Promise((s,n)=>{var r,i;(r=C.messagingService)==null||r.send({type:e,data:t});const o=p=>{var u;const{type:l,data:m}=p.data;l===e&&(m.status==="resolved"?s(m.payload):n(m.payload),(u=C.messagingService)==null||u.removeListener(o))};(i=C.messagingService)==null||i.onReceive(o)})})}postMessage(e){var t;(t=C.messagingService)==null||t.send({type:e})}};let P=C;w(P,"messagingService",null),w(P,"isCommunicationReady");function y(f,e){if(f)throw new Error(e)}const V=new Set(["payment","payout"]),_=new Set(["en","fr","ar"]);class ${constructor(e){w(this,"options");w(this,"messagingService",null);w(this,"iframe",null);w(this,"isCommunicationReady",null);y(!V.has(e.type),`MoneyHash constructor must be called with valid type (${[...V].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,onHeightChange:a}){var i,p;(i=this.messagingService)==null||i.abortService();const s=d(),n=new URL(`${s}/embed/${this.options.type}/${t}`);n.searchParams.set("sdk","true"),n.searchParams.set("parent",window.location.origin),n.searchParams.set("version","js@1.7.0"),a&&n.searchParams.set("onDimensionsChange","true");const o=(p=this.options.locale)==null?void 0:p.split("-")[0];o&&n.searchParams.set("lang",o),this.iframe=document.createElement("iframe"),this.iframe.src=n.toString(),this.iframe.style.height="100%",this.iframe.style.width="100%",this.iframe.style.border="0";const r=document.querySelector(e);return y(!r,`Couldn't find an element with selector ${e}!`),r.replaceChildren(this.iframe),this.messagingService=new c({target:this.iframe.contentWindow,targetOrigin:s}),this.isCommunicationReady=new Promise(l=>{var u;const m=v=>{var E;v.data.type==="sdk:init"&&(l(),(E=this.messagingService)==null||E.removeListener(m))};(u=this.messagingService)==null||u.onReceive(m)}),this.messagingService.onReceive((l,m)=>{var E,S,D,g;const{type:u,data:v}=l.data;switch(u){case"sdk:init":{m({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(S=(E=this.options).onComplete)==null||S.call(E,k({type:this.options.type},v)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{(g=(D=this.options).onFail)==null||g.call(D,k({type:this.options.type},v)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"dimensionsChange":{a==null||a(v.iframeHeight);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 R{constructor(){w(this,"promise");w(this,"resolve");w(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function F(){var e;return(e=window.MONEYHASH_VAULT_API_URL)!=null?e:"https://vault.moneyhash.io"}function U(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function te(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}function se(f){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!f.includes(t))return t;return null}function ie(f){return(Array.isArray(f)?f.length:Object.keys(f).length)===0}function ne(f,e){return new Promise((t,a)=>{if(document.getElementById(e)){t(void 0);return}const n=document.createElement("script");n.src=f,n.id=e,n.addEventListener("load",()=>{t(void 0)}),n.addEventListener("error",()=>{a(new Error("Script failed to load"))}),document.body.appendChild(n)})}function Se(f){return new Promise(e=>{setTimeout(()=>{e("done")},f*1e3)})}function Re(f,e){f&&console.warn(e)}const ae=new Set(["method","customerBalance","savedCard"]);class Ce{constructor(e){L(this,q);L(this,H);L(this,j);L(this,O);L(this,T);L(this,N);L(this,W);L(this,B);L(this,G);L(this,Y);w(this,"options");w(this,"sdkApiHandler",new P);w(this,"sdkEmbed");w(this,"vaultSubmitListener",{current:null});w(this,"mountedCardElements",[]);w(this,"googlePaymentsClient",null);w(this,"cardForm",{collect:()=>b(this,null,function*(){y(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to collect card!");const e=se(this.mountedCardElements);y(!!e,`You must mount ${e} element!`);const t=yield this.sdkApiHandler.request({api:"sdk:generateAccessToken",payload:{publicApiKey:this.options.publicApiKey}});return A(this,H,Z).call(this,{accessToken:t})}),pay:o=>b(this,[o],function*({intentId:e,cardData:t,saveCard:a,billingData:s,shippingData:n}){return this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,lang:this.sdkEmbed.lang,paymentMethod:"CARD",billingData:s,shippingData:n,cardEmbed:t,saveCard:a}})}),createCardToken:a=>b(this,[a],function*({cardIntentId:e,cardData:t}){return this.sdkApiHandler.request({api:"sdk:createCardToken",payload:{cardIntentId:e,lang:this.sdkEmbed.lang,paymentMethod:"CARD",cardEmbed:t}})})});this.options=e,this.sdkEmbed=new $(K(k({},e),{headless:!0})),A(this,B,Ee).call(this,this.vaultSubmitListener)}getIntentDetails(e){return this.sdkApiHandler.request({api:"sdk:getIntentDetails",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}getIntentMethods(e){return this.sdkApiHandler.request({api:"sdk:getIntentMethods",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}getMethods(e){return"intentId"in e?this.getIntentMethods(e.intentId):(y(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to get methods!"),y(this.options.type==="payout","getMethods is not allowed for payout!"),this.sdkApiHandler.request({api:"sdk:getMethods",payload:k({intentType:this.options.type,lang:this.sdkEmbed.lang,publicApiKey:this.options.publicApiKey},e)}))}proceedWith({intentId:e,type:t,id:a,useWalletBalance:s,metaData:n}){return y(!ae.has(t),`type must be a valid one (${[...ae].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:a,lang:this.sdkEmbed.lang,useWalletBalance:s,metaData:n}})}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 y(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:a,countryCode:s,onCancel:n=()=>{},onError:o,onComplete:r,billingData:i={}}){if(yield ne("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)return;const l=new ApplePaySession(3,{countryCode:s,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${a}`}}),{state:m,intent:u}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(m==="FORM_FIELDS"){if(ie(i))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:i}})}}catch(E){throw yield this.resetSelectedMethod(e),E}const v=new R;l.onvalidatemerchant=E=>{fetch(`${te()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:u.secret,validation_url:E.validationURL})}).then(S=>S.ok?S.json():Promise.reject()).then(S=>l.completeMerchantValidation(S)).catch(o)},l.onpaymentauthorized=E=>{fetch(`${te()}/api/v1/providers/applepay/token/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({token_data:{token:E.payment.token},secret:u.secret})}).then(S=>S.ok?S.json():Promise.reject()).then(()=>{l.completePayment(ApplePaySession.STATUS_SUCCESS),r==null||r(),v.resolve(void 0)}).catch(()=>{l.completePayment(ApplePaySession.STATUS_FAILURE),o(),v.reject(void 0)})},l.oncancel=n,l.begin(),yield v.promise})}renderGooglePayButton(a){return b(this,null,function*(){var s=a,{onClick:e}=s,t=fe(s,["onClick"]);var r;const n=document.getElementById("moneyHash-google-pay-button");y(!n,"Couldn't find an element with id moneyHash-google-pay-button to render the google pay button!"),yield ne("https://pay.google.com/gp/p/js/pay.js","moneyHash-google-pay-sdk"),this.googlePaymentsClient=new window.google.payments.api.PaymentsClient({environment:((r=this.options.googlePay)==null?void 0:r.environment)||"PRODUCTION"});const o=A(this,q,Q).call(this);this.googlePaymentsClient.isReadyToPay(o).then(i=>{if(i.result){const p=this.googlePaymentsClient.createButton(K(k({buttonSizeMode:"fill",buttonType:"pay"},t),{allowedPaymentMethods:o.allowedPaymentMethods,onClick:e}));n==null||n.replaceChildren(p)}else throw new Error("Google Pay is not ready to pay!")}).catch(i=>{console.dir(i)})})}payWithGooglePay(s){return b(this,arguments,function*({intentId:e,billingData:t={},onCancel:a}){y(!this.googlePaymentsClient,'Google Payments Client is not initialized! Make sure to call "renderGooglePay" before calling "payWithGooglePay"');const{state:n,__nativePayData__:o}=yield this.proceedWith({intentId:e,type:"method",id:"GOOGLE_PAY"});try{if(n==="FORM_FIELDS"){if(ie(t))throw new Error("Billing data is missing while calling payWithGooglePay");yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"GOOGLE_PAY",lang:this.sdkEmbed.lang,billingData:t}})}}catch(r){throw yield this.resetSelectedMethod(e),r}return this.googlePaymentsClient.loadPaymentData(K(k({},A(this,q,Q).call(this,o)),{transactionInfo:{totalPriceStatus:"FINAL",totalPriceLabel:"Total",totalPrice:`${o.amount}`,currencyCode:o.currency_code,countryCode:o.country_code},merchantInfo:{merchantName:o==null?void 0:o.merchant_name,merchantId:o==null?void 0:o.merchant_id}})).then(r=>{const i=r.paymentMethodData.tokenizationData.token;return this.sdkApiHandler.request({api:"sdk:submitReceipt",payload:{intentId:e,paymentMethod:"GOOGLE_PAY",lang:this.sdkEmbed.lang,receipt:i}})}).catch(r=>(r.statusCode==="CANCELED"?a==null||a():console.dir(r),Promise.reject(r)))})}renderForm(e){return y(!e.selector,"selector is required for renderForm"),y(!e.intentId,"intentId is required for renderForm"),this.sdkEmbed.render(e)}setLocale(e){Re(!!e&&!_.has(e),`Invalid locale. Supported languages (${[..._].join(" | ")})`);const t=_.has(e)?e:"en";return this.sdkEmbed.setLocale(t)}removeEventListeners(){return this.sdkEmbed.abortService()}updateIntentDiscount({intentId:e,discount:t}){return y(!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(a=>{y(!a.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:a}){const s=[],n={},o=new Map;let r=!1;return A(this,W,ve).call(this,s),{create:({elementType:i,elementOptions:p})=>{var S,D;const l=new Map;let m=null;const u=k(k({},t),p.classes),v=((S=u==null?void 0:u.focus)==null?void 0:S.split(" "))||["MoneyHashElement--focus"],E=((D=u==null?void 0:u.error)==null?void 0:D.split(" "))||["MoneyHashElement--error"];return{mount:()=>{const g=document.querySelector(p.selector);y(!g,`Couldn't find an element with selector ${p.selector}!`),g.classList.add("MoneyHashElement"),s.push(z=>{var re,oe,de,ce,le,he,me,pe,ue;const{type:M,data:I}=z.data;if(M===`${i}@mount`&&(n[i]=I.isValid,(re=l.get(`${i}@mount`))==null||re()),M===`${i}@focus`){g.classList.add(...v),(oe=l.get(`${i}@focus`))==null||oe();return}if(M===`${i}@blur`){g.classList.remove(...v),(de=l.get(`${i}@blur`))==null||de();return}if(M===`${i}@error`){I.isValid?g.classList.remove(...E):g.classList.add(...E),(ce=l.get(`${i}@error`))==null||ce(I);return}if(M===`${i}@changeInput`){if((le=l.get(`${i}@changeInput`))==null||le({isValid:I.isValid,length:I.length}),n[i]=I.isValid,o.get("validityChange")){const J=Object.values(n).every(Boolean);J!==r&&((he=o.get("validityChange"))==null||he(J),r=J)}return}if(M===`${i}@cardNumberChange`){(me=l.get(`${i}@cardNumberChange`))==null||me(I);return}if(M===`${i}@key:Backspace`){(pe=l.get(`${i}@key:Backspace`))==null||pe();return}M===`${i}@key:Enter`&&((ue=l.get(`${i}@key:Enter`))==null||ue())}),m=A(this,G,ke).call(this,{container:g,elementType:i,elementOptions:p,styles:k(k({},e),p.styles),fontSourceCss:a}),this.mountedCardElements.push(i)},on:(g,z)=>{l.set(`${i}@${g}`,z)},off:g=>l.delete(`${i}@${g}`),focus:()=>{var g;(g=m==null?void 0:m.contentWindow)==null||g.postMessage({type:"focus"},U())},blur:()=>{var g;(g=m==null?void 0:m.contentWindow)==null||g.postMessage({type:"blur"},U())},clear:()=>{var g;(g=m==null?void 0:m.contentWindow)==null||g.postMessage({type:"clear"},U())}}},on:(i,p)=>{o.set(i,p)}}}submitForm(i){return b(this,arguments,function*({intentId:e,accessToken:t,billingData:a,shippingData:s,saveCard:n,paymentMethod:o="CARD",useWalletBalance:r}){let p;if(t){const m=se(this.mountedCardElements);y(!!m,`You must mount ${m} element!`),p=yield A(this,H,Z).call(this,{accessToken:t})}return yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:o,lang:this.sdkEmbed.lang,billingData:a,shippingData:s,cardEmbed:p,useWalletBalance:r,saveCard:n}})})}submitCvv(a){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(n){return b(this,arguments,function*({intentId:e,url:t,renderStrategy:a,options:s}){switch(this.sdkApiHandler.postMessage("SDKRenderUrl"),a){case"IFRAME":return A(this,j,we).call(this,{url:t,intentId:e});case"POPUP_IFRAME":return A(this,O,be).call(this,{url:t,intentId:e,options:s});case"REDIRECT":return A(this,T,Pe).call(this,{url:t,options:s});default:return null}})}onExpiration(e,t){if(!e)return()=>{};const a=new Date(e),s=setInterval(()=>b(this,null,function*(){const n=new Date;a<n&&(clearInterval(s),t())}),1e3);return()=>clearInterval(s)}}return q=new WeakSet,Q=function(e){var a,s;return{apiVersion:2,apiVersionMinor:0,allowedPaymentMethods:[k({type:"CARD",parameters:{allowedAuthMethods:((a=this.options.googlePay)==null?void 0:a.allowedAuthMethods)||["PAN_ONLY","CRYPTOGRAM_3DS"],allowedCardNetworks:((s=this.options.googlePay)==null?void 0:s.allowedCardNetworks)||["AMEX","DISCOVER","JCB","MASTERCARD","VISA"]}},e?{tokenizationSpecification:{type:"PAYMENT_GATEWAY",parameters:{gateway:e.gateway,gatewayMerchantId:e.gateway_merchant_id}}}:{})]}},H=new WeakSet,Z=function(t){return b(this,arguments,function*({accessToken:e}){const a=new R;this.vaultSubmitListener.current=o=>{const{type:r,data:i}=o.data;r==="vaultSubmit:success"&&a.resolve(i),r==="vaultSubmit:error"&&a.reject(i)};const s=A(this,Y,Ae).call(this,{accessToken:e}),n=yield a.promise;return s.remove(),n})},j=new WeakSet,we=function(a){return b(this,arguments,function*({intentId:e,url:t}){const s=document.querySelector("#rendered-url-iframe-container");y(!s,"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"),s==null||s.replaceChildren(n),yield A(this,N,ee).call(this,{intentId:e}),n.remove()})},O=new WeakSet,be=function(s){return b(this,arguments,function*({intentId:e,url:t,options:a={}}){const{width:n=600,height:o=400,left:r=200,top:i=200}=a.window||{},p=window.open(t,"",`width=${n},height=${o},left=${r},top=${i}`);y(!p,"Popup blocked by browser!"),yield A(this,N,ee).call(this,{intentId:e,isUsingPopUp:!0}),p==null||p.close()})},T=new WeakSet,Pe=function(a){return b(this,arguments,function*({url:e,options:t}){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},N=new WeakSet,ee=function(a){return b(this,arguments,function*({intentId:e,isUsingPopUp:t=!1}){const s=new R,n=o=>b(this,null,function*(){var i,p,l,m;if(o.origin!==d())return;const{type:r}=o.data;if(r==="intentResult"){t&&this.sdkApiHandler.postMessage("EmbedResultClose");const[u]=yield Promise.all([this.getIntentDetails(e),Se(2)]),v=u.transaction.status.split(".")[1];v==="successful"||v.startsWith("pending")?(p=(i=this.options).onComplete)==null||p.call(i,k({type:this.options.type},u)):(m=(l=this.options).onFail)==null||m.call(l,k({type:this.options.type},u)),s.resolve(()=>null),window.removeEventListener("message",n)}});return window.addEventListener("message",n),s.promise})},W=new WeakSet,ve=function(e){const t=a=>{a.origin===U()&&e.forEach(s=>{s(a)})};window.addEventListener("message",t)},B=new WeakSet,Ee=function(e){const t=a=>{e.current&&e.current(a)};window.addEventListener("message",t)},G=new WeakSet,ke=function({container:e,elementType:t,elementOptions:a,styles:s,fontSourceCss:n}){var p,l,m,u;const o=U(),r=new URL(`${o}/vaultField/vaultField.html`);n&&r.searchParams.set("fontSourceCss",n),r.searchParams.set("host",btoa(window.location.origin)),r.searchParams.set("type",t),((p=a.validation)==null?void 0:p.required)!==void 0&&r.searchParams.set("required",`${(l=a.validation)==null?void 0:l.required}`),r.searchParams.set("placeholder",(m=a.placeholder)!=null?m:""),r.searchParams.set("lang",this.sdkEmbed.lang),r.searchParams.set("direction",(s==null?void 0:s.direction)||""),r.searchParams.set("color",JSON.stringify(s!=null&&s.color?s.color:"#000")),r.searchParams.set("placeholderColor",(s==null?void 0:s.placeholderColor)||"#ccc"),r.searchParams.set("backgroundColor",(s==null?void 0:s.backgroundColor)||"transparent"),r.searchParams.set("fontSize",(s==null?void 0:s.fontSize)||""),r.searchParams.set("fontFamily",(s==null?void 0:s.fontFamily)||""),r.searchParams.set("fontWeight",`${s==null?void 0:s.fontWeight}`),r.searchParams.set("fontStyle",(s==null?void 0:s.fontStyle)||""),r.searchParams.set("padding",(s==null?void 0:s.padding)||"");const i=document.createElement("iframe");return i.src=r.toString(),i.style.height=(u=s==null?void 0:s.height)!=null?u:"40px",i.style.setProperty("overflow","hidden","important"),i.style.setProperty("display","block","important"),i.style.setProperty("width","100%","important"),i.style.setProperty("maxWidth","100%","important"),i.style.setProperty("border","0","important"),i.style.setProperty("margin","0","important"),i.style.setProperty("padding","0","important"),i.style.setProperty("userSelect","none","important"),i.style.setProperty("colorScheme","light only","important"),e.replaceChildren(i),i},Y=new WeakSet,Ae=function({accessToken:e}){const t=U(),a=F(),s=new URL(`${t}/vaultSubmit/vaultSubmit.html`);s.searchParams.set("host",btoa(window.location.origin)),s.searchParams.set("vault_api_url",`${a}/api/v1/tokens/`),s.searchParams.set("access_token",e),s.searchParams.set("lang",this.sdkEmbed.lang);const n=document.createElement("iframe");return n.id="moneyhash-submit-iframe",n.src=s.toString(),n.hidden=!0,document.body.appendChild(n),n},Ce});
(function(c,d){typeof exports=="object"&&typeof module!="undefined"?module.exports=d():typeof define=="function"&&define.amd?define(d):(c=typeof globalThis!="undefined"?globalThis:c||self,c.MoneyHash=d())})(this,function(){var q,Q,H,Z,j,we,O,be,T,Pe,N,ee,W,ve,B,Ee,G,ke,Y,Ae;"use strict";var Le=Object.defineProperty,Me=Object.defineProperties;var Ie=Object.getOwnPropertyDescriptors;var x=Object.getOwnPropertySymbols;var ge=Object.prototype.hasOwnProperty,ye=Object.prototype.propertyIsEnumerable;var X=(c,d,h)=>d in c?Le(c,d,{enumerable:!0,configurable:!0,writable:!0,value:h}):c[d]=h,k=(c,d)=>{for(var h in d||(d={}))ge.call(d,h)&&X(c,h,d[h]);if(x)for(var h of x(d))ye.call(d,h)&&X(c,h,d[h]);return c},K=(c,d)=>Me(c,Ie(d));var fe=(c,d)=>{var h={};for(var P in c)ge.call(c,P)&&d.indexOf(P)<0&&(h[P]=c[P]);if(c!=null&&x)for(var P of x(c))d.indexOf(P)<0&&ye.call(c,P)&&(h[P]=c[P]);return h};var w=(c,d,h)=>(X(c,typeof d!="symbol"?d+"":d,h),h),Ue=(c,d,h)=>{if(!d.has(c))throw TypeError("Cannot "+h)};var L=(c,d,h)=>{if(d.has(c))throw TypeError("Cannot add the same private member more than once");d instanceof WeakSet?d.add(c):d.set(c,h)};var A=(c,d,h)=>(Ue(c,d,"access private method"),h);var b=(c,d,h)=>new Promise((P,y)=>{var V=R=>{try{$(h.next(R))}catch(F){y(F)}},_=R=>{try{$(h.throw(R))}catch(F){y(F)}},$=R=>R.done?P(R.value):Promise.resolve(R.value).then(V,_);$((h=h.apply(c,d)).next())});class c{constructor(e){w(this,"target");w(this,"targetOrigin");w(this,"listeners");w(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 d(){var e;return(e=window.MONEYHASH_IFRAME_URL)!=null?e:"https://embed.moneyhash.io"}function h(){return typeof window!="undefined"}const C=class{constructor(){h()&&this.initSDKCommunicationIframe()}initSDKCommunicationIframe(){if(document.getElementById("moneyhash-headless-sdk"))return;const e=d(),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.7.1");const a=document.createElement("iframe");a.id="moneyhash-headless-sdk",a.src=t.toString(),a.hidden=!0,document.body.appendChild(a),C.messagingService=new c({target:a.contentWindow,targetOrigin:e}),C.isCommunicationReady=new Promise(s=>{var o;const n=r=>{var i;r.data.type==="headlessSDK:init"&&(s(),(i=C.messagingService)==null||i.removeListener(n))};(o=C.messagingService)==null||o.onReceive(n)})}request(a){return b(this,arguments,function*({api:e,payload:t}){return yield C.isCommunicationReady,new Promise((s,n)=>{var r,i;(r=C.messagingService)==null||r.send({type:e,data:t});const o=p=>{var u;const{type:l,data:m}=p.data;l===e&&(m.status==="resolved"?s(m.payload):n(m.payload),(u=C.messagingService)==null||u.removeListener(o))};(i=C.messagingService)==null||i.onReceive(o)})})}postMessage(e){var t;(t=C.messagingService)==null||t.send({type:e})}};let P=C;w(P,"messagingService",null),w(P,"isCommunicationReady");function y(f,e){if(f)throw new Error(e)}const V=new Set(["payment","payout"]),_=new Set(["en","fr","ar"]);class ${constructor(e){w(this,"options");w(this,"messagingService",null);w(this,"iframe",null);w(this,"isCommunicationReady",null);y(!V.has(e.type),`MoneyHash constructor must be called with valid type (${[...V].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,onHeightChange:a}){var i,p;(i=this.messagingService)==null||i.abortService();const s=d(),n=new URL(`${s}/embed/${this.options.type}/${t}`);n.searchParams.set("sdk","true"),n.searchParams.set("parent",window.location.origin),n.searchParams.set("version","js@1.7.1"),a&&n.searchParams.set("onDimensionsChange","true");const o=(p=this.options.locale)==null?void 0:p.split("-")[0];o&&n.searchParams.set("lang",o),this.iframe=document.createElement("iframe"),this.iframe.src=n.toString(),this.iframe.style.height="100%",this.iframe.style.width="100%",this.iframe.style.border="0";const r=document.querySelector(e);return y(!r,`Couldn't find an element with selector ${e}!`),r.replaceChildren(this.iframe),this.messagingService=new c({target:this.iframe.contentWindow,targetOrigin:s}),this.isCommunicationReady=new Promise(l=>{var u;const m=v=>{var E;v.data.type==="sdk:init"&&(l(),(E=this.messagingService)==null||E.removeListener(m))};(u=this.messagingService)==null||u.onReceive(m)}),this.messagingService.onReceive((l,m)=>{var E,S,D,g;const{type:u,data:v}=l.data;switch(u){case"sdk:init":{m({type:"sdk:init",data:{headless:Boolean(this.options.headless),styles:this.options.styles}});break}case"onComplete":{(S=(E=this.options).onComplete)==null||S.call(E,k({type:this.options.type},v)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"onFail":{(g=(D=this.options).onFail)==null||g.call(D,k({type:this.options.type},v)),this.options.headless&&this.iframe&&(this.iframe.hidden=!0);break}case"dimensionsChange":{a==null||a(v.iframeHeight);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 R{constructor(){w(this,"promise");w(this,"resolve");w(this,"reject");this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}function F(){var e;return(e=window.MONEYHASH_VAULT_API_URL)!=null?e:"https://vault.moneyhash.io"}function U(){var e;return(e=window.MONEYHASH_VAULT_INPUT_IFRAME_URL)!=null?e:"https://vault-form.moneyhash.io"}function te(){var e;return(e=window.API_URL)!=null?e:"https://web.moneyhash.io"}function se(f){const e=["cardNumber","cardCvv","cardExpiryMonth","cardExpiryYear"];for(const t of e)if(!f.includes(t))return t;return null}function ie(f){return(Array.isArray(f)?f.length:Object.keys(f).length)===0}function ne(f,e){return new Promise((t,a)=>{if(document.getElementById(e)){t(void 0);return}const n=document.createElement("script");n.src=f,n.id=e,n.addEventListener("load",()=>{t(void 0)}),n.addEventListener("error",()=>{a(new Error("Script failed to load"))}),document.body.appendChild(n)})}function Se(f){return new Promise(e=>{setTimeout(()=>{e("done")},f*1e3)})}function Re(f,e){f&&console.warn(e)}const ae=new Set(["method","customerBalance","savedCard"]);class Ce{constructor(e){L(this,q);L(this,H);L(this,j);L(this,O);L(this,T);L(this,N);L(this,W);L(this,B);L(this,G);L(this,Y);w(this,"options");w(this,"sdkApiHandler",new P);w(this,"sdkEmbed");w(this,"vaultSubmitListener",{current:null});w(this,"mountedCardElements",[]);w(this,"googlePaymentsClient",null);w(this,"cardForm",{collect:()=>b(this,null,function*(){y(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to collect card!");const e=se(this.mountedCardElements);y(!!e,`You must mount ${e} element!`);const t=yield this.sdkApiHandler.request({api:"sdk:generateAccessToken",payload:{publicApiKey:this.options.publicApiKey}});return A(this,H,Z).call(this,{accessToken:t})}),pay:o=>b(this,[o],function*({intentId:e,cardData:t,saveCard:a,billingData:s,shippingData:n}){return this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,lang:this.sdkEmbed.lang,paymentMethod:"CARD",billingData:s,shippingData:n,cardEmbed:t,saveCard:a}})}),createCardToken:a=>b(this,[a],function*({cardIntentId:e,cardData:t}){return this.sdkApiHandler.request({api:"sdk:createCardToken",payload:{cardIntentId:e,lang:this.sdkEmbed.lang,paymentMethod:"CARD",cardEmbed:t}})})});this.options=e,this.sdkEmbed=new $(K(k({},e),{headless:!0})),A(this,B,Ee).call(this,this.vaultSubmitListener)}getIntentDetails(e){return this.sdkApiHandler.request({api:"sdk:getIntentDetails",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}getIntentMethods(e){return this.sdkApiHandler.request({api:"sdk:getIntentMethods",payload:{intentType:this.options.type,intentId:e,lang:this.sdkEmbed.lang}})}getMethods(e){return"intentId"in e?this.getIntentMethods(e.intentId):(y(!this.options.publicApiKey,"publicApiKey on MoneyHash instance is required to get methods!"),y(this.options.type==="payout","getMethods is not allowed for payout!"),this.sdkApiHandler.request({api:"sdk:getMethods",payload:k({intentType:this.options.type,lang:this.sdkEmbed.lang,publicApiKey:this.options.publicApiKey},e)}))}proceedWith({intentId:e,type:t,id:a,useWalletBalance:s,metaData:n}){return y(!ae.has(t),`type must be a valid one (${[...ae].join(" | ")})`),this.sdkApiHandler.request({api:"sdk:proceedWith",payload:{proceedWith:t,intentType:this.options.type,intentId:e,id:a,lang:this.sdkEmbed.lang,useWalletBalance:s,metaData:n}})}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 y(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:a,countryCode:s,onCancel:n=()=>{},onError:o,onComplete:r,billingData:i={}}){if(yield ne("https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js","moneyHash-apple-pay-sdk"),!ApplePaySession)return;const l=new ApplePaySession(3,{countryCode:s,currencyCode:t,supportedNetworks:["visa","masterCard","amex","discover","mada"],merchantCapabilities:["supports3DS"],total:{label:"Apple Pay",type:"final",amount:`${a}`}}),{state:m,intent:u}=yield this.proceedWith({intentId:e,type:"method",id:"APPLE_PAY"});try{if(m==="FORM_FIELDS"){if(ie(i))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:i}})}}catch(E){throw yield this.resetSelectedMethod(e),E}const v=new R;l.onvalidatemerchant=E=>{fetch(`${te()}/api/v1/providers/applepay/session/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:u.secret,validation_url:E.validationURL})}).then(S=>S.ok?S.json():Promise.reject()).then(S=>l.completeMerchantValidation(S)).catch(o)},l.onpaymentauthorized=E=>{fetch(`${te()}/api/v1/providers/applepay/token/`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify({token_data:{token:E.payment.token},secret:u.secret})}).then(S=>S.ok?S.json():Promise.reject()).then(()=>{l.completePayment(ApplePaySession.STATUS_SUCCESS),r==null||r(),v.resolve(void 0)}).catch(()=>{l.completePayment(ApplePaySession.STATUS_FAILURE),o(),v.reject(void 0)})},l.oncancel=n,l.begin(),yield v.promise})}renderGooglePayButton(a){return b(this,null,function*(){var s=a,{onClick:e}=s,t=fe(s,["onClick"]);var r;const n=document.getElementById("moneyHash-google-pay-button");y(!n,"Couldn't find an element with id moneyHash-google-pay-button to render the google pay button!"),yield ne("https://pay.google.com/gp/p/js/pay.js","moneyHash-google-pay-sdk"),this.googlePaymentsClient=new window.google.payments.api.PaymentsClient({environment:((r=this.options.googlePay)==null?void 0:r.environment)||"PRODUCTION"});const o=A(this,q,Q).call(this);this.googlePaymentsClient.isReadyToPay(o).then(i=>{if(i.result){const p=this.googlePaymentsClient.createButton(K(k({buttonSizeMode:"fill",buttonType:"pay"},t),{allowedPaymentMethods:o.allowedPaymentMethods,onClick:e}));n==null||n.replaceChildren(p)}else throw new Error("Google Pay is not ready to pay!")}).catch(i=>{console.dir(i)})})}payWithGooglePay(s){return b(this,arguments,function*({intentId:e,billingData:t={},onCancel:a}){y(!this.googlePaymentsClient,'Google Payments Client is not initialized! Make sure to call "renderGooglePay" before calling "payWithGooglePay"');const{state:n,__nativePayData__:o}=yield this.proceedWith({intentId:e,type:"method",id:"GOOGLE_PAY"});try{if(n==="FORM_FIELDS"){if(ie(t))throw new Error("Billing data is missing while calling payWithGooglePay");yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:"GOOGLE_PAY",lang:this.sdkEmbed.lang,billingData:t}})}}catch(r){throw yield this.resetSelectedMethod(e),r}return this.googlePaymentsClient.loadPaymentData(K(k({},A(this,q,Q).call(this,o)),{transactionInfo:{totalPriceStatus:"FINAL",totalPriceLabel:"Total",totalPrice:`${o.amount}`,currencyCode:o.currency_code,countryCode:o.country_code},merchantInfo:{merchantName:o==null?void 0:o.merchant_name,merchantId:o==null?void 0:o.merchant_id}})).then(r=>{const i=r.paymentMethodData.tokenizationData.token;return this.sdkApiHandler.request({api:"sdk:submitReceipt",payload:{intentId:e,paymentMethod:"GOOGLE_PAY",lang:this.sdkEmbed.lang,receipt:i}})}).catch(r=>(r.statusCode==="CANCELED"?a==null||a():console.dir(r),Promise.reject(r)))})}renderForm(e){return y(!e.selector,"selector is required for renderForm"),y(!e.intentId,"intentId is required for renderForm"),this.sdkEmbed.render(e)}setLocale(e){Re(!!e&&!_.has(e),`Invalid locale. Supported languages (${[..._].join(" | ")})`);const t=_.has(e)?e:"en";return this.sdkEmbed.setLocale(t)}removeEventListeners(){return this.sdkEmbed.abortService()}updateIntentDiscount({intentId:e,discount:t}){return y(!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(a=>{y(!a.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:a}){const s=[],n={},o=new Map;let r=!1;return A(this,W,ve).call(this,s),{create:({elementType:i,elementOptions:p})=>{var S,D;const l=new Map;let m=null;const u=k(k({},t),p.classes),v=((S=u==null?void 0:u.focus)==null?void 0:S.split(" "))||["MoneyHashElement--focus"],E=((D=u==null?void 0:u.error)==null?void 0:D.split(" "))||["MoneyHashElement--error"];return{mount:()=>{const g=document.querySelector(p.selector);y(!g,`Couldn't find an element with selector ${p.selector}!`),g.classList.add("MoneyHashElement"),s.push(z=>{var re,oe,de,ce,le,he,me,pe,ue;const{type:M,data:I}=z.data;if(M===`${i}@mount`&&(n[i]=I.isValid,(re=l.get(`${i}@mount`))==null||re()),M===`${i}@focus`){g.classList.add(...v),(oe=l.get(`${i}@focus`))==null||oe();return}if(M===`${i}@blur`){g.classList.remove(...v),(de=l.get(`${i}@blur`))==null||de();return}if(M===`${i}@error`){I.isValid?g.classList.remove(...E):g.classList.add(...E),(ce=l.get(`${i}@error`))==null||ce(I);return}if(M===`${i}@changeInput`){if((le=l.get(`${i}@changeInput`))==null||le({isValid:I.isValid,length:I.length}),n[i]=I.isValid,o.get("validityChange")){const J=Object.values(n).every(Boolean);J!==r&&((he=o.get("validityChange"))==null||he(J),r=J)}return}if(M===`${i}@cardNumberChange`){(me=l.get(`${i}@cardNumberChange`))==null||me(I);return}if(M===`${i}@key:Backspace`){(pe=l.get(`${i}@key:Backspace`))==null||pe();return}M===`${i}@key:Enter`&&((ue=l.get(`${i}@key:Enter`))==null||ue())}),m=A(this,G,ke).call(this,{container:g,elementType:i,elementOptions:p,styles:k(k({},e),p.styles),fontSourceCss:a}),this.mountedCardElements.push(i)},on:(g,z)=>{l.set(`${i}@${g}`,z)},off:g=>l.delete(`${i}@${g}`),focus:()=>{var g;(g=m==null?void 0:m.contentWindow)==null||g.postMessage({type:"focus"},U())},blur:()=>{var g;(g=m==null?void 0:m.contentWindow)==null||g.postMessage({type:"blur"},U())},clear:()=>{var g;(g=m==null?void 0:m.contentWindow)==null||g.postMessage({type:"clear"},U())}}},on:(i,p)=>{o.set(i,p)}}}submitForm(i){return b(this,arguments,function*({intentId:e,accessToken:t,billingData:a,shippingData:s,saveCard:n,paymentMethod:o="CARD",useWalletBalance:r}){let p;if(t){const m=se(this.mountedCardElements);y(!!m,`You must mount ${m} element!`),p=yield A(this,H,Z).call(this,{accessToken:t})}return yield this.sdkApiHandler.request({api:"sdk:submitNativeForm",payload:{intentId:e,paymentMethod:o,lang:this.sdkEmbed.lang,billingData:a,shippingData:s,cardEmbed:p,useWalletBalance:r,saveCard:n}})})}submitCvv(a){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(n){return b(this,arguments,function*({intentId:e,url:t,renderStrategy:a,options:s}){switch(this.sdkApiHandler.postMessage("SDKRenderUrl"),a){case"IFRAME":return A(this,j,we).call(this,{url:t,intentId:e});case"POPUP_IFRAME":return A(this,O,be).call(this,{url:t,intentId:e,options:s});case"REDIRECT":return A(this,T,Pe).call(this,{url:t,options:s});default:return null}})}onExpiration(e,t){if(!e)return()=>{};const a=new Date(e),s=setInterval(()=>b(this,null,function*(){const n=new Date;a<n&&(clearInterval(s),t())}),1e3);return()=>clearInterval(s)}}return q=new WeakSet,Q=function(e){var a,s;return{apiVersion:2,apiVersionMinor:0,allowedPaymentMethods:[k({type:"CARD",parameters:{allowedAuthMethods:((a=this.options.googlePay)==null?void 0:a.allowedAuthMethods)||["PAN_ONLY","CRYPTOGRAM_3DS"],allowedCardNetworks:((s=this.options.googlePay)==null?void 0:s.allowedCardNetworks)||["AMEX","DISCOVER","JCB","MASTERCARD","VISA"]}},e?{tokenizationSpecification:{type:"PAYMENT_GATEWAY",parameters:{gateway:e.gateway,gatewayMerchantId:e.gateway_merchant_id}}}:{})]}},H=new WeakSet,Z=function(t){return b(this,arguments,function*({accessToken:e}){const a=new R;this.vaultSubmitListener.current=o=>{const{type:r,data:i}=o.data;r==="vaultSubmit:success"&&a.resolve(i),r==="vaultSubmit:error"&&a.reject(i)};const s=A(this,Y,Ae).call(this,{accessToken:e}),n=yield a.promise;return s.remove(),n})},j=new WeakSet,we=function(a){return b(this,arguments,function*({intentId:e,url:t}){const s=document.querySelector("#rendered-url-iframe-container");y(!s,"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"),s==null||s.replaceChildren(n),yield A(this,N,ee).call(this,{intentId:e}),n.remove()})},O=new WeakSet,be=function(s){return b(this,arguments,function*({intentId:e,url:t,options:a={}}){const{width:n=600,height:o=400,left:r=200,top:i=200}=a.window||{},p=window.open(t,"",`width=${n},height=${o},left=${r},top=${i}`);y(!p,"Popup blocked by browser!"),yield A(this,N,ee).call(this,{intentId:e,isUsingPopUp:!0}),p==null||p.close()})},T=new WeakSet,Pe=function(a){return b(this,arguments,function*({url:e,options:t}){if(!t||!t.redirectToNewWindow){window.location.href=e;return}window.open(e,"_blank")})},N=new WeakSet,ee=function(a){return b(this,arguments,function*({intentId:e,isUsingPopUp:t=!1}){const s=new R,n=o=>b(this,null,function*(){var i,p,l,m;if(o.origin!==d())return;const{type:r}=o.data;if(r==="intentResult"){t&&this.sdkApiHandler.postMessage("EmbedResultClose");const[u]=yield Promise.all([this.getIntentDetails(e),Se(2)]),v=u.transaction.status.split(".")[1];v==="successful"||v.startsWith("pending")?(p=(i=this.options).onComplete)==null||p.call(i,k({type:this.options.type},u)):(m=(l=this.options).onFail)==null||m.call(l,k({type:this.options.type},u)),s.resolve(()=>null),window.removeEventListener("message",n)}});return window.addEventListener("message",n),s.promise})},W=new WeakSet,ve=function(e){const t=a=>{a.origin===U()&&e.forEach(s=>{s(a)})};window.addEventListener("message",t)},B=new WeakSet,Ee=function(e){const t=a=>{e.current&&e.current(a)};window.addEventListener("message",t)},G=new WeakSet,ke=function({container:e,elementType:t,elementOptions:a,styles:s,fontSourceCss:n}){var p,l,m,u;const o=U(),r=new URL(`${o}/vaultField/vaultField.html`);n&&r.searchParams.set("fontSourceCss",n),r.searchParams.set("host",btoa(window.location.origin)),r.searchParams.set("type",t),((p=a.validation)==null?void 0:p.required)!==void 0&&r.searchParams.set("required",`${(l=a.validation)==null?void 0:l.required}`),r.searchParams.set("placeholder",(m=a.placeholder)!=null?m:""),r.searchParams.set("lang",this.sdkEmbed.lang),r.searchParams.set("direction",(s==null?void 0:s.direction)||""),r.searchParams.set("color",JSON.stringify(s!=null&&s.color?s.color:"#000")),r.searchParams.set("placeholderColor",(s==null?void 0:s.placeholderColor)||"#ccc"),r.searchParams.set("backgroundColor",(s==null?void 0:s.backgroundColor)||"transparent"),r.searchParams.set("fontSize",(s==null?void 0:s.fontSize)||""),r.searchParams.set("fontFamily",(s==null?void 0:s.fontFamily)||""),r.searchParams.set("fontWeight",`${s==null?void 0:s.fontWeight}`),r.searchParams.set("fontStyle",(s==null?void 0:s.fontStyle)||""),r.searchParams.set("padding",(s==null?void 0:s.padding)||"");const i=document.createElement("iframe");return i.src=r.toString(),i.style.height=(u=s==null?void 0:s.height)!=null?u:"40px",i.style.setProperty("overflow","hidden","important"),i.style.setProperty("display","block","important"),i.style.setProperty("width","100%","important"),i.style.setProperty("maxWidth","100%","important"),i.style.setProperty("border","0","important"),i.style.setProperty("margin","0","important"),i.style.setProperty("padding","0","important"),i.style.setProperty("userSelect","none","important"),i.style.setProperty("colorScheme","light only","important"),e.replaceChildren(i),i},Y=new WeakSet,Ae=function({accessToken:e}){const t=U(),a=F(),s=new URL(`${t}/vaultSubmit/vaultSubmit.html`);s.searchParams.set("host",btoa(window.location.origin)),s.searchParams.set("vault_api_url",`${a}/api/v1/tokens/`),s.searchParams.set("access_token",e),s.searchParams.set("lang",this.sdkEmbed.lang);const n=document.createElement("iframe");return n.id="moneyhash-submit-iframe",n.src=s.toString(),n.hidden=!0,document.body.appendChild(n),n},Ce});

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

"use strict";var d=Object.defineProperty;var a=(t,e,s)=>e in t?d(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var n=(t,e,s)=>(a(t,typeof e!="symbol"?e+"":e,s),s);const r=require("./warnIf-97d3456f.cjs");class o{constructor(e){n(this,"options");n(this,"sdkEmbed");this.options=e,this.sdkEmbed=new r.SDKEmbed(e)}start(e){return r.throwIf(!e.selector,"selector is required for start"),r.throwIf(!e.intentId,"intentId is required for start"),this.sdkEmbed.render(e)}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 d=Object.defineProperty;var a=(t,e,s)=>e in t?d(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var n=(t,e,s)=>(a(t,typeof e!="symbol"?e+"":e,s),s);const r=require("./warnIf-1e9cc55c.cjs");class o{constructor(e){n(this,"options");n(this,"sdkEmbed");this.options=e,this.sdkEmbed=new r.SDKEmbed(e)}start(e){return r.throwIf(!e.selector,"selector is required for start"),r.throwIf(!e.intentId,"intentId is required for start"),this.sdkEmbed.render(e)}setLocale(e){r.warnIf(!!e&&!r.supportedLanguages.has(e),`Invalid locale. Supported languages (${[...r.supportedLanguages].join(" | ")})`);const s=r.supportedLanguages.has(e)?e:"en";return this.sdkEmbed.setLocale(s)}removeEventListeners(){return this.sdkEmbed.abortService()}}module.exports=o;
var n = Object.defineProperty;
var i = (t, e, s) => e in t ? n(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s;
var r = (t, e, s) => (i(t, typeof e != "symbol" ? e + "" : e, s), s);
import { S as o, t as d, w as u, s as a } from "./warnIf-cd10a9ff.js";
import { S as o, t as d, w as u, s as a } from "./warnIf-6af14c9d.js";
class c {

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

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

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